Printing JPanel to fit one page, Urgent  (thanks for help)..........

hi all,
I am trying to print and can't get the right scaling. My problem is if the JPanel that has lot of images inside it is too big to come on one page width and height then I want the print out to be on one page. If my panel's height is too large to fit on one page and the width is only half of the page or less than page half of the width. Then I want to scale it's height only to fit on one page while keeping the width the same during printing and the images also to be scaled accordingly. And if my height is too small lets say less than half the page and the width is too large too fit on one page then in this case I want to print the original height or keep the height to be shown on the printout as it looks on the screen but scale the width to fit on to one page and the images also to be scaled accordingly. But my following piece of code doesn't honor this though it fits on one page. It keeps on increasing the width or height to fit the whole page thought the width or height is less than that and the images are also expaned accordingly. I want to scale the images too and only fit the width or height if any is greater than one page. Any help is really appreciated. Thanks in advance
RepaintManager.currentManager(panel).setDoubleBufferingEnabled(false);
//Creates and returns a PrinterJob.
PrinterJob printerJob = PrinterJob.getPrinterJob();
Book book = new Book ();
PageFormat pf = printerJob.pageDialog(printerJob.defaultPage());
int pagecount = this.calculatePageCount(pf);
book.append (this, pf, pagecount);
// set pageable
printerJob.setPageable(book);
if (printerJob != null && printerJob.printDialog())
try
//this print() method implements the Printable interface
printerJob.print();
catch (Exception e)
e.printStackTrace();
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
if ( pageIndex >= 1 )
return NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D)graphics;
// leave room for a page number
double pageHeight = pageFormat.getImageableHeight();
double pageWidth = pageFormat.getImageableWidth();
double scaleFactorH = (panel.getSize().height)/(double)(pageFormat.getImageableHeight());
// set the clip to the size of one page
g2.setClip(0, 0, (int)pageWidth, (int)pageHeight);
// translate down the graphics object to the top of this page
g2.translate(0f, -pageIndex*pageHeight);
// scale to fit the width
g2.scale(scale,1.0/scaleFactorH);
panel.paint(g2);
return PAGE_EXISTS;
//method to calculate
public int calculatePageCount (PageFormat pf)
double pageHeight = pf.getImageableHeight();
double pageWidth = pf.getImageableWidth();
double componentWidth = panel.getSize().getWidth();
System.out.println("THe imageable width is " + pageWidth);
if (componentWidth > pageWidth)
scale = pageWidth / panel.getWidth();
double componentHeight = panel.getSize().getHeight() * scale;
printPageCount = (int)Math.round(Math.ceil (componentHeight/pageHeight));
return printPageCount;
Is there a way to fix this any help is appreciated.
Thanks

Dear Nadia,
Thanks for the info.
If I understand it correct I can make a copy of my actual css file.
Rename it this copy to e.g. print.css
And then make some changes such a letter fonts and colour
Linking this css file to my pages and specify it is only for `print1`
Right?
I`m using a template so if I amend the template like this and have all pages updated automatically that should do the trick?
Right?
Is there somewhere where I need to mention that e.g. the page needs to be reduced onto 95% by printing?
Or will the print.css do the trick?
Sometimes I get confused on what css can do and it can do a lot.
Many thanks for helping me out here.
Kind regards
martine

Similar Messages

  • Hi, is it possible to print also A2 with adobe illustrator ? Thanks for help.

    hi, is it possible to print also A2 with adobe illustrator ? Thanks for help.

    pandron,
    One simple way would be to save as/print to PDF, then print from Acrobat/Reader.
    You could also make a copy of the file, then change the Artboard size and scale up the artwork and print from that (presuming you still wish to work in A4 or something).

  • Doesn't open the PDF file (i.e. articles, books pages). It appears a black page. Thanks for help

    Safari doesn't open the PDF file (articles, book page, etc). It appears a black page. Before that it was working perfectly. Thank for your help

    Try this ...
    Open a Finder window then from the menu bar click Go > Go to Folder
    Type or copy paste the following:
    /Library/Internet Plug-Ins
    Click Go.
    If you see the:  AdobePDFViewer plugin (or anything Adobe related) in the Internet Plug-Ins folder, move it to the trash.
    Restart your Mac and try opening a PDF file.

  • Possible to print 2 photos on one page?

    Is it possible to print more than one photo (different shots) on one page thru the print module.  I can't find anything about it in the LR3 Help files.  I know I can do multiples of the same photo but I want two different shots on one page.
    Thanks for your help.
    Paula

    Actually you can drag as many pictures as you can onto the template. 
    I put
    19 shots one one template one day
    >
    >
    Tunney
    THanks Tunney.  Do you just resize the photos to fit, then?
    Paula Minor
    [email protected]
    To laugh often and much; to win the respect of intelligent people and 
    the affection of children....to leavethe world a better place....to 
    know even on life has breathed easier because you have lived.  This is 
    to have succeeded.   Ralph Waldo Emerson

  • How to print two voucher in one page?

    HI,
    we want to print two voucher in one paper. what are the steps to be taken in sapscript? is it purely relted to SPAD?
    Regards,
    lijo Joseph

    hi joseph,
    i'm not sure how related this would be to your concern, but in my place, we've implemented that by sizing a voucher as half a page, so that when we print vouchers, the printer would know that one page is half of a regular page. SPAD is one place to fix, but the actual printing program and SAPScript was also customized so that it would send two vouchers for printing consecutively, and would fit in one page.
    ryan.

  • How to print all columns in one page

    Hi,
    Can anybody explain me how to print all columns in one page.we have around 15 to 20 columns for 4 reports and all these reports are build on one multiprovider.we are using BW 3.5.
    Can anyone explain me  how to print ALL COLUMNS IN ONE PAGE  .currently they are getting all columns in 2 to 3 pages. They are using PORTAL to run the reports here.
    Is it possible to do by customizing Webtemplate or by macros in Workbook.Please help me
    Edited by: kotha123 on Oct 11, 2010 5:58 PM

    Hi,
    Your best bet is to use a workbook template or else Excel to pdf option...Thanks

  • How to print 20 lines in one page and remaining lines in another in script?

    Hi I created 2 pages in script for page1 next page is page2 , how i can print 20 lines in one page and remaining in next page plz send me the code for that and is windows same for 2 pages?...

    Hi Krishna,
    Try below code...
        CALL FUNCTION 'OPEN_FORM'
        EXPORTING
          form                              = form.
        CALL FUNCTION 'START_FORM'
        EXPORTING
         language               = sy-langu
         startpage              = page1
      LOOP AT itab.
        count = count + 1.
        item = count mod 20.
        IF item EQ '1' AND count NE '1'.
           CALL FUNCTION 'END_FORM'.
           CALL FUNCTION 'START_FORM'
           EXPORTING
             language               = sy-langu
             startpage              = <b>page2</b>
        ENDIF.
       "write_form statement ....
      ENDLOOP.
    Message was edited by:
            Hikaruno

  • Controlling print options esp. fit to page

    is there a way to control print options, particularly fit to page, from within the PDF itself?
    We provide print ready files for our clients who print them as needed, but they are brochures that are set up for fit to page OFF, otherwise the white border (because it can't bleed) around it is uneven.
    So they would send the file to our print shop and the printer would automatically print it with this option off, based on the pdf settings for that document.

    Go to Properties (Crtl+D) and the advanced tab, you can set the print porperties that will come up by default there, it is still possible to over ride them though.

  • Printing multiple photos onto one page

    Sorry, fairly new to PSE9!
    Have a group of photos I need to print to actual size (3cm x 4cm) to go into a photo frame.  They are all cropped and ready to go but there doesn't seem to be an option to print multiple images onto one page at a custom size?  A contact sheet only gives me the option for the number of columns and picture package doesn't give any such option either as far as I can see!  I'm sure I must be missing something here!
    Any help much appreciated!  Don't want to waste photo paper printing each small photo individually!

    http://www.elementsvillage.com/forums/showthread.php?p=206785#post206785
    Post #6 in this thread provides standard directions.

  • When I try to print sth I can´t choose my printer. Adobe Reader only shows a printer I used years ago.I aleady deleted and reinstalled the Reader and deleted all other printers from the computer.How can I add a new printer to Adobe Reader?Thanks for help!

    When I try to print sth I can´t choose my printer. Adobe Reader only shows a printer I used years ago.I aleady deleted and reinstalled the Reader and deleted all other printers from the computer.How can I add a new printer to Adobe Reader?Thanks for help!

    Hi,
    I would suggest you to uninstall Adobe Reader using the cleaner tool and then re-install the latest version.
    Adobe Cleaner Tool:- Download Adobe Reader and Acrobat Cleaner Tool - Adobe Labs.
    Latest version of Adobe Reader:- http://get.adobe.com/reader/
    If you still experience the same issue, please share the following information:-
    - Screenshot of Adobe Reader showing printer options
    - Screenshot of Microsoft Word showing printer options
    - Screenshot of control panel- Control Panel\All Control Panel Items\Devices and Printers
    Regards,
    Nakul 

  • Need scanner App for Dock. I have Maverick 10.9.5 and Epson Perfection V500 photo. My present app 3.7.1 won't work. Otherwise I have to go into System Preferences every time I scan to Select to switch from the Printer. Thanks for help.

    Need scanner App for Dock. I have Maverick 10.9.5 and Epson Perfection V500 photo. My present app 3.7.1 won't work. Otherwise I have to go into System Preferences every time I scan to Select to switch from the Printer. Thanks for help.

    You might give VueScan a try. It should work with your scanner. There's a demo version that you can use initially.

  • IMac 24" iMac  (iMac7,1), Intel Core 2 Duo 2,8 GHz  Ram 4 MB running OS 10.6.8: impossible upgrade to Mac OSX Mavericks. Already created second account, according to apple online support, but still doesn't work. Thanks for help.

    iMac 24" iMac  (iMac7,1), Intel Core 2 Duo 2,8 GHz  Ram 4 MB running OS 10.6.8: impossible upgrade to Mac OSX Mavericks. Already created second account, according to apple online support, but still doesn't work. Thanks for help.

    Your Mac is definitely one of the supported models? http://www.apple.com/uk/osx/specs/
    If so, what happens when you try to download? Is it a case of nothing happens? If so, take a look at the suggestions under 'Stalled Download' in this link:
    http://www.wired.com/gadgetlab/2013/10/mavericks-issues-and-fixes/#slideid-23477 1
    Also, some usrs have found that logging out of the Mac App Store and then back in again and starting over has kick-started the download. It seems that the 5+gb download can take a long time to give any feedback as to what's happening.

  • About complier. Thanks for help

    Can anyone tell me how to convert *.class to end-user program-application file? For example, what else of complier to use...
    Thanks for help..

    Hi,
    Read about it here:
    http://developer.java.sun.com/developer/qow/archive/21/index.html
    Regards,
    Manfred.

  • I got the iphone 5, got some pics and msgs and contacts on it, and when i connected to my PC to restore my previous info from the old iphone, all the new stuff are gone, how can i get it back, thanks for help.

    i got the iphone 5, got some pics and msgs and contacts on it, and when i connected to my PC to restore my previous info from the old iphone, all the new stuff are gone, how can i get it back, thanks for help.

    The voicemail system used for the iPhone is different from the voicemail system used on the rest of the Verizon Wireless network. When you activate the iPhone, you lose your saved voicemails from the other system. When you activate a non-iphone, you lose any saved voicemails from the iPhone voicemail system too.

  • Hi , my problem is that i can only create absolute links to other pdf-files in a main pdf-file. how can i switch to or create relative links. Thanks for help!

    Hi , my problem is that i can only create absolute links to other pdf-files in a main pdf-file. how can i switch to or create relative links. Thanks for help!

    I’m using version 11.0.10. So where the Menu resides in a folder ready to be burnt on to a CD, that same folder is where the links point to.
    Thanks

Maybe you are looking for