Only first page of a large JTable will be printed.....

Hi,
I print a JTable with e.g. 4 pages with an BrotherHL1660e-printer. I used the code below, I have got this from http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/advprint.html#pe and modified it a little bit.
     Graphics2D g2 = (Graphics2D) g;
     int fontHeight=g2.getFontMetrics().getHeight();
     int fontDesent=g2.getFontMetrics().getDescent();
     //leave room for page number
     double pageHeight = pageFormat.getImageableHeight()-fontHeight;
     //Seitenbreite
     double pageWidth = pageFormat.getImageableWidth();
     //Tabellenbreite
     double tableWidth = (double) ((JTable)componentToBePrinted).getColumnModel().getTotalColumnWidth();
     double scale = 1.0;
     if (tableWidth >= pageWidth) {
          scale = pageWidth / tableWidth;
     double headerHeightOnPage=
((JTable)componentToBePrinted).getTableHeader().getHeight()*scale;
     //Tabellenbreite wird f?r die Seite passend verkleinert
     double tableWidthOnPage=tableWidth*scale;
     //H?he einer Zeile
     double oneRowHeight=(((JTable)componentToBePrinted).getRowHeight())*scale;
          //Anzahl Zeilen auf einer Seite
     int numRowsOnAPage=
(int)((pageHeight-headerHeightOnPage)/oneRowHeight);
          //H?he einer Seite
     double pageHeightForTable=(double)(oneRowHeight*numRowsOnAPage);
          //Anzahl Seiten gesamt
     int totalNumPages= (int)Math.ceil((
(double)((JTable)componentToBePrinted).getRowCount())/numRowsOnAPage);
     if(pageIndex>=totalNumPages)
return NO_SUCH_PAGE;
     ((JTable)componentToBePrinted).clearSelection();
((JTable)componentToBePrinted).requestFocus();
          //Verschieben zum oberen linken Rand der Seite
     g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
          //Schreiben der Seitenzahlen am unteren Rand der jeweiligen Seite
     g2.drawString("Page: "+(pageIndex+1),(int)pageWidth/2-35,
(int)(pageHeight+fontHeight-fontDesent));//bottom center
//          Hintergrundbild (graues Rechteck) f?r den TableHeader
     int colCount= ((JTable)componentToBePrinted).getTableHeader().getColumnModel().getColumnCount();
     double colWidth=tableWidth/colCount;
     int x=0;
          BufferedImage img=new BufferedImage((int)tableWidth, (int)headerHeightOnPage,BufferedImage.TYPE_USHORT_GRAY);
          Graphics2D iG= (Graphics2D)img.getGraphics();               
     for (int i=0; i<colCount; i++)
               iG.setColor(Color.gray);
               iG.fill3DRect(x,0,img.getWidth(),img.getHeight(),true);
//          x+=colWidth;
     iG.scale(scale,scale);
     g2.drawImage(img,null,null);
          x=0;     
//          Zeichnen der Spalten?berschriften
          for (int i=0; i<colCount; i++)
               g2.drawString((String)((JTable)componentToBePrinted).getTableHeader().getColumnModel().getColumn(i).getHeaderValue(),
//                              x,(int)headerHeightOnPage/2);
               x+=colWidth;                              
     g2.translate(0f,headerHeightOnPage);
//          linie auf der linken Seite der Tabelle
          g2.setColor(Color.gray);
          g2.drawLine(0,0,0,(int)pageHeightForTable);
//          g2.setColor(Color.black);
     g2.translate(1f,(double)(-pageIndex*pageHeightForTable));
g2.setClip(0, (int)(pageHeightForTable*pageIndex),
(int) Math.ceil(tableWidthOnPage),
(int) Math.ceil(pageHeightForTable));
          //Anpassen des Graphic-Kontextes an Seitengr?sse
     g2.scale(scale,scale);
          //rendern der aktuellen Seite
     ((JTable)componentToBePrinted).paint(g2);
     g2.scale(1/scale,1/scale);
     g2.translate(1f,(double)(pageIndex*pageHeightForTable));
     g2.translate(/*0f*/(double)0.0, -headerHeightOnPage);
     g2.setClip(0, 0,(int) Math.ceil(tableWidthOnPage),
(int)Math.ceil(headerHeightOnPage));
     g2.scale(scale,scale);
     return Printable.PAGE_EXISTS;
I have modified the code so that I do not paint the TableHeader. Instead of this I paint grey BufferedImages and the text of the TableHeader on this Images. The reason is that if I paint the TableHeader, only the last row of the Header will be printed but not the table. If I paint the images instead it works.
But my next problem is that I can only print the first page. From the next pages only the last column of the last row will be printed.
Has anyone a good idea to solve this problem? Please help, I am working at this for a couple of days now and I am going mad :-(.
Thank you in advance - netti
PS: excuse my bumpy english

Hey all,
I solved this problem. It was not a code-problem but a printer problem. This code do not work on a BrotherHL1660e-printer. On all other printer I tried it works fine.
Greetings - netti

Similar Messages

  • How to get the text field in the header for only first page of the report

    Hi,
    I am developing reports in BI Publisher Enterprise where i am facing problem i.e., i have to get some text field in header,for only first page in the result but it is displaying in all the other pages of the report in result.So,please if you have any idea of how to solve it, please reply.It is required as early as possible.
    Thanks in Advance

    Invalid path? What are you doing? Writing the report output to an invalid directory?
    Where are your terms and conditions? It would be very easy just to put them in a database table and select them in your report query.

  • This was only 1 page, not a large amt of printing?

    This was only 1 page, not a large amount of printing?

    Your post makes no sense the way it is written, please take some time to recompose and ask a question. Please remember we are end users just like you and cannot read minds or see what you're doing so you need to write clearly and draw an accurate picture of what is occuring.

  • I am using window.print() to print the data of my webpage, it prints only first page and left the remaining while it works fine with IE and Google Chrome, ie print all the pages.

    My Page has data more than one page, it has verticle scroll bar to view all data .
    I used window.print() to print the data of webpage, but it prints only first page and left the remaining information.
    This works fine with Internet Explorer 6+ and Google Chrome.

    Does the entire webpage appear in Print Preview? <br />
    File > Print Preview

  • Only first page of pdfs will display in Reader for iPad?

    When I attempt to open some (not all) pdf files, only the first page of the document will display. The remaining pages show up blank, with the top toolbar also not displayed.
    These files are downloaded from my university's Blackboard app, with some working properly and others not despite them all being pdfs. I have tried downloading them directly from Blackboard and uploading them to Google Drive (where they display properly) and downloading them from there, but neither works. All files will open and display properly in iBooks so it seems that the problem is with Adobe Reader. How do I fix this?

    Are you running the latest Adobe Reader Version i.e. 11.0.1? Can you please share the file where you are encountering this issue to [email protected]?

  • Printing only first page

    --____FSVYRLDZXHAFLIWKCCOF____
    Content-Type: text/plain; charset=iso-8859-15
    Content-Transfer-Encoding: quoted-printable
    Greeitngs,=20
    We have numerous long pages - lists, lists and more lists -
    created in =
    DW8. Just about everyone here uses IE7, but we also have a
    few IE6 and =
    Firefox workstations.=20
    If a user tries to PRINT one of these long pages, such as
    this one:=20
    http://www.tsc.state.tn.us/geninfo/Programs/ADR/mediatorList.asp?chooseType=
    =3DGeneral+Civil&mnuCounty=3DAnderson&DisplayList=3DDisplay+List
    all they get is the first page of what ought to be six to
    nine print =
    pages.=20
    It gets weirder. On our index page,
    http://www.tsc.state.tn.us/
    if the =
    user tries to print it, the columns react differently. The
    center column =
    does not print past what fits ona printed page, while the
    right hand =
    column prints in its entirety. =20
    I've checked the CSS to see if there was a "don't print me"
    feature in any =
    of the CSS scripts, and there is not. the z-indexes appear to
    be ok. (the =
    two columns have the same z-index and are reacting
    differently to the =
    print command) =20
    My question(s) is(are): Can I better control the content of
    the page (the =
    two columns) and how? Is it CSS, html, or some other language
    that will =
    help me control this? Why is IE7 printing only one page of a
    multi-page =
    print job?=20
    Any ideas?
    NOTE: IE6 prints the entire page (multiple print pages). IE7
    and FF do =
    not.=20
    Peter
    --____FSVYRLDZXHAFLIWKCCOF____
    Content-Type: multipart/related;
    boundary="____RIVEUQBROELBXRGDYMGQ____"
    --____RIVEUQBROELBXRGDYMGQ____
    Content-Type: text/html; charset=windows-1252
    Content-Transfer-Encoding: quoted-printable
    <HTML><HEAD>
    <META http-equiv=3DContent-Type content=3D"text/html;
    charset=3Diso-8859-15=
    ">
    <META content=3D"MSHTML 6.00.6000.16525"
    name=3DGENERATOR></HEAD>
    <BODY style=3D"MARGIN: 4px 4px 1px; FONT: 10pt Tahoma">
    <DIV>Greeitngs, </DIV>
    <DIV>We have numerous long pages - lists, lists and
    more lists - created =
    in DW8. Just about everyone here uses IE7, but we also have a
    few IE6 and =
    Firefox workstations. </DIV>
    <DIV> </DIV>
    <DIV>If a user tries to PRINT one of these long pages,
    such as this one: =
    </DIV>
    <DIV> </DIV>
    <DIV><A href=3D"
    http://www.tsc.state.tn.us/geninfo/Programs/ADR/mediatorLis=
    t.asp?chooseType=3DGeneral+Civil&amp;mnuCounty=3DAnderson&amp;DisplayList=
    =3DDisplay+List">
    http://www.tsc.state.tn.us/geninfo/Programs/ADR/mediatorLi=
    st.asp?chooseType=3DGeneral+Civil&amp;mnuCounty=3DAnderson&amp;DisplayList=
    =3DDisplay+List</A></DIV>
    <DIV> </DIV>
    <DIV>all they get is the first page of what ought to be
    six to nine print =
    pages. </DIV>
    <DIV> </DIV>
    <DIV>It gets weirder.  On our index page,
    <A href=3D"
    http://www.tsc.st=
    ate.tn.us/">
    http://www.tsc.state.tn.us/</A> if
    the user tries to =
    print it, the columns react differently.  The center
    column does not =
    print past what fits ona printed page, while the right hand
    column prints =
    in its entirety.  </DIV>
    <DIV> </DIV>
    <DIV>I've checked the CSS to see if there was a "don't
    print me" feature =
    in any of the CSS scripts, and there is not. the z-indexes
    appear to be =
    ok. (the two columns have the same z-index and are reacting
    differently to =
    the print command)  </DIV>
    <DIV> </DIV>
    <DIV>My question(s) is(are): Can I better
    control the content of the =
    page (the two columns) and how?  Is it CSS, html, or
    some other =
    language that will help me control this? Why is IE7 printing
    only one page =
    of a multi-page print job? </DIV>
    <DIV> </DIV>
    <DIV>Any ideas?</DIV>
    <DIV> </DIV>
    <DIV>NOTE: IE6 prints the entire page (multiple print
    pages). IE7 and FF =
    do not. </DIV>
    <DIV> </DIV>
    <DIV>Peter</DIV>
    <DIV> </DIV>
    <DIV> </DIV></BODY></HTML>
    --____RIVEUQBROELBXRGDYMGQ____--
    --____FSVYRLDZXHAFLIWKCCOF____--

    Try one of these:
    1/ In Adobe, deselect "Choose Paper based on PDF size" - you can leave the "Auto Rotate and Center" on.
    2/ In Adobe, go into Advanced and choose "Print as Image".
    3/ If this is a Canon H1 Fiery RIP, go into Printer Properties, Printing Preferences, Layout, Rotate 180degrees and choose "Large Paper Only."

  • Printing only first page landscape not portrait

    Acrobat Standard for Windows v.8
    When using Acrobat to print any PDF document, the first page is printed in landscape instead of portrait, the rest of the pages print as expected. This is reproduceable behavior on a single machine. Printing the PDF using other applications like InDesign or eCopy Desktop print as expected. Only Acrobat is exhibiting this behavior.
    Acrobat has been reapired, uninstalled and reinstalled, printer drivers reinstalled with no success. The work around I have figured out (as a temporary solution so the user can print documents properly) is to select to print the PDF in landscape orientation in the print driver when printing from Acrobat, which prints the whole document in portrait orientation, essentially what was supposed to happen in the first place. This orientation change only seems to affect the first page and doesn't have any affect on duplex orientation.
    Does anyone have a solution to this one? Or some direction? Thanks in advance.

    Try one of these:
    1/ In Adobe, deselect "Choose Paper based on PDF size" - you can leave the "Auto Rotate and Center" on.
    2/ In Adobe, go into Advanced and choose "Print as Image".
    3/ If this is a Canon H1 Fiery RIP, go into Printer Properties, Printing Preferences, Layout, Rotate 180degrees and choose "Large Paper Only."

  • Adobe form only first page is displayed

    hi all,
    I have created two pages under the Master page but only the First page is getting displayed. Both are set to visible. Whatelse could be the reason. Thanks.
    Regards,
    FS

    Hi,
    Can you please elaborate more on this. Have you added 2 body pages or 2 master pages?
    If you have added 2 body pages and if they are empty then they wont get displayed. You will have to insert a subform into the page. Only then you would be able to see the extra two pages.
    Thanks,
    Radhika

  • Acrobat Pro 9.0 printing to Canon ImageRunner 3220 prints only first page of multi-page documents?

    We just got the new CS4 and with the Acrobat Pro 9.0 install, we cannot seem to print multi-page documents.  Only the first page comes through, and the queue clears as though the document's been fully printed.
    We are running Windows XP Pro SP3, and the printer is the Canon ImageRunner irC3220.
    I do not want to use the "Print as Image" option, as I don't want to rasterize the file before sending it to the printer. It's an important document and it's imperative that it is printed at high quality.
    We had no problems printing with Acrobat 8.
    I've seen old posts regarding this issue, but couldn't find anything newer that might have had an updated solution.
    Thank you in advance!! any help would be sooo appreciated right now!

    Great! Many thanks
    Is there actually a kind of marketplace for Javascipts for Adobe Acrobat Pro somewhere? ...
    Really useful!

  • Help - Trying to email 2 page PDF but only first page is attaching

    I have been trying to email a two page pdf (resume) but each time in Mail, it only attaches the first page (actually, it doesn't attach it but paste the first page of the pdf into the document).
    I've tried this three different ways, all with the same result: 
    1) First I created the document in Pages '09, then saved it as a PDF.  When I open up the PDF itself, the entire two page document is there.  When open on the PDF document, I click the share button, select mail, and when a mail window opens up, only the first page of my resume appears pasted into the body of the email.
    2) I open a new window in Mail, I click on the paperclip to attach a document, I select the two page PDF I created, and once again, only the first page appears pasted into the body of the email.
    3). When on the Pages version of my resume, I go to File, then Print, and select "Mail PDF" from the PDF drop down menu...once again only page 1 is pasted into the body of the email.
    I also tried this with a different document and once again only the first page gets pasted.
    I am running Mac OSX Version 10.9
    Thanks in advance for your insight.

    Are you sure that it is only the first page? It is a file and usually only the first page shows, but the rest are there.
    What happens when you double click on the pdf in the email?
    Peter

  • Printing only first page of multiple PDF's

    I need to be able to process a stack of PDF documents.
    What I need: to always print-out only the first page of all documens.
    These are invoices with sometimes 5 pages, sometimes 2....but I only need to archive the frontpage.
    So: opening each of these maybe 100 documents and always only print the first page manually seems a bit like "nonsense" to me.
    Could do this on a friends machine who has an Acrobat Pro X installed.
    Help appreciated
    Anna

    Great! Many thanks
    Is there actually a kind of marketplace for Javascipts for Adobe Acrobat Pro somewhere? ...
    Really useful!

  • Only first page of WordPerfect document is converted to PDF

    Hello- i use wordperfect 15. when i click on the pdf icon to convert the document to pdf, for some reason it is only converting the first page? help!!

    [discussion moved to Creating, Editing & Exporting PDFs forum]

  • InDesign CS5 - Printing, only first page is upside down.

    Strange problem.
    I have a multipage document that has threaded text on pages 2-10 (for example). When I print (duplex or not), the first page (cover page of the manual I writing) is upside down!
    It shows correctly in indesign, as well as when I export it to a PDF and print it.
    The printer i'm using is a Ricoh Aficio MP C4000 PS.
    Our IT group at work says it's an indesign issue! I have had it successfully print on other printers, and I've tried everything I can think of on this printer.
    HELP!

    In my experience, when an IT department can't figure things out, it's always the application's fault (or "those stinkin' Macs").
    I'm pretty sure its a Ricoh thing. I do duplex booklet printing from Acrobat 9 (from a PDF file exported from InDesign CS5) to a Ricoh 5560. I often get the same problem. I find toggling the "Auto Rotate Pages" button in the print dialog on and off will fix it for me. There's no sense to it. If it first prints upside down, click the button and print again and it will work. But the next time you go to print with that setting, it will be upside down again. Click the button off, and it will work. I've given up trying to troubleshoot it.

  • PDF Documents oplen only first page

    When  I open a PDF document it show only the first page with no option to scroll.  It used to work.  I used Lion and have upgraded to Mountain Lion.  The problem was before I upgraded.  How can I solve this problem?
    Thank you.
    Maria

    This forum is for users of an iPad, iPhone, or iPod Touch, and Adobe Reader on those devices.
    It's sounding like you are having problems with PDF in Adobe Reader on a Macintosh. Is that correct? If so, you should ask in this forum:
    Adobe Reader

  • When printing from websites, only first page prints correctly. Rest of pages lose about one quarter of the page on the right side.

    Starting with the 2nd page, the pages are expanded and the whole right side of the page is gone. This only seems to happen on my Mac. I run Firefox on my PC and it prints correctly. At first I thought it was a problem with certain websites, but it always happens when I try to print out more than one page.

    The 2nd page print scaling error has been an issue with Firefox on the Mac since 2011. People at Mozilla have not considered this a major problem. Try printing anything at less than 100% and you'll quickly see how every page after the first page being scaled wrong gets old real fast. The lack of a solution to this issue forced me long ago into using Safari as my primary browser. Good luck waiting until version 21 for a solution. Current release is 18.0.2.

Maybe you are looking for

  • Is there a way to transfer money from one account to another

    please help

  • Why won't Premiere/Media Encoder export FLV?

    I seem to be unable to export to Flash Video under any circumstances. The result is the same regardless of what type of video I try to export: I have tried SD DV and HDV (more details below). In any case, the result is the same: AME loads, I click St

  • PR to PO & release of Unspent Commitment

    Hi, I have created a Internal order with 15000 as commitment. Now used the same Internal Order for creation of a Purch Requisition (PR). Then at time of creating a PO from PR, i used only 8500 as order value. Now, 1. how to release the balance unspen

  • Adobe X Pro vs Adobe X Standard and Javascripts

    Hi, I'm running into a problem.  I have Adobe Acrobat X Pro on my computer at work, however, I'm finding that my field personnel have Adobe Acrobat X Standard.  I've written some javascripts on a form to automatically calculate when a number is enter

  • Problem at startup with all CS3 products

    hello it's a couple of day that i'm not able to open any program of CS3.. I work on a MacBook (black version) with Tiger 10.4.11 Is someone having the same problem? I think that maybe this can have something to do with the OSX update I installed on S