com.aspose.pdf.facades

Class PdfViewer

  • All Implemented Interfaces:
    com.aspose.ms.System.IDisposable, IFacade


    public final class PdfViewer
    extends Object
    implements IFacade

    Represents a class to view or print a pdf.

    • Field Detail

      • EndPrint

        public final PdfEvent<com.aspose.ms.System.Drawing.Printing.PrintEventHandler> EndPrint
        Adds/removes subscription on the last page printing event.
    • Constructor Detail

      • PdfViewer

        public PdfViewer()

        Initializes new PdfViewer object.

      • PdfViewer

        public PdfViewer(IDocument document)

        Initializes new PdfViewer object.

        Parameters:
        document - Document object.
    • Method Detail

      • isShowHiddenAreas

        @Deprecated
        public boolean isShowHiddenAreas()
        Deprecated. 

        This method is Deprecated Gets flag that controls visibility of hidden areas on the page.

        Returns:
        boolean value
      • setShowHiddenAreas

        @Deprecated
        public void setShowHiddenAreas(boolean value)
        Deprecated. 
      • getPrintStatus

        public Object getPrintStatus()

        Gets the result of printing job. If success than null; otherwise, exception object.

        Returns:
        exception object or null
      • getUseIntermidiateImage

        public boolean getUseIntermidiateImage()

        Gets the using of conversion of pdf page into intermidiate png file during printing in file mode. Use it when the size of output file is important.

        Returns:
        boolean value.
      • setUseIntermidiateImage

        public void setUseIntermidiateImage(boolean value)

        Sets the using of conversion of pdf page into intermidiate png file during printing in file mode. Use it when the size of output file is important.

        Parameters:
        value - boolean value.
      • getCopiesPrinted

        public int getCopiesPrinted()

        Gets copies printed

        Returns:
        int value
      • getCoordinateType

        public int getCoordinateType()

        Gets the page coordinate type (Media/Crop boxes). CropBox value is used by default.

        Returns:
        PageCoordinateType element
        See Also:
        PageCoordinateType
      • setCoordinateType

        public void setCoordinateType(int value)

        Sets the page coordinate type (Media/Crop boxes). CropBox value is used by default.

        Parameters:
        value - PageCoordinateType element
        See Also:
        PageCoordinateType
      • getPrintAsImage

        public boolean getPrintAsImage()

        Gets a mode for PdfViewer to print as image.

        Returns:
        boolean value
        If true prints always as image (generates image that is printed) If false prints directly to device if all features are supported. In case document contains non-supported features the system may automatically decide to print as image. Default falue is false.
      • setPrintAsImage

        public void setPrintAsImage(boolean value)

        Sets a mode for PdfViewer to print as image.

        Parameters:
        value - boolean value
        If true prints always as image (generates image that is printed) If false prints directly to device if all features are supported. In case document contains non-supported features the system may automatically decide to print as image. Default falue is false.
      • getPageCount

        public int getPageCount()

        Gets page count of the current Pdf file.

        Returns:
        return page count.
      • getPassword

        public String getPassword()

        Gets input document password.

        Returns:
        String value
      • setPassword

        public void setPassword(String value)

        Sets input document password.

        Parameters:
        value - String value
      • getPrintPageDialog

        public boolean getPrintPageDialog()

        Gets a bool value that indicates whether produce the page number dialog when printing.

        Returns:
        boolean value
      • setPrintPageDialog

        public void setPrintPageDialog(boolean value)

        Sets a boolean value that indicates whether produce the page number dialog when printing.

        Parameters:
        value - boolean value
      • getPrintAsGrayscale

        public boolean getPrintAsGrayscale()

        Gets or sets a bool value that indicates whether the page is being printed as grayscale. By default is false.


        Default false is false.
        Returns:
        boolean value
      • setPrintAsGrayscale

        public void setPrintAsGrayscale(boolean value)

        Gets or sets a bool value that indicates whether the page is being printed as grayscale. By default is false.


        Default false is false.
        Parameters:
        value - boolean value
      • getPrinterJobName

        public String getPrinterJobName()

        Gets name of document in printer queue when document is printed. Default value is file name.

        Returns:
        String value
      • setPrinterJobName

        public void setPrinterJobName(String value)

        Sets name of document in printer queue when document is printed. Default value is file name.

        Parameters:
        value - String value
      • getFormPresentationMode

        public int getFormPresentationMode()

        Gets form presentation mode.

        Returns:
        FormPresentationMode element
        See Also:
        FormPresentationMode
      • setFormPresentationMode

        public void setFormPresentationMode(int value)

        Sets form presentation mode.

        Parameters:
        value - FormPresentationMode element
      • getRenderingOptions

        public RenderingOptions getRenderingOptions()

        Gets rendering options.

        Returns:
        RenderingOptions object
      • setRenderingOptions

        public void setRenderingOptions(RenderingOptions value)

        Sets rendering options.

        Parameters:
        value - RenderingOptions value
      • getVerticalAlignment

        public int getVerticalAlignment()

        Gets a value that indicates vertical alignment

        Returns:
        VerticalAlignment element
        See Also:
        VerticalAlignment
      • setVerticalAlignment

        public void setVerticalAlignment(int value)

        Sets a value that indicates vertical alignment

        Parameters:
        value - VerticalAlignment element
        See Also:
        VerticalAlignment
      • getHorizontalAlignment

        public int getHorizontalAlignment()

        Gets a value that indicates horizontal alignment

        Returns:
        HorizontalAlignment element
        See Also:
        HorizontalAlignment
      • setHorizontalAlignment

        public void setHorizontalAlignment(int value)

        Sets a value that indicates horizontal alignment

        Parameters:
        value - HorizontalAlignment element
        See Also:
        HorizontalAlignment
      • getAutoResize

        public boolean getAutoResize()

        Sets a bool value that indicates whether the file be printed with optimized size.

        Returns:
        boolean value: If false print page without page scaling. If true print page with scaling to fit to printable area.
      • setAutoResize

        public void setAutoResize(boolean value)

        Sets a bool value that indicates whether the file be printed with optimized size.

        Parameters:
        value - boolean value: If false print page without page scaling. If true print page with scaling to fit to printable area.
      • getAutoRotate

        public boolean getAutoRotate()

        Gets a bool value that indicates whether the file be printed with auto rotation

        Returns:
        boolean value
      • setAutoRotate

        public void setAutoRotate(boolean value)

        Sets a bool value that indicates whether the file be printed with auto rotation

        Parameters:
        value - boolean value
      • getAutoRotateMode

        public int getAutoRotateMode()

        Gets an AutoRotateMode value that indicates direction of rotation

        Returns:
        AutoRotateMode element
        See Also:
        AutoRotateMode
      • setAutoRotateMode

        public void setAutoRotateMode(int value)

        Sets an AutoRotateMode value that indicates direction of rotation

        Parameters:
        value - AutoRotateMode element
        See Also:
        AutoRotateMode
      • getResolution

        public int getResolution()

        Gets or sets resolution during viewing and printing. The higher resolution, the slower speed. The default value is 150.

        Returns:
        int value
      • setResolution

        public void setResolution(int value)

        Sets resolution during viewing and printing. The higher resolution, the slower speed. The default value is 150.

        Parameters:
        value - int value
      • printLargePdf

        public void printLargePdf(String filePath)

        Opens and prints a large Pdf file. If your Pdf file has hundreds of pages or more or its size is more than 3 MB, this method is recommended to get better performance.


         PdfViewer viewer = new PdfViewer();
         viewer.setAutoResize(true); // print the file with adjusted size
         viewer.setAutoRotate(true); // print the file with adjusted rotation
         viewer.setPrintPageDialog(false);// do not produce the page number dialog when
                                                                                // printing
         viewer.setPrintLargePdf("d:\test.pdf");
         
        Parameters:
        filePath - The path of Pdf file.
        This method has integrated the opening and the printing of the file and you need not calling the OpenPdfFile() explicitly.
      • printLargePdf

        public void printLargePdf(InputStream inputStream)

        Opens and prints a large Pdf stream. If your Pdf file has hundreds of pages or more or its size is more than 3 MB, this method is recommended to get better performance.


         PdfViewer viewer = new PdfViewer();
         viewer.setAutoResize ( true);        //print the file with adjusted size
         viewer.setAutoRotate ( true);        //print the file with adjusted rotation
         viewer.printPageDialog=false;//do not produce the page number dialog when printing
         viewer.printLargePdf(new MemoryStream(File.ReadAllBytes(@"d:\test.pdf")));
         viewer.closePdfFile();
         

        This method has integrated the opening and the printing of the file and you need not calling the OpenPdfFile() explicitly.
        Parameters:
        inputStream - The pdf stream to be opened and printed..
      • printLargePdf

        public void printLargePdf(String filePath,
                                  PdfPrinterSettings printerSettings)

        Opens and prints a large Pdf file with specified printer settings. If your Pdf file has hundreds of pages or more or its size is more than 3 MB, this method is recommended to get better performance.


         
         PdfViewer viewer = new PdfViewer();
         viewer.setAutoResize ( true);       //print the file with adjusted size
         viewer.setAutoRotate ( true);       //print the file with adjusted rotation
         viewer.setPrintPageDialog ( false);//do not produce the page number dialog when printing
         PrinterSettings ps = new PrinterSettings();
         PrintDocument prtdoc = new PrintDocument();
         ps.setPrinterName ( prtdoc.getPrinterSettings().getPrinterName());
         viewer.printLargePdf("d:\\test.pdf",ps);
         viewer.closePdfFile();
          

        This method has integrated the opening and the printing of the file and you need not calling the OpenPdfFile() explicitly.
        Parameters:
        filePath - The path of Pdf file.
        printerSettings - The printer settings.
      • printLargePdf

        public void printLargePdf(InputStream inputStream,
                                  PdfPrinterSettings printerSettings)

        Opens and prints a large Pdf stream with specified printer settings. If your Pdf file has hundreds of pages or more or its size is more than 3 MB, this method is recommended to get better performance.


         
         PdfViewer viewer = new PdfViewer();
         viewer.setAutoResize(true); // print the file with adjusted size
         viewer.setAutoRotate(true); // print the file with adjusted rotation
         viewer.setPrintPageDialog(false); // do not produce the page number dialog when
                                          // printing
         PrinterSettings ps = new PrinterSettings();
         PrintDocument prtdoc = new PrintDocument();
         ps.setPrinterName(prtdoc.getPrinterSettings().getPrinterName());
         viewer.printLargePdf(new FileInputStream("d:\\middleware.pdf"), ps);
         viewer.closePdfFile();
         

        This method has integrated the opening and the printing of the file and you need not calling the OpenPdfFile() explicitly.
        Parameters:
        inputStream - The pdf stream to be opened and printed..
        printerSettings - The printer settings.
      • printLargePdf

        public void printLargePdf(String filePath,
                                  PrintPageSettings pageSettings,
                                  PdfPrinterSettings printerSettings)

        Opens and prints a large Pdf file with specified page settings and printer settings. If your Pdf file has hundreds of pages or more or its size is more than 3 MB, this method is recommended to get better performance.


         
         PdfViewer viewer = new PdfViewer();
         viewer.setAutoResize(true); // print the file with adjusted size
         viewer.setAutoRotate(true); // print the file with adjusted rotation
         viewer.setPrintPageDialog(false); // do not produce the page number dialog when
                                          // printing
         PrinterSettings ps = new PrinterSettings();
         PrintDocument prtdoc = new PrintDocument();
         ps.setPrinterName(prtdoc.getPrinterSettings().getPrinterName());
         PageSettings pgs = new PageSettings();
         pgs.setPaperSize(new PaperSize("A4", 827, 1169));
         pgs.setMargins(new Margins(0, 0, 0, 0));
         viewer.printLargePdf("d:\\test.pdf", pgs, ps);
         viewer.closePdfFile();
         

        This method has integrated the opening and the printing of the file and you need not calling the OpenPdfFile() explicitly.
        Parameters:
        filePath - The path of Pdf file.
        pageSettings - The page settings.
        printerSettings - The printer settings.
      • printLargePdf

        public void printLargePdf(InputStream inputStream,
                                  PrintPageSettings pageSettings,
                                  PdfPrinterSettings printerSettings)

        Opens and prints a large Pdf stream with specified page settings and printer settings. If your Pdf file has hundreds of pages or more or its size is more than 3 MB, this method is recommended to get better performance.


         
         PdfViewer viewer = new PdfViewer();
         viewer.setAutoResize ( true);       //print the file with adjusted size
         viewer.setAutoRotate ( true);       //print the file with adjusted rotation
         viewer.setPrintPageDialog ( false);//do not produce the page number dialog when printing
         PrinterSettings ps = new PrinterSettings();
         PrintDocument prtdoc = new PrintDocument();
         ps.setPrinterName ( prtdoc.getPrinterSettings().getPrinterName());
         PageSettings pgs = new PageSettings();
         pgs.setPaperSize ( new PaperSize("A4", 827, 1169));
         pgs.setMargins ( new Margins(0, 0, 0, 0));
         viewer.printLargePdf(new FileInputStream("d:\\middleware.pdf"),pgs,ps);
         viewer.closePdfFile();
          

        This method has integrated the opening and the printing of the file and you need not calling the OpenPdfFile() explicitly.
        Parameters:
        inputStream - The pdf stream to be opened and printed.
        pageSettings - The page settings.
        printerSettings - The printer settings.
      • decodeAllPages

        public BufferedImage[] decodeAllPages()

        Get pages of current pdf file.

        Returns:
        return the array of Pdf page images.
      • decodePage

        public BufferedImage decodePage(int pageNumber)

        Decodes a page of one Pdf file.

        Parameters:
        pageNumber - The page number of one Pdf file which must be between 1 and PageCount.
        Returns:
        return the Pdf page image.
      • printDocumentWithSettings

        public void printDocumentWithSettings(PrintPageSettings pageSettings,
                                              PdfPrinterSettings printerSettings)

        Prints the Pdf document with settings. If the document size is not complatible to page size, pdf.kit will extend it to fit page size.


         
         PdfViewer viewer = new PdfViewer();
         viewer.openPdfFile("d:\\test.pdf");
         viewer.setAutoResize ( true);         //print the file with adjusted size
         viewer.setAutoRotate ( true);         //print the file with adjusted rotation
         viewer.setPrintPageDialog ( false);//do not produce the page number dialog when printing
         PrinterSettings ps = new PrinterSettings();
         PrintDocument prtdoc = new PrintDocument();
         ps.setPrinterName ( prtdoc.getPrinterSettings.getPrinterName());
         PageSettings pgs = new PageSettings();
         pgs.setPaperSize ( new PaperSize("A4", 827, 1169));
         pgs.setMargins ( new Margins(0, 0, 0, 0));
         viewer.printDocumentWithSettings(pgs, ps);
         viewer.closePdfFile();
          
        Parameters:
        pageSettings - The page setting of the printing document.
        printerSettings - The printer setting of the printing document.
        printerSettings object is used to print the document. pageSettings.PrinterSettings object is ignored.
      • printDocumentWithSettings

        public void printDocumentWithSettings(PdfPrinterSettings printerSettings)

        Prints the Pdf document with printer settings. The output page size will fit the the document first page size.


         
         
         PdfViewer viewer = new PdfViewer();
         viewer.openPdfFile("d:\\test.pdf");
         viewer.setAutoResize ( true);         //print the file with adjusted size
         viewer.setAutoRotate ( true);         //print the file with adjusted rotation
         viewer.setPrintPageDialog ( false);   //do not produce the page number dialog when printing
         PrinterSettings ps = new PrinterSettings();
         PrintDocument prtdoc = new PrintDocument();
         ps.setPrinterName ( prtdoc.getPrinterSettings().PrinterName());
         viewer.printDocumentWithSettings(ps);
         viewer.closePdfFile();
          
        Parameters:
        printerSettings - The printer setting of the printing document.
      • printDocument

        public void printDocument()

        Prints the Pdf document using default printer.


         
         PdfViewer viewer = new PdfViewer();
         viewer.openPdfFile("d:\\test.pdf");
         viewer.setAutoResize ( true);         //print the file with adjusted size
         viewer.setAutoRotate ( true);         //print the file with adjusted rotation
         viewer.setPrintPageDialog ( false);   //do not produce the page number dialog when printing
         viewer.printDocument(ps);
         viewer.closePdfFile();
         
         
      • getDefaultPageSettings

        public PrintPageSettings getDefaultPageSettings()

        Gets the default page settings.

        Returns:
        Page settings object.
      • getDefaultPrinterSettings

        public PdfPrinterSettings getDefaultPrinterSettings()

        Gets the default printer settings.

        Returns:
        Page settings object.
      • openPdfFile

        @Deprecated
        public void openPdfFile(String filePath)
        Deprecated. 

        Opens a Pdf file, but does not actually decode the pages of the Pdf file.


         
         
         PdfViewer viewer = new PdfViewer();
         viewer.openPdfFile("d:\\test.pdf");
         viewer.closePdfFile();
          
        Parameters:
        filePath - The path of Pdf file.
      • openPdfFile

        @Deprecated
        public void openPdfFile(InputStream inputStream)
        Deprecated. 

        Opens a Pdf file stream. But does not actually decode the pages of the Pdf file.


         
         
         PdfViewer viewer = new PdfViewer();
         viewer.openPdfFile(new FileInputStream("d:\\test.pdf")));
         viewer.closePdfFile();
          
        Parameters:
        inputStream - The pdf stream to be opened.
      • closePdfFile

        public void closePdfFile()

        Closes the current Pdf file.

      • decodePageToImage

        public BufferedImage decodePageToImage(int pageNumber,
                                               ImageType imageFormat)

        Decodes page to BufferedImage

        Parameters:
        pageNumber - int value
        imageFormat - ImageType object
        Returns:
        BufferedImage value
      • getScaleFactor

        public float getScaleFactor()

        Gets a floating point value that indicates scale factor. The default value is 1.0.

        Returns:
        floating point value.
      • setScaleFactor

        public void setScaleFactor(float value)

        Sets a floating point value that indicates scale factor. The default value is 1.0.

        Parameters:
        value - floating point value.
      • bindPdf

        public void bindPdf(String srcFile)

        Initializes the facade.

        Specified by:
        bindPdf in interface IFacade
        Parameters:
        srcFile - The PDF file.
      • bindPdf

        public void bindPdf(InputStream srcStream)

        Initializes the facade.

        Specified by:
        bindPdf in interface IFacade
        Parameters:
        srcStream - The stream of PDF file.
      • bindPdf

        public void bindPdf(IDocument srcDoc)

        Initializes the facade.

        Specified by:
        bindPdf in interface IFacade
        Parameters:
        srcDoc - The Document object.
      • save

        public void save(String destFile)

        Saves the result PDF document to file.

        Parameters:
        destFile - The path of output PDF document.
      • save

        public void save(InputStream destStream)

        Saves the result PDF document to stream.

        Parameters:
        destStream - The stream of output PDF document.
      • close

        public void close()
        Closes the current Pdf file.
        Specified by:
        close in interface IFacade
      • dispose

        public void dispose()

        Disposes the facade resources.

        Specified by:
        dispose in interface com.aspose.ms.System.IDisposable