Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: i need Image printing in Multiple pages.

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Location
    Hyderabad,India
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question i need Image printing in Multiple pages.

    Printing of the image display area is to small to read on some large displays

    Need to restrict the image resizing in generating the print output to a minimum size (to allow it to be readable) and allow the printed output to flow into a multiple pages wide by multiple pages in length if necessary. Currently it is restricted to one page.

    below is the code

    {
    public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
    if (pageIndex != 0)
    return NO_SUCH_PAGE;

    Graphics2D g2d = (Graphics2D) g;

    Rectangle2D.Double printBounds = new Rectangle2D.Double(
    pageFormat.getImageableX(),
    pageFormat.getImageableY(),
    pageFormat.getImageableWidth(),
    pageFormat.getImageableHeight()
    );

    // Print the header and reduce the height for printing
    float headerHeight = printHeader(printBounds, g2d);
    printBounds.y += headerHeight;
    printBounds.height -= headerHeight;

    // Carve off the amount of space needed for the footer
    printBounds.height -= getFooterHeight(g2d);

    // Print the nodes and edges
    printDisplay( printBounds, g2d, 0 );

    if (footer != null) {
    printBounds.y += (printBounds.height + 15);
    printFooter(printBounds, g2d);
    }

    return PAGE_EXISTS;
    }

    }
    =================================

    {
    protected void printDisplay( Rectangle2D.Double printBounds, Graphics2D g2d, double margin ) {
    // Get a rectangle that represents the bounds of all of the DisplayEntities
    Rectangle r = null;
    for (Enumeration e=displayManager.getEntitySet().getEntityEnumerati on();e.hasMoreElements() {
    DisplayEntity de = (DisplayEntity)e.nextElement();
    if (r == null)
    r = de.getBounds();
    else
    r = r.union(de.getBounds());
    }

    // Get that as doubles, rather than ints, and expand by half the margin
    // height in all directions
    Rectangle2D.Double entityBounds = new Rectangle2D.Double(r.x,r.y,r.width,r.height);
    entityBounds.x -= margin/2;
    entityBounds.y -= margin/2;
    entityBounds.width += margin;
    entityBounds.height += margin;

    // See if height and/or width was specified
    Unit specifiedSize = configuration.getHeight();
    double printHeight = (specifiedSize != null) ?
    specifiedSize.getValueAsPixels((int)printBounds.he ight) :
    printBounds.height;

    specifiedSize = configuration.getWidth();
    double printWidth = (specifiedSize != null) ?
    specifiedSize.getValueAsPixels((int)printBounds.wi dth) :
    printBounds.width;

    // Figure out the ratio of print-bounds to the entities' bounds
    double scaleX = 1;
    double scaleY = 1;

    // See if we need to scale
    boolean canExpand = configuration.expandToFit();
    boolean canShrink = configuration.shrinkToFit();

    if (canExpand == false && canShrink == false) {
    scaleX = scaleY = configuration.getScale();
    }
    else {
    if ((canShrink && canExpand) ||
    (canShrink &&
    (entityBounds.width > printWidth ||
    entityBounds.height > printHeight)) ||
    (canExpand &&
    (entityBounds.width < printWidth ||
    entityBounds.height < printHeight))) {
    scaleX = printWidth / entityBounds.width;
    scaleY = printHeight / entityBounds.height;
    }
    }

    if (configuration.maintainAspectRatio()) { // Scale the same
    if (scaleX > scaleY)
    scaleX = scaleY;
    else
    scaleY = scaleX;
    }

    }

    above methods am using for printing image. but in large display i cant able to read letters.


    Thanks in advance

    Srini


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,225
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: i need Image printing in Multiple pages.

    Please read the forum rules. Double posting is not allowed. Your other post has been deleted.

Similar Threads

  1. Replies: 6
    Last Post: December 9th, 2011, 04:53 PM
  2. Replies: 1
    Last Post: September 28th, 2011, 07:29 AM
  3. question Regarding visited pages
    By NituKhanna in forum Java Theory & Questions
    Replies: 2
    Last Post: March 16th, 2011, 05:55 AM
  4. [SOLVED] Printing Array without printing empty elements
    By CarlMartin10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 12th, 2010, 02:41 AM
  5. How to Hyper-link pages together in Java?
    By don.java1 in forum Java Applets
    Replies: 5
    Last Post: July 21st, 2008, 05:09 AM