public class PDDocument extends Object implements Closeable
| Modifier and Type | Class and Description |
|---|---|
static interface |
PDDocument.OnClose
Action to be performed before the
PDDocument is close |
| Constructor and Description |
|---|
PDDocument() |
PDDocument(COSDocument document)
Constructor that uses an existing document.
|
PDDocument(COSDocument document,
SecurityHandler securityHandler)
Constructor that uses an existing document.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addPage(PDPage page)
This will add a page to the document.
|
void |
close()
Closes the
PDDocument executing the set onClose action. |
COSString |
generateFileIdentifier(byte[] md5Update) |
AccessPermission |
getCurrentAccessPermission()
Returns the access permissions granted when the document was decrypted.
|
COSDocument |
getDocument() |
PDDocumentCatalog |
getDocumentCatalog()
This will get the document CATALOG.
|
PDDocumentInformation |
getDocumentInformation()
This will get the document info dictionary.
|
PDEncryption |
getEncryption()
This will get the encryption dictionary for this document.
|
Set<Subsettable> |
getFontsToSubset() |
int |
getNumberOfPages() |
PDPage |
getPage(int pageIndex) |
PDPageTree |
getPages() |
ResourceCache |
getResourceCache()
Returns the resource cache associated with this document, or null if there is none.
|
SecurityHandler |
getSecurityHandler() |
String |
getVersion() |
PDPage |
importPage(PDPage page)
This will import and copy the contents from another location.
|
boolean |
isEncrypted() |
boolean |
isOpen() |
static PDDocument |
load(File file) |
void |
registerTrueTypeFontForClosing(org.apache.fontbox.ttf.TrueTypeFont ttf)
For internal PDFBox use when creating PDF documents: register a TrueTypeFont to make sure it is closed when the
PDDocument is closed to avoid memory leaks.
|
void |
removePage(int pageNumber)
Remove the page from the document.
|
void |
removePage(PDPage page)
Remove the page from the document.
|
void |
requireMinVersion(String version)
If the document is not at the given version or above, it sets the version of the PDF specification to which the
document conforms.
|
void |
setDocumentInformation(PDDocumentInformation documentInformation)
This will set the document information for this document.
|
void |
setOnCloseAction(PDDocument.OnClose onClose)
Sets an action to be performed right before this
PDDocument is closed. |
void |
setVersion(String newVersion)
Sets the version of the PDF specification to which the document conforms.
|
void |
writeTo(File file,
StandardSecurity security,
WriteOption... options)
Writes the document to the given
File encrypting it using the given security. |
void |
writeTo(File file,
WriteOption... options)
Writes the document to the given
File. |
void |
writeTo(OutputStream out,
StandardSecurity security,
WriteOption... options)
Writes the document to the given
OutputStream encrypting it using the given security. |
void |
writeTo(OutputStream out,
WriteOption... options)
Writes the document to the given
OutputStream. |
void |
writeTo(String filename,
StandardSecurity security,
WriteOption... options)
Writes the document to the file corresponding the given file name encrypting it using the given security.
|
void |
writeTo(String filename,
WriteOption... options)
Writes the document to the file corresponding the given file name.
|
void |
writeTo(WritableByteChannel channel,
StandardSecurity security,
WriteOption... options)
Writes the document to the given
WritableByteChannel encrypting it using the given security. |
void |
writeTo(WritableByteChannel channel,
WriteOption... options)
Writes the document to the given
WritableByteChannel. |
public PDDocument()
public PDDocument(COSDocument document)
document - The COSDocument that this document wraps.public PDDocument(COSDocument document, SecurityHandler securityHandler)
document - The COSDocument that this document wraps.securityHandler - public void addPage(PDPage page)
page - The page to add to the document.public void removePage(PDPage page)
page - The page to remove from the document.public void removePage(int pageNumber)
pageNumber - 0 based index to page number.public PDPage importPage(PDPage page)
page - The page to import.public COSDocument getDocument()
public PDDocumentInformation getDocumentInformation()
public void setDocumentInformation(PDDocumentInformation documentInformation)
info - The updated document information.public PDDocumentCatalog getDocumentCatalog()
public boolean isEncrypted()
public PDEncryption getEncryption()
public void registerTrueTypeFontForClosing(org.apache.fontbox.ttf.TrueTypeFont ttf)
ttf - public Set<Subsettable> getFontsToSubset()
public PDPage getPage(int pageIndex)
pageIndex - the page indexpublic PDPageTree getPages()
public int getNumberOfPages()
public AccessPermission getCurrentAccessPermission()
public SecurityHandler getSecurityHandler()
public String getVersion()
public void setVersion(String newVersion)
newVersion - the new PDF versionpublic void requireMinVersion(String version)
version - public void setOnCloseAction(PDDocument.OnClose onClose)
PDDocument is closed.onClose - public COSString generateFileIdentifier(byte[] md5Update)
md5Update - public void writeTo(File file, WriteOption... options) throws IOException
File. The document is closed once written.file - options - IOExceptionclose()public void writeTo(String filename, WriteOption... options) throws IOException
filename - options - IOExceptionclose()public void writeTo(WritableByteChannel channel, WriteOption... options) throws IOException
WritableByteChannel. The document is closed once written.channel - options - IOExceptionclose()public void writeTo(OutputStream out, WriteOption... options) throws IOException
OutputStream. The document is closed once written.out - options - IOExceptionclose()public void writeTo(File file, StandardSecurity security, WriteOption... options) throws IOException
File encrypting it using the given security. The document is closed once
written.file - security - options - IOExceptionclose()public void writeTo(String filename, StandardSecurity security, WriteOption... options) throws IOException
filename - security - options - IOExceptionclose()public void writeTo(WritableByteChannel channel, StandardSecurity security, WriteOption... options) throws IOException
WritableByteChannel encrypting it using the given security. The document
is closed once written.channel - security - options - IOExceptionclose()public void writeTo(OutputStream out, StandardSecurity security, WriteOption... options) throws IOException
OutputStream encrypting it using the given security. The document is
closed once written.out - security - options - IOExceptionclose()public boolean isOpen()
PDDocument is openpublic void close()
throws IOException
PDDocument executing the set onClose action. Once closed the document is pretty much unusable
since most of the methods requires an open document.close in interface Closeableclose in interface AutoCloseableIOExceptionsetOnCloseAction(OnClose)public ResourceCache getResourceCache()
public static PDDocument load(File file) throws IOException
IOExceptionCopyright © 2020 sejda. All rights reserved.