Tutorial on how to print  multiple output pages

Hi,
I am rather sad that this forum does not provide a simple principle on how to printout multiple pages to newbie.
Below is a short contribution from me on how to print across multiple pages, other reader are also encourage to modify the code to provide more robust tutorial .
* How to use java to print across pages that are more than one
* Short contribution to java forum by Eric gan (Malaysia)
import java.awt.*;
import java.awt.geom.*;
import java.awt.print.*;
import java.awt.Graphics2D;
import java.awt.print.*;
import java.awt.print.Book;
import java.awt.print.Pageable;
import java.awt.Graphics2D;
import java.awt.Graphics;
public class Example implements Printable {
//--- Private instances declarations
private int row_cnt=30; // set the total number of row per page
private int cum_row_cnt=30; // set the counter to record total number of row per page to determine
// whether maximum pages should be increase depending on the programme requirement
private int max_pg=0; // set the maximum number of page
public Example () {
//--- Create a printerJob object
PrinterJob printJob = PrinterJob.getPrinterJob ();
     printJob.setPrintable(Example.this);
if (printJob.printDialog()) {
try {
printJob.print();
} catch (Exception PrintException) {
PrintException.printStackTrace();
public void paint (Graphics g) {
Graphics2D g2d;
g2d = (Graphics2D) g;     
int x=10;
int y=10;
for (int outline=0;outline<=160;outline+=20){
          if (y>cum_row_cnt){
          cum_row_cnt+=row_cnt;//counter should grow by value equal to row_cnt
     max_pg++;
     g2d.drawString("outline value ---> " +outline , x, y);
     y+=10; // to set the row printing interval      
} // end of paint procedure
     public int print(Graphics g,
PageFormat pf, int pi)
          throws PrinterException {
// normal routine to check when should java stop the print looping
if (pi >max_pg) {
return Printable.NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D) g;
     int fontHeight=g2.getFontMetrics().getHeight();
     int fontDesent=g2.getFontMetrics().getDescent();
     double pageHeight = pf.getImageableHeight()-fontHeight;
     double pageWidth = pf.getImageableWidth();
     // setting for the translate and graphics clipping to enable printing on output pages
// row_cnt can be equal to pageHeight
// in this examples assumming pageHeight=20 rows           
     g2.translate(pf.getImageableX(), pf.getImageableY());
g2.translate(0f,-pi*row_cnt);
g2.setClip(0, (int)(row_cnt* pi),
(int) Math.ceil(pageWidth),
(int) Math.ceil(row_cnt));
paint(g2);
return Printable.PAGE_EXISTS;
public static void main (String [] args) {
Example example = new Example ();
System.exit (0);
Thank

Hello
I know that Pages is using its own algorithm to resize pages when it put several of them on a single sheet.
This is why I use this tip.
I draw a rectangle whose size is supposed to be the final one.
I give it a white background and a black border whose thickness is set to one point.
For the tests I just insert three page breaks so that the document is a four pages one.
I print it as is.
Doing that, I may measure the printed rectangle.
Of course, at first attempt it doesn't match the required size.
It's easy to compute the required adjustments.
When the correct factor is reached, it is easy to build the complete document so that it prints the correct size.
Doing that I never got odd results but maybe it's because I am a lucky guy.
Of course, disagreeing with one advice doesn't mean that I don't respect it.
I respect your opinion, _on other matters too_
Yvan KOENIG (from FRANCE mardi 6 mai 2008 17:24:09)

Similar Messages

  • How to print multiple small pages on 1 sheet of paper without changing size

    I have a document 85x110mm which I want to print *at exactly that size* 4 times on a sheet of A4 paper. I have duplicated the pages in the document (so there are 4 of them) and in print -> layout I can choose that they all go onto one sheet. BUT they get resized. In print -> paper handling there is an option 'destination paper size' (sounds hopeful...) where I can choose 'document paper size: letter' or 'scale to fit paper size: my custom 85x110 page'. The paper size isn't letter; it's 85x110mm; and my default paper size is A4. The first option seems to lay out the pages to letter, but resizes them anyway, and the second option lays them out to A4, but resizes them. Where's the missing function which lets me *keep everything at the correct size*?
    Possible workaround: if I can lay out the 4 pages on one A4 page that would do - but I need to specify their exact layout in centimetres. I tried modifying a business card layout, but it seemed to want me to set the positions of every element in every card manually. I can't do that precisely enough.

    Hello
    I know that Pages is using its own algorithm to resize pages when it put several of them on a single sheet.
    This is why I use this tip.
    I draw a rectangle whose size is supposed to be the final one.
    I give it a white background and a black border whose thickness is set to one point.
    For the tests I just insert three page breaks so that the document is a four pages one.
    I print it as is.
    Doing that, I may measure the printed rectangle.
    Of course, at first attempt it doesn't match the required size.
    It's easy to compute the required adjustments.
    When the correct factor is reached, it is easy to build the complete document so that it prints the correct size.
    Doing that I never got odd results but maybe it's because I am a lucky guy.
    Of course, disagreeing with one advice doesn't mean that I don't respect it.
    I respect your opinion, _on other matters too_
    Yvan KOENIG (from FRANCE mardi 6 mai 2008 17:24:09)

  • How to print multiple footers for each page in RTF template xml report.

    Hi,
    How to print multiple footers for each page in RTF template xml report.
    i am able to print ( two sets ) ...
    up to last page ( one template ) and for last page ( another template).
    i want to change the footer information based on the group value printed in the report ( it might be 5 to 6) In every report run.. can you please check and let me know do we have any feasibility to achieve this.
    Thanks in advance.
    Regards,
    KAP.

    You can remove all other logic, like last page only contents (start@last-page:body), etc and section breaks if any you have inserted manually.
    Just have for-each@section logic.
    It would be difficult for me to guess what you have done without looking at your RTF or describing here.

  • How to print multiple copies on one page ?

    How to print multiple copies of one document on one page ?
    in coreldraw I used to make the document -for example a business card 5x9 - and when sending to print it automatically placed the number of cards that would fit in my A4 sheet.
    how do I make the same operation in Indesign.
    thanks

    Hi, Peter S.
    >I can see that as a shortcut to printing a page of different cards for multiple people, but to do a simple n-up of a single card it seems overly complex to me. What am I missing?
    * It's just an alternative to copy/paste and step/repeat.
    * For a one-time only use, perhaps it's a little more complex than necessary. But for any future needs, only the content of the data file needs to be changed, either by editing, or by pointing to a new data file. If different cards for multiple people becomes necessary, it's ready to go.
    Regards,
    Peter Gold
    KnowHow ProServices

  • How to generate multiple output pdf's from one oracle reports

    how to generate multiple output pdf's from one oracle reports.
    I have a report where I have to generate more than one output files from the same report based on a parameter.
    Each output file is for each parameter.
    Is this possible in oracle reports, is so how ?

    You can better post your question in the reports forum instead of this pl/sql forum.

  • How to print envelopes in pages, How to print envelopes in pages

    How to print envelopes in pages, How to print envelopes in pages

    I presume you are using the Pages application, is that correct?
    So start off by launching Pages and choose one of the regular envelope styles. Traditional works well for me.
    Next go to the File menu and select Page setup. From the menu that says Paper Size select Manage Custom Sizes. In the resulting dialog, there should be a button on the left labeled "+". Click it. In the Paper Size area, select Width 5 in and Height 7 in. Name the size (where it says "untitled" something descriptive like "5 x 7 envelope". Click the OK button. The Paper Size menu here should now say the description you gave it. Click OK again. Your work area should now be a 5 x 7 envelope.
    Best of luck.
    PS If you are using Word or some other program, the process is probably the same or very similar.

  • I have a macbook pro using version 10.7.4 and I can't print multiple size pages in a pdf file using the brother laser printer hl-5470 dwt

    I have a Macbook Pro using the 10.7.4 version. I recently bought a Brother HL-5470DWT Laser Printer. I can't seem to tell the printer to print multiple size pages in my pdf files.
    No matter what I do it still prints all the documents as 8.5x11! It isn't pulling the paper from both printer trays.
    Please Please help me out....
    deb

    Contact Brother tech support.

  • I was wondering if there is a tutorial on how to make a blog page in muse?

    I was wondering if there is a tutorial on how to make a blog page in muse? Any help will be appreciated.

    Hi
    You can integrate third party blog in your site or if you are using Business Catalyst , then you can go with BC blog modules on page.
    More Details :
    http://www.musegrid.com/blog/add-business-catalyst-blogs-to-your-adobe-muse-website
    http://www.muse-themes.com/blogs/news/7257782-creating-a-blog-in-adobe-muse-powered-by-nab ble
    Thanks,
    Sanjit

  • Re : how to print report output in DOT MATRIX printer

    Hai
           how to print report output in DOT MATRIX printer.
    Thanks
    mani

    Check this
    [http://help.sap.com/saphelp_nw04/helpdata/en/90/78f078030211d399b90000e83dd9fc/frameset.htm]
    also check the SAP Note 129581

  • How to print 2 sided pages brochure

    how to print 2 sided pages brochure

    Hello kaskasnikola,
    I understand that you need to print 2 pages per page.
    1 Open the printer driver, and click the Finishing tab.
    2 Select the number of pages per sheet from the Pages
    per sheet drop-down list.
    3 Select the correct options for Print page borders,
    Page order, and Orientation.
    4 Click OK.
    If you are having any problems please post on our printer forums.
    Here is a link to the forum.

  • How to print the output of the screen in Dialog Programming

    Hi,
    Could anybody help how to print the output of a screen in the dialog programming. i can select 'Hard Copy' option in the 'Custumizing of Local Layout' Icon in the standard tool bar. but that prints the whole screen with the toolbar. i want to print only the output which is displayed on the screen. Please help..
    Regards,
    Swathi

    Hi Swathi,
        Ok. Do One thing. Go to menu bar and select Systems -> Own pool Request -> here you get the spool number. Select it and select the option "Print Directly" in tool bar.
    Thanks.

  • Can anybody explain how to print multiple copies of different documents at the same time as at the moment I have to open each individually and press print

    Can anybody explain how to print multiple copies of different documents at the same time as at the moment I have to open each individually and press print

    is this a windows in bootcamp question ?

  • Here is a Tutorial on How to sync Multiple Video and Audio Clips

    Check out my Tutorial on How to sync Multiple Video and Audio Clips http://vimeo.com/28972315

    Very true ! My main point was to show how easy it was to sync. I still think apple has a way to go to make this a great tool. It was fast to edit but when I want to send somthing to AE 5.5 it was a nightmare. I do  I love how it organizes keywords and the color correction tools are good if you want to do it your self (check out this site http://www.colorgradingcentral.com/final-cut-pro-x-color-grading-table-of-conten ts ) it will be a great program if apple listens to all the comments but does not make it too complicated the you cant create quickly.

  • How to print multiple pages using Internet Explorer with af:showPrintablePageBehavior

    Hello,
    I am facing one issue with using af:showPrintablePageBehavior. I found similar posts and google pages, but unable to fix the issue. Most relevant post is,
    Print issues with af:showPrintablePageBehavior and Internet Explorer
    I have a page show in a af:popup. This page contain a Title in the top, af:outputText and a Print button below it. I have added af:showPrintablePageBehavior to Print button. I am using lots of data in the af:outputText. When I click on Print button, showPrintablePageBehavior is opening new browser window with multiple pages. But when I click on the Print Preview or Print, only first page is shown.
    I have tried the solution mentioned in above post but no luck.
        <f:verbatim>
            <style type="text/css">
                textarea {
                    width: 95%;
                    height: 350px;
                    overflow: auto;
                @agent ie {
                    af|document:maximized::printable {
                        position: static;
            </style>
      </f:verbatim>
      <af:panelStretchLayout bottomHeight="10%" startWidth="0%" endWidth="0%" topHeight="10%" inlineStyle="height: 100%; width: 100%">
      <f:facet name="top">
      <af:panelGroupLayout id="pnlGrpTitle"  layout="vertical" halign="center" inlineStyle="width: 100%;">
      <af:spacer id="titleSpacer" height="10px" />
      <af:label value="Title" inlineStyle="font-weight:bold; font-size: 16px; color:#000066; padding-left: 5px" id="dialogTitle" />
      <af:spacer id="titleSpacer2" height="20px" />
      </af:panelGroupLayout>
      </f:facet>
      <f:facet name="center">
      <af:panelStretchLayout bottomHeight="0" topHeight="0" startWidth="0" endWidth="0">
      <f:facet name="center">
      <af:panelStretchLayout bottomHeight="0" topHeight="25" startWidth="0" endWidth="0">
      <f:facet name="center">
      <af:panelGroupLayout id="pnlTextArea" layout="scroll">
      <af:outputText binding="#{mybean.tfdArea}" escape="false" id="tfdArea" />
      </af:panelGroupLayout>
      </f:facet>
      </af:panelStretchLayout>
      </f:facet>
      </af:panelStretchLayout>
      </f:facet>
      <f:facet name="bottom">
      <af:panelGroupLayout id="pnlGrpBottom" layout="vertical" halign="center" inlineStyle="width: 100%">
      <af:commandToolbarButton id="cbPrint" shortDesc="Print" icon="/images/print.png" inlineStyle="width: 40%" >
      <!--af:clientListener method="self.print" type="action"/-->
      <af:showPrintablePageBehavior />
      </af:commandToolbarButton>
      </af:panelGroupLayout>
      </f:facet>
      </af:panelStretchLayout>
    Any idea how to fix it?
    - Sujay

    Hello,
    I am facing one issue with using af:showPrintablePageBehavior. I found similar posts and google pages, but unable to fix the issue. Most relevant post is,
    Print issues with af:showPrintablePageBehavior and Internet Explorer
    I have a page show in a af:popup. This page contain a Title in the top, af:outputText and a Print button below it. I have added af:showPrintablePageBehavior to Print button. I am using lots of data in the af:outputText. When I click on Print button, showPrintablePageBehavior is opening new browser window with multiple pages. But when I click on the Print Preview or Print, only first page is shown.
    I have tried the solution mentioned in above post but no luck.
        <f:verbatim>
            <style type="text/css">
                textarea {
                    width: 95%;
                    height: 350px;
                    overflow: auto;
                @agent ie {
                    af|document:maximized::printable {
                        position: static;
            </style>
      </f:verbatim>
      <af:panelStretchLayout bottomHeight="10%" startWidth="0%" endWidth="0%" topHeight="10%" inlineStyle="height: 100%; width: 100%">
      <f:facet name="top">
      <af:panelGroupLayout id="pnlGrpTitle"  layout="vertical" halign="center" inlineStyle="width: 100%;">
      <af:spacer id="titleSpacer" height="10px" />
      <af:label value="Title" inlineStyle="font-weight:bold; font-size: 16px; color:#000066; padding-left: 5px" id="dialogTitle" />
      <af:spacer id="titleSpacer2" height="20px" />
      </af:panelGroupLayout>
      </f:facet>
      <f:facet name="center">
      <af:panelStretchLayout bottomHeight="0" topHeight="0" startWidth="0" endWidth="0">
      <f:facet name="center">
      <af:panelStretchLayout bottomHeight="0" topHeight="25" startWidth="0" endWidth="0">
      <f:facet name="center">
      <af:panelGroupLayout id="pnlTextArea" layout="scroll">
      <af:outputText binding="#{mybean.tfdArea}" escape="false" id="tfdArea" />
      </af:panelGroupLayout>
      </f:facet>
      </af:panelStretchLayout>
      </f:facet>
      </af:panelStretchLayout>
      </f:facet>
      <f:facet name="bottom">
      <af:panelGroupLayout id="pnlGrpBottom" layout="vertical" halign="center" inlineStyle="width: 100%">
      <af:commandToolbarButton id="cbPrint" shortDesc="Print" icon="/images/print.png" inlineStyle="width: 40%" >
      <!--af:clientListener method="self.print" type="action"/-->
      <af:showPrintablePageBehavior />
      </af:commandToolbarButton>
      </af:panelGroupLayout>
      </f:facet>
      </af:panelStretchLayout>
    Any idea how to fix it?
    - Sujay

  • How to print multiple emails on one page

    How do I print multiple emails on a single page?

    Thanks, but fumbling around I think I found a better solution.
    All of the incoming e-mails have a see more from...." line in blue type at the bottom. When I click on the"See more from…"  line it opens up the entire chain of discussion which can then be printed on a single page. Exactly what I've been searching to do.

Maybe you are looking for