How to do Print, Print Preview & Page Setup?

do you have any sample to do Print, Print Preview & Page Setup.
thanks very much!

I have a JTable on a dialog and wanted to print it. I discovered the following method (may or may not work for you).
1) Simply extend your class to implement Prinatable....
public class EbertPanelProductivityHistory extends JPanel implements Printable {
2) As pare of your class in #1 make a print() method as follows (i.e. implement print() for Printable)
public int print( Graphics g, PageFormat pageFormat, int page ) {
int i,j,k,x,y;
Graphics2D g2d;
// We're done! (page is 0 based)
if( page >= ReportDataPrintPageCnt ) {
return (NO_SUCH_PAGE);
// Create a graphic2D object and set the default parameters
g2d = (Graphics2D)g;
g2d.setColor( Color.black );
etc. etc. etc....
// PRINT IT!!!
return( PAGE_EXISTS );
3) And then you can print yourself...
private void PrintActionPerformed(java.awt.event.ActionEvent evt) {
PrinterJob PrintJob = PrinterJob.getPrinterJob(); // printer access - instance of PrinterJob
/**** THIS IS OURSELF - i.e. our class with print() implemented that implements Printable **********/
PrintJob.setPrintable(this); // this class implements Printable - see print()
PrintJob.setJobName( Title ); // job name
if( PrintJob.printDialog() ) {                    // print dialog!
try { PrintJob.print(); } catch (Exception e) {
javax.swing.JOptionPane.showMessageDialog(null, MSG_ID + MSG_ERR + e.getMessage(), "Alert", javax.swing.JOptionPane.ERROR_MESSAGE);

Similar Messages

  • How can use Print and Page Setup Dialogs with multiple monitors?

    It seems the designers of the printing API forgot to include multiple monitor support.
    According to the API, a way to popup a print dialog is done via this manner;
    1) PrinterJob.getPrinterJob().printDialog()
    or
    2)PrinterJob.getPrinterJob().printDialog(PrintRequestAttributeSet atts)
    Option (1) brings up the native print dialog and hangs the event thread (another problem, for later i guess) and (2) brings up the Swing dialog which at least doesn't hang the event thread. And while somewhat limited is not a bad print dialog.
    The problem is that there is no way to pass a GraphicsConfiguration object, so that the print dialog can know where to popup (what monitor).
    So looking around, we have this newer 1.4 method
    http://java.sun.com/j2se/1.4/docs/api/javax/print/ServiceUI.html
    public static PrintService printDialog(GraphicsConfiguration gc,
    int x,
    int y,
    PrintService[] services,
    PrintService defaultService,
    DocFlavor flavor,
    PrintRequestAttributeSet attributes) throws HeadlessException
    So now this method has a way to pass a graphicsconfiguration, so it should know what monitor to create the dialog in.
    But this method is such a mess to setup. When I use it, it lists the printers but doesn't select the user's default printer.
    But more problematecally is that there is no PAGE SETUP dialog equivalent to this method! So I would have a print dialog that pops up in the right place, but page setup on default monitor! ARGH!!!
    The code for ServiceUI has a pageDialog() method but it's commented out for "future release". What a mess.
    Is there any way to solve this? To have pageDialog and printDialog on a given monitor?

    It seems the designers of the printing API forgot to include multiple monitor support.
    According to the API, a way to popup a print dialog is done via this manner;
    1) PrinterJob.getPrinterJob().printDialog()
    or
    2)PrinterJob.getPrinterJob().printDialog(PrintRequestAttributeSet atts)
    Option (1) brings up the native print dialog and hangs the event thread (another problem, for later i guess) and (2) brings up the Swing dialog which at least doesn't hang the event thread. And while somewhat limited is not a bad print dialog.
    The problem is that there is no way to pass a GraphicsConfiguration object, so that the print dialog can know where to popup (what monitor).
    So looking around, we have this newer 1.4 method
    http://java.sun.com/j2se/1.4/docs/api/javax/print/ServiceUI.html
    public static PrintService printDialog(GraphicsConfiguration gc,
    int x,
    int y,
    PrintService[] services,
    PrintService defaultService,
    DocFlavor flavor,
    PrintRequestAttributeSet attributes) throws HeadlessException
    So now this method has a way to pass a graphicsconfiguration, so it should know what monitor to create the dialog in.
    But this method is such a mess to setup. When I use it, it lists the printers but doesn't select the user's default printer.
    But more problematecally is that there is no PAGE SETUP dialog equivalent to this method! So I would have a print dialog that pops up in the right place, but page setup on default monitor! ARGH!!!
    The code for ServiceUI has a pageDialog() method but it's commented out for "future release". What a mess.
    Is there any way to solve this? To have pageDialog and printDialog on a given monitor?

  • JasperReports - how to save as PDF from Print Preview page?

    Hi all!
    How can I save reports created with JasperReperts (with iReport tool) as PDF?
    On print preview, when I select it is as PDF, and click on "save", nothing is saved. Also, I get NoClassDefFoundError despite I included all nessesry classes (did I?). Here are list of included classes
    jasperreports-1.2.7.jar;
    jasperreports-1.2.7-javaflow.jar;
    commons-beanutils-1.5.jar;
    commons-collections-2.1.jar;
    commons-logging-1.0.2.jar;
    commons-digester-1.7.jar;Here is my code:
    void printWithPreview() {
        try {
          JasperPrint print = JasperFillManager.fillReport(report, reportParam, conn);
          JasperViewer.viewReport(print, false);
          //byte[] pdfasbytes = JasperExportManager.exportReportToPdf(print); // can I use it somehow?
          JasperExportManager.exportReportToPdf(print);
        } catch (JRException e) {
          e.printStackTrace();
      }Can you help me with this?
    Also, I need to know, how to limit options "save as" only to PFD (on same Print Preview page)?
    Thank you in advance!

    Right!
    I was missing iText.jar.
    So, you need only this code to get report preview and feature to export to pdf, html and other formats:
    void printWithPreview() {
        try {
          JasperPrint print = JasperFillManager.fillReport(report, reportParam, conn);
          JasperViewer.viewReport(print, false);
          JasperExportManager.exportReportToPdf(print);
        } catch (JRException e) {
          e.printStackTrace();
      }You do not need to save it specificly to c: or other "hard coded" directory.
    Thanx 1000 times!!!

  • How can I change the default page setup for printing messages in Apple Mac Version 4.6 (1085)

    How can I change the default page setup for printing messages in Apple Mac Version 4.6 (1085)

    As soon as I posted, Ifigured this one out on my own by going into user settings and changing the default there. Then I was able to delete the default @mac account. Thanks!

  • How can I print half pages to fit in my circa desk calendar

    How can I print half pages from iCal to fit in my Circa desk calendar?

    That depends on the program, but if it's Preview, go to Page Setup... under the File menu. Select the appropriate paper size there. Then go to File > Print... and do a Preview. If the content does not fit on the page, some printer drivers will have a Scale to Fit setting. If there is none, go back to Page Setup... and manually adjust the Scale until it fits nicely when you do a Preview.

  • How do I print a page of return labels in Address Book?

    How do I print a page of return labels in Address Book?

    Okay, it's a bit of hack, but standby..
    Setup your address (that you want printed) in contacts app
    Copy that address
    Paste 30 times (or however many labels you have per page)
    Select those 30 duplicate entries, and go to print
    Viola! (When you are done you can delete the excess entries)

  • How one can print a page to pocket printer from handset of nokia 40 series/

    how one can print a page to pocket printer from handset of nokia 40 series/60series/80 series
    if u have any information regarding these two question the pls send me the link

    I came across something similar recently where it printed the left hand side only!
    If I want to print an email, instead of File > Print  ( does not print properly ) I click on the print icon on my email webpage ( do not use applemail and access gmail direct) which then takes me to print preview showing the complete email which prints ok.
    Some webpages ( File>Print) do not print properly and some do. Those that do not generally have their own printer icon (path) that needs to be clicked on.
    Maybe something to do with encryption but don't know.
    Hope this helps in some way.

  • How can I print a pages document in book format ..order?

    How can I print a pages document in book format ..order?

    This is usually a function of the driver you're using. Have you looked in the various PDEs for black and white or grayscale? What kind of printer are you using?

  • How can i print specific pages against searched word or name (in one print command) from 1000 pages

    how can i print specific pages against searched word or name (in one print command) from 1000 pages

    Thanks, Alex!
    ok, I try first approach in print4.vi, but Labview return an error (view jpg); if I cut From, To controls, the VI print all pages. The same things happen also if I trasform I32 in Variant.
    I don't try second approach, because at this time I have only one report
    I try also with VB macro: this is better (print3.vi) but.....if I use:
    Sub Print_Pages_From_To()
    ActiveDocument.ActiveWindow.PrintOut Range:=wdPrintFromTo, From:="2", To:="3"
    End Sub
    is ok; print the pages selected; if I use:
    Sub PrintPages()
    ActiveDocument.ActiveWindow.PrintOut  Pages:="2-3"  
    End Sub
    printer print all pages.
    what do you think?
    regards,
    Italo
    Attachments:
    print Problem.jpg ‏39 KB
    print4.vi ‏19 KB
    print3.vi ‏19 KB

  • How can i print only pages which have been highlighted, from a multi page file?

    How can i print only pages which have been highlighted, in a multi page file.

    Ah, I see want you mean. This might not be practical for you, but if you select one instance of the highlighted text and add a [space] to the little sticky note, all of the highlighted text on that page will appear in the summary.

  • How do I print 2 pages from a pdf file and enlarge it

    how do i print 2 pages from a file and enlarge it  to email

    Hi stevebulldog,
    Do I understand correctly that you'd like to extract two pages from a PDF, and then send them via email?
    To extract pages from a PDF, you need to use Acrobat. If you don't have Acrobat, you can try it for free for 30 days. Please see http://www.adobe.com/products/acrobat.html.
    I'm not sure what you mean by "enlarge" it. When your recipient views the PDF, they can enlarge the view (zoom in on the PDF) by choosing options from the View menu in Acrobat or Reader.
    Best,
    Sara

  • How do I print selected pages from a multi page document

    How do I print selected pages from a multi page document?
    This question was solved.
    View Solution.

    Hi,
    It depends on the software you are using, what is it ? In general you can select a range or just a number of pages.
    Regards
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • How do I print multiple pages (2) to one A4 page?

    Hi folks,
    How do I print multiple pages (2) to one A4 page (as you can in a PDF) ?
    There is no option when I try to print & I have checked advanced etc. I have tried opening as a PDF. I have tried printing to PDF but it won't allow.
    Any ideas or suggestions would be greatly welcomed - I don't fancy printing the whole 188 pages, but I need them all!
    Thanks,

    Hi Chris,
    Try this, and if you have any trouble get back and we'll trouble shoot, but I think it will work for you.
    Open System Preferences.
    Select Print & Scan
    Click on your printer under Printers in the left pane
    Click "Open Print Queue", on the right
    The print queue app will appear on your Dock
    Open a Finder window containing your files to be printed and select them all
    Drag the files from Finder to Print Queue icon in Dock
    Regards,
    Jerry

  • How to find print preview for purchase order like what we find in va03

    hi guru's
    how to find print preview for purchase order like what we find in va03
    let me share ur information
    thank u

    Hi
    You can see the Print Preview/printout etc using the Transaction ME9F for Purchase Order
    Execute the ME9F tcode and execute you will get lot of PO's select any Po and press display message
    you will see the print preview
    Similarly for RFQ output use the Tcode ME9A
    for Contrat use ME9K
    for GR output use MB90
    Reward points for useful Answers
    Regards
    Anji

  • How to enable Print Preview with the Envy 5530

    How to enable Print Preview on the Envy 5530

    Hi,
    A print preview is not offered by the current HP software as older software versions provided.
    A preview is only available if the application you are printing from include a such, it is not provided by the printer driver itself.
    Shlomi
    Say thanks by clicking the Kudos thumb up in the post.
    If my post resolve your problem please mark it as an Accepted Solution

Maybe you are looking for

  • Packaging Material and Handling Unit Issue

    Dear All, Context:       VL02N Outbound delivery (& packing) I have 2 packaging material 1.box 2.carton Finish product  a,b,c,d  etc I want to put multiple finish product in a box then I want to put 3box in a carton. I have VERP Packaging maerial  00

  • Isight camer gives green screen in photo booth, black in ichat.

    imac g5 insight   Mac OS X (10.4.6)  

  • "retrieve disk item references" error

    using the "save PDF to folder as jpg" option below the printer>pdf button , I get a "retrieve disk item references" error, but save PDF to folder as tiff is still working. What is going wrong ??

  • What's wrong with the manifest file????

    when i tried to jar using this command: java -jar aaa.jar i have an error saying: Failed to load Main-Class manifest attribute from aaa.jar so i tried editing my manifest file but no matter wad changes i make to the manifest file the same error occur

  • BridgeCS4Emailer Scripts

    Running IMAC Intel with Snow Leopard O/S 10.6.4, PSE 8.0 for MAC and Adobe Bridge 3.0.0.464, and I have the latest version of Adobe Extension Manager installed.  When I try to install the BridgeCS4Emailer.mxp file I get the message "This extension ca