![]() |
||
Home Products Purchase Downloads Demos Forums Blogs Ticket Wiki API Corporate |
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.aspose.pdf.kit.PdfViewer
Represents the Pdf Viewer,it can be embedded in three-party software to view and print Pdf files, it has almost all Adobe Reader¡¯s functions. On the same way, it provides APIs to achieve the same functions. This component¡¯s features including:
1. viewing Pdf file in visual mode embedded to other software;
2. zooming the Pdf page;
3. printing the Pdf file, including: print all pages or a special page scale;
4. searching text in the Pdf file, including: search text in a special rectangle or full pdf page;
5. extracting text in the Pdf file, including: extract text in a special rectangle or full pdf page;
It can be used like this: Pdf kit viewer lib, The SimplePdfViewer example has the view and print function of the lib. Examples for the lib are listed as follows: 1.SimplePdfViewer 2.BackgroundPrint 3.ExtractTextInRectangle 4.SearchTextInRectangle To use the lib you need the following step at least: [SampleCode] //create a PdfViewer class instance. PdfViewer pdfviewer = new PdfViewer(); //open a Pdf file. pdfviewer.openPdfFile(filePath); //decode the pdf page. pdfviewer.decodePage(currentPage); //set the Pdf file page parameters, the first 1 = 100%, the second 1 is the Pdf page number. pdfviewer.setPdfPageParameters(1, 1); //initialize the Pdf show. displayScrollPane = pdfviewer.showPdf(); //If you want to print the Pdf file, the follow code is an example. The SimplePdfViewer shows the usage in detail. //sets the default print scale - false. pdfviewer.enableScalePrint(false); //gets a printjob object. PrinterJob printJob = PrinterJob.getPrinterJob(); //gets the default page. PageFormat pf = printJob.defaultPage(); //sets the Paper object for this PageFormat. pf.setPaper(paper); //allows user to edit settings and select printing printJob.setPrintable(pdfviewer, pf); //creates the printDialog. boolean printFile = printJob.printDialog(); if (printFile) { printJob.print(); } //close the Pdf file. pdfviewer.closePdfFile();
Field Summary |
Fields inherited from interface java.awt.print.Printable |
NO_SUCH_PAGE, PAGE_EXISTS |
Fields inherited from interface java.awt.print.Pageable |
UNKNOWN_NUMBER_OF_PAGES |
Constructor Summary | |
PdfViewer()
The constructor of the PdfViewer object. |
|
PdfViewer(boolean isGraphic)
The constructor of the PdfViewer object. |
Method Summary | |
void |
closePdfFile()
Closes the current Pdf file. |
void |
decodePage(int pageNumber)
Decodes a page of one Pdf file. |
void |
enableScalePrint(boolean scalePrint)
Sets the print scale or not. |
int |
getCropBoxHeight(int pageNumber)
Gets the cropBox height. |
int |
getCropBoxWidth(int pageNumber)
Gets the cropBox width. |
int |
getMediaBoxHeight(int pageNumber)
Gets the pdf height of mediaBox. |
int |
getMediaBoxWidth(int pageNumber)
Gets the pdf width of mediaBox. |
int |
getMediaBoxX(int pageNumber)
Gets the pdf mediaBox X value. |
int |
getMediaBoxY(int pageNumber)
Gets the pdf file mediaBox Y value. |
int |
getNumberOfPages()
Gets the print page number which implements the java.awt.print.Pageable interface. |
java.awt.print.PageFormat |
getPageFormat(int pageIndex)
Gets the PageFormat object of the pageIndex page which implements java.awt.print.Pageable interface. |
int |
getPdfFilePageCount()
Gets page count of the current Pdf file. |
int |
getPdfHeight()
Gets the height of JScrollPane which is the Pdf file view area. |
int |
getPdfWidth()
Gets the width of JScrollPane which is the Pdf file view area. |
java.awt.print.Printable |
getPrintable(int pageIndex)
Gets the Printable object which implements the java.awt.print.Pageable interface. |
java.lang.String |
getPrintFailureMessage()
Gets the print failure message string. |
float |
getPrintScaleFactor()
Gets the scaling factor applied to the Pdf page. |
void |
invalidate()
Invalidates the container. |
boolean |
isPrintSuccess()
Shows the Pdf page print successful or not. |
void |
openPdfFile(java.io.InputStream inputStream)
Opens a Pdf file stream. |
void |
openPdfFile(java.lang.String filePath)
Opens a Pdf file, but does not actually decode the pages of the Pdf file. |
int |
print(java.awt.Graphics graphics,
java.awt.print.PageFormat pageFormat,
int pageIndex)
Implements the standard Java printing functionality of java.awt.print.Printable. |
void |
setPageFormat(int pageNumber,
java.awt.print.PageFormat pageFormat)
Sets the page format for a special page. |
void |
setPdfPageParameters(float scale,
int pageNumber)
Initialises the initial scale factor of the specific Pdf page number. |
void |
setPrintPageRange(int startPage,
int endPage)
Sets the print page range. |
javax.swing.JScrollPane |
showPdf()
Shows the Pdf file in a JScrollPane object which is the Pdf view area. |
void |
updateUI()
Invokes this method to reset the UI which using the JPanel.updateUI(). |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PdfViewer()
public PdfViewer(boolean isGraphic)
isGraphic
- boolean show the pdf file in JScrollPane or not.
true - show the pdf file in JScrollPane.
false - not show the pdf file in JScrollPane, it is for text extraction.Method Detail |
public final void openPdfFile(java.lang.String filePath) throws PdfViewerException, java.lang.Exception
filePath
- String the path of Pdf file.
PdfViewerException
java.lang.Exception
public final void closePdfFile()
public final void decodePage(int pageNumber) throws PdfViewerSecurityException, PdfViewerFontException, PdfViewerException, java.lang.Exception
pageNumber
- int The page number of one Pdf file which must be between 1 and getPdfFilePageCount().
PdfViewerSecurityException
PdfViewerFontException
PdfViewerException
java.lang.Exception
public javax.swing.JScrollPane showPdf()
public final void setPdfPageParameters(float scale, int pageNumber)
scale
- float the scale factor.pageNumber
- int the special page of the Pdf file.public final int getPdfFilePageCount()
public int getCropBoxWidth(int pageNumber)
pageNumber
- int the page number to be examined to get the CropBox Width.
public int getCropBoxHeight(int pageNumber)
pageNumber
- int the page number to be examined to get the CropBox height.
public final int getPdfWidth()
public final int getPdfHeight()
public void invalidate()
public void updateUI()
JComponent.updateUI()
public void enableScalePrint(boolean scalePrint)
scalePrint
- boolean true - using the pdf scaling factor to print.
false - using the 100% scaling factor to print which is the raw pdf scale.public float getPrintScaleFactor()
public boolean isPrintSuccess()
public java.lang.String getPrintFailureMessage()
public int print(java.awt.Graphics graphics, java.awt.print.PageFormat pageFormat, int pageIndex) throws java.awt.print.PrinterException
print
in interface java.awt.print.Printable
graphics
- Graphics object page rendered.pageFormat
- PageFormat object of the print PageFormat.pageIndex
- int current page index (less 1 so start at page 0).
java.awt.print.PrinterException
public int getNumberOfPages()
getNumberOfPages
in interface java.awt.print.Pageable
Pageable.getNumberOfPages()
public java.awt.print.PageFormat getPageFormat(int pageIndex) throws java.lang.IndexOutOfBoundsException
getPageFormat
in interface java.awt.print.Pageable
java.lang.IndexOutOfBoundsException
Pageable.getPageFormat(int)
public void setPageFormat(int pageNumber, java.awt.print.PageFormat pageFormat)
pageNumber
- int the special page.pageFormat
- PageFormat the PageFormat object.public java.awt.print.Printable getPrintable(int pageIndex) throws java.lang.IndexOutOfBoundsException
getPrintable
in interface java.awt.print.Pageable
pageIndex
- int the index of the page.
java.lang.IndexOutOfBoundsException
Pageable.getPrintable(int)
public void setPrintPageRange(int startPage, int endPage)
startPage
- int the start page to print and larger than 1.endPage
- int the end page to print and larger than or equals startPage.public int getMediaBoxX(int pageNumber)
pageNumber
- int the page number of the current pdf file.
public int getMediaBoxY(int pageNumber)
pageNumber
- int the page number of the current pdf file.
public int getMediaBoxHeight(int pageNumber)
pageNumber
- int the page number of the current pdf file.
public int getMediaBoxWidth(int pageNumber)
pageNumber
- int the page number of the current pdf file.
public final void openPdfFile(java.io.InputStream inputStream) throws PdfViewerException, java.io.IOException
inputStream
- The pdf stream to be opened.
PdfViewerException
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |