![]() |
||
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 | |
boolean |
canUserPrint(java.io.InputStream inputStream)
Shows the Encrypted pdf inputStream can print or not. |
boolean |
canUserPrint(java.lang.String filePath)
Shows the Encrypted pdf file can print or not. |
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 |
getCurrentHighlightIndex()
Gets current ID of textToFind for GUI Search. |
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. |
int |
getSearchEndPage()
Gets the search end page for GUI Search. |
int |
getSearchStartPage()
Gets the search start page for GUI Search. |
int |
getTextMatchedCount()
Gets the total matched number for GUI Search. |
void |
HighlightTextArea(int textMatchedIndex)
Highlights the matched text area. |
void |
invalidate()
Invalidates the container. |
boolean |
isEncryptedFile(java.io.InputStream inputStream)
Shows the Pdf file stream is Encrypted or not. |
boolean |
isEncryptedFile(java.lang.String filePath)
Shows the Pdf file is Encrypted or not. |
boolean |
isOwnerPassword(java.io.InputStream inputStream,
java.lang.String ownerPassword)
Shows the password is the owner password of the Encrypted Pdf file inputStream or not. |
boolean |
isOwnerPassword(java.lang.String filePath,
java.lang.String ownerPassword)
Shows the password is the owner password of the Encrypted Pdf file or not. |
boolean |
isPrintSuccess()
Shows the Pdf page print successful or not. |
boolean |
isUserPassword(java.io.InputStream inputStream,
java.lang.String userPassword)
Shows the password is the user password password of the Encrypted Pdf file or not.If the user is the user(not the owner),he has limited access to the pdf file ,including printing and so on. |
boolean |
isUserPassword(java.lang.String filePath,
java.lang.String userPassword)
Shows the password is the user password of the Encrypted Pdf file or not. |
void |
openPdfFile(java.io.InputStream inputStream)
Opens a Pdf file stream. |
void |
openPdfFile(java.io.InputStream inputStream,
java.lang.String password)
Opens an encrypted Pdf file stream. |
void |
openPdfFile(java.lang.String filePath)
Opens a Pdf file, but does not actually decode the pages of the Pdf file. |
void |
openPdfFile(java.lang.String filePath,
java.lang.String password)
Opens an encrypted Pdf document. |
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 |
searchText(java.lang.String textToSearch)
Searches text from startPage to endPage. |
void |
searchText(java.lang.String textToSearch,
boolean isCaseSensitive)
Searches text from startPage to endPage. |
void |
searchText(java.lang.String textToSearch,
boolean isCaseSensitive,
java.awt.Color HightLightColor)
Searches text to get location of textToSearch within the rectangle from startPage to endPage.And shows itemFoundCount in searchCount TextField. |
void |
searchText(java.lang.String textToSearch,
java.awt.Color hightlightColor)
Searches text from startPage to endPage. |
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. |
void |
setSearchEndPage(int endPage)
Sets the search end page for GUI Search. |
void |
setSearchStartPage(int startPage)
Sets the search start page for GUI Search. |
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, java.lang.Exception
inputStream
- InputStream the pdf stream to be opened.
PdfViewerException
java.io.IOException
java.lang.Exception
public final void openPdfFile(java.io.InputStream inputStream, java.lang.String password) throws PdfViewerException, java.lang.Exception
inputStream
- InputStream the encrypted pdf stream to be opened.password
- String the password of the file.
PdfViewerException
java.lang.Exception
public final void openPdfFile(java.lang.String filePath, java.lang.String password) throws PdfViewerException, java.lang.Exception
filePath
- String the file path of the encrypted Pdf document to be opened.password
- String the password of the file.
PdfViewerException
java.lang.Exception
public void setSearchStartPage(int startPage)
startPage
- int the start page of pdf file to be searched in GUI.public int getSearchStartPage()
public void setSearchEndPage(int endPage)
endPage
- int the end page of pdf file to be searched in GUI.public int getSearchEndPage()
public void searchText(java.lang.String textToSearch) throws PdfViewerException, java.lang.Exception
textToSearch
- String text to be searched.
PdfViewerException
java.lang.Exception
public void searchText(java.lang.String textToSearch, boolean isCaseSensitive) throws PdfViewerException, java.lang.Exception
textToSearch
- String text to be searched.isCaseSensitive
- boolean shows the text comparison case senitive or not.
true - case sensitive comparison when searching.
false - not case sensitive comparison when searching.
PdfViewerException
java.lang.Exception
public void searchText(java.lang.String textToSearch, java.awt.Color hightlightColor) throws PdfViewerException, java.lang.Exception
textToSearch
- String text to be searched.hightlightColor
- Color the color of searched text.
PdfViewerException
java.lang.Exception
public void searchText(java.lang.String textToSearch, boolean isCaseSensitive, java.awt.Color HightLightColor) throws PdfViewerException, java.lang.Exception
textToSearch
- String text to be found.isCaseSensitive
- boolean if a case sensitive comparison happens or not when
searching.HightLightColor
- Color color of textToSearch.
PdfViewerException
java.lang.Exception
public int getTextMatchedCount()
public int getCurrentHighlightIndex()
public void HighlightTextArea(int textMatchedIndex) throws PdfViewerException, java.lang.Exception
textMatchedIndex
- int the index of search result.
PdfViewerException
java.lang.Exception
public boolean isEncryptedFile(java.lang.String filePath) throws java.io.IOException
filePath
- String the path of Pdf file.
IOException.
java.io.IOException
public boolean isEncryptedFile(java.io.InputStream inputStream) throws java.io.IOException
inputStream
- InputStream the stream of Pdf file.
IOException.
java.io.IOException
public boolean isOwnerPassword(java.io.InputStream inputStream, java.lang.String ownerPassword) throws java.io.IOException, com.aspose.pdf.kit.CryptographyException
inputStream
- InputStream the stream of Pdf file.ownerPassword
- String the owner password of the Pdf file.If the user is the
owner ,he has full access to the pdf file ,including viewing, printing and so on.
CryptographyException.
IOException.
java.io.IOException
com.aspose.pdf.kit.CryptographyException
public boolean isOwnerPassword(java.lang.String filePath, java.lang.String ownerPassword) throws java.io.IOException, com.aspose.pdf.kit.CryptographyException
filePath
- String the path of the Pdf file.ownerPassword
- String the owner password of the Pdf file.If the user is the
owner ,he has full access to the pdf file ,including printing and so on.
CryptographyException.
IOException.
java.io.IOException
com.aspose.pdf.kit.CryptographyException
public boolean isUserPassword(java.lang.String filePath, java.lang.String userPassword) throws java.io.IOException, com.aspose.pdf.kit.CryptographyException
filePath
- String the path of the Pdf file.userPassword
- String the user password of the Pdf file.If the user is the
user(not the owner),he has limited access to the pdf file ,including printing and so on.
CryptographyException.
IOException.
java.io.IOException
com.aspose.pdf.kit.CryptographyException
public boolean isUserPassword(java.io.InputStream inputStream, java.lang.String userPassword) throws java.io.IOException, com.aspose.pdf.kit.CryptographyException
inputStream
- InputStream the stream of Pdf file.userPassword
- String the user password of the Pdf file.
CryptographyException.
IOException.
java.io.IOException
com.aspose.pdf.kit.CryptographyException
public boolean canUserPrint(java.lang.String filePath) throws java.io.IOException
filePath
- String the path of the Pdf file.
IOException.
java.io.IOException
public boolean canUserPrint(java.io.InputStream inputStream) throws java.io.IOException
inputStream
- InputStream the stream of Pdf file.
IOException.
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |