public abstract class PdfDocumentBase extends Object
Modifier and Type | Field and Description |
---|---|
com.pd4ml.pdf.parser.PdfDoc |
pdf |
Constructor and Description |
---|
PdfDocumentBase(byte[] bytes,
String password) |
PdfDocumentBase(InputStream stream,
String password) |
PdfDocumentBase(URL url,
String password) |
Modifier and Type | Method and Description |
---|---|
void |
append(PdfDocumentBase toMerge) |
static boolean[] |
computeScope(String scope,
int pageNum)
Utility method converts page scope description to a boolean array of flags.
|
int |
deletePage(int pageNumber)
deletes a page of a loaded document.
|
String |
dumpOutlines() |
String |
getAuthor() |
String |
getCreationDate() |
String |
getCreator() |
String |
getKeywords() |
String |
getMetadata() |
String |
getModDate() |
int |
getNumberOfPages() |
String |
getPageContent(int pageIndex) |
String |
getPdfFormatVersion() |
int |
getPermissions() |
String |
getProducer() |
String |
getSubject() |
String |
getTitle() |
void |
overlay(PdfDocumentBase anotherDoc,
int opacity) |
void |
overlay(PdfDocumentBase anotherDoc,
String srcScope,
String destScope,
int opacity) |
void |
read()
reads and parses given PDF document stream
|
void |
setAuthor(String author) |
void |
setCreator(String creator) |
void |
setKeywords(String keywords) |
void |
setModDate()
sets the document modification date to "now"
|
void |
setSubject(String subject) |
void |
setTitle(String title) |
void |
underlay(PdfDocumentBase anotherDoc,
int opacity) |
void |
underlay(PdfDocumentBase anotherDoc,
String srcScope,
String destScope,
int opacity) |
void |
write(OutputStream out)
writes current PDF document state to given output stream.
|
void |
write(OutputStream out,
String password,
int permissions)
writes current PDF document state to given output stream.
|
public PdfDocumentBase(byte[] bytes, String password) throws InvokeException
bytes
- PDF document as an array of bytespassword
- if any. "null" for not protected PDF documentsInvokeException
- by invalid call parameterspublic PdfDocumentBase(InputStream stream, String password) throws InvokeException
stream
- PDF document input streampassword
- if any. "null" for not protected PDF documentsInvokeException
- by invalid call parameterspublic PdfDocumentBase(URL url, String password) throws InvokeException
url
- PDF document URLpassword
- if any. "null" for not protected PDF documentsInvokeException
- by invalid call parameterspublic void write(OutputStream out) throws IOException, InvokeException
out
- an output stream to write toIOException
- write errorsInvokeException
- if the document is already appended to another one (document objects reassigned to another root).public void write(OutputStream out, String password, int permissions) throws IOException, InvokeException, InvalidPasswordException
out
- an output stream to write topassword
- password string. null if no password to be appliedpermissions
- PDF file access permissions See PD4Constants.Allow* constants.
Example AllowAnnotate | AllowDegradedPrint. Use PD4Constants#DefaultPermissions for defaults.IOException
- write errorsInvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.InvokeException
- if the document is already appended to another one (document objects reassigned to another root).Constants.DefaultPermissions
public void append(PdfDocumentBase toMerge) throws IOException
toMerge
- another PDF document to append to the current one. Implicitly invokes read()
if has not been triggered before.IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.InvokeException
- by an attempt to merge with more than one documentpublic void overlay(PdfDocumentBase anotherDoc, int opacity) throws IOException
anotherDoc
- another PDF document whose page content is to be combined with the pages of the current document. Implicitly invokes read()
if has not been triggered before.
The method applies all pages of anotherDoc to all pages of this doc.opacity
- transparency of the overlay: 0 = fully transparent, 255 (or any negative value) = opaqueIOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.InvokeException
- by an attempt to merge with more than one documentcomputeScope(String, int)
public void overlay(PdfDocumentBase anotherDoc, String srcScope, String destScope, int opacity) throws IOException
anotherDoc
- another PDF document whose page content is to be combined with the pages of the current document. Implicitly invokes read()
if has not been triggered before.srcScope
- a page range of an overlay document to use.destScope
- a page range in the current document the overlay is to apply to.opacity
- transparency of the overlay: 0 = fully transparent, 255 (or any negative value) = opaqueIOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.InvokeException
- by an attempt to merge with more than one documentcomputeScope(String, int)
public void underlay(PdfDocumentBase anotherDoc, int opacity) throws IOException
anotherDoc
- another PDF document whose page content is to be placed under of the current document content. Implicitly invokes read()
if has not been triggered before.
The method applies all pages of anotherDoc to all pages of this doc.opacity
- transparency of the overlay: 0 = fully transparent, 255 (or any negative value) = opaqueIOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.InvokeException
- by an attempt to merge with more than one documentcomputeScope(String, int)
public void underlay(PdfDocumentBase anotherDoc, String srcScope, String destScope, int opacity) throws IOException
anotherDoc
- another PDF document whose page content is to be placed under of the current document content. Implicitly invokes read()
if has not been triggered before.srcScope
- a page range of an underlay document to use.destScope
- a page range in the current document the underlay is to apply to.opacity
- transparency of the overlay: 0 = fully transparent, 255 (or any negative value) = opaqueIOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.InvokeException
- by an attempt to merge with more than one documentcomputeScope(String, int)
public int getNumberOfPages() throws IOException, InvalidPasswordException
read()
if has not been triggered before.IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public int getPermissions() throws IOException, InvalidPasswordException
IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public String getTitle() throws IOException, InvalidPasswordException
read()
if has not been triggered before.IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public void setTitle(String title) throws IOException, InvalidPasswordException
title
- new document title. Implicitly invokes read()
if has not been triggered before.IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public String getAuthor() throws IOException, InvalidPasswordException
read()
if has not been triggered before.IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public void setAuthor(String author) throws IOException
author
- a value to override document "Author" name. Implicitly invokes read()
if has not been triggered before.IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public String getPdfFormatVersion() throws IOException, InvalidPasswordException
IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public String getMetadata() throws IOException, InvalidPasswordException
read()
if has not been triggered before.IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public String getCreationDate() throws IOException, InvalidPasswordException
read()
if has not been triggered before.IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public String dumpOutlines() throws IOException, InvalidPasswordException
read()
if has not been triggered before.IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public String getKeywords() throws IOException, InvalidPasswordException
read()
if has not been triggered before.IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public void setKeywords(String keywords) throws IOException, InvalidPasswordException
keywords
- a value to override document "Keywords" string. Implicitly invokes read()
if has not been triggered before.IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public String getCreator() throws IOException, InvalidPasswordException
read()
if has not been triggered before.IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public void setCreator(String creator) throws IOException, InvalidPasswordException
creator
- a value to override document "Creator" name. Implicitly invokes read()
if has not been triggered before.IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public String getProducer() throws IOException, InvalidPasswordException
read()
if has not been triggered before.IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public String getSubject() throws IOException, InvalidPasswordException
read()
if has not been triggered before.IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public void setSubject(String subject) throws IOException, InvalidPasswordException
subject
- a value to override document "Subject" string. Implicitly invokes read()
if has not been triggered before.IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public void setModDate() throws IOException, InvalidPasswordException
IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public String getModDate() throws IOException, InvalidPasswordException
read()
if has not been triggered before.IOException
- reflects a variety of PDF read/parse errors by read()
InvalidPasswordException
- invalid password given to the object constructor, i.e. PdfDocumentBase(byte[], String)
.public void read() throws IOException, InvokeException, InvalidPasswordException
IOException
- read/parsing errorsInvokeException
- PDF parsing specific errorsInvalidPasswordException
- PDF encryption password do not matchpublic String getPageContent(int pageIndex) throws InvalidPasswordException, IOException
pageIndex
- page number (0 is the first page)IOException
- read/parsing errorsInvalidPasswordException
- PDF encryption password do not matchpublic int deletePage(int pageNumber) throws InvalidPasswordException, IOException
pageNumber
- index of page to delete (first page is 1)IOException
- read/parsing errorsInvalidPasswordException
- PDF encryption password do not matchpublic static boolean[] computeScope(String scope, int pageNum)
scope
- "null" = all pages. Allowed syntax: "1", "3-5", "2+", "last", "even", "odd", "1+,skiplast", "5+,even"pageNum
- number of pagesRevision 4.0.9 / 20200806-0454