Package org.zefer.pd4ml.npdf
Class PD4DocumentBase
- java.lang.Object
-
- org.zefer.pd4ml.npdf.PD4DocumentBase
-
- Direct Known Subclasses:
PD4Document
public abstract class PD4DocumentBase extends Object
-
-
Field Summary
Fields Modifier and Type Field Description org.zefer.pd4ml.npdf.parser.PdfDocumentpdf
-
Constructor Summary
Constructors Constructor Description PD4DocumentBase(byte[] bytes, String password)PD4DocumentBase(InputStream stream, String password)PD4DocumentBase(URL url, String password)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(PD4DocumentBase toMerge)static boolean[]computeScope(String scope, int pageNum)Utility method converts page scope description to a boolean array of flags.intdeletePage(int pageNumber)deletes a page of a loaded document.StringdumpOutlines()StringgetAuthor()StringgetCreationDate()StringgetCreator()StringgetKeywords()StringgetModDate()intgetNumberOfPages()StringgetPageContent(int pageIndex)StringgetPdfFormatVersion()intgetPermissions()StringgetProducer()StringgetSubject()StringgetTitle()voidoverlay(PD4DocumentBase anotherDoc, int opacity)voidoverlay(PD4DocumentBase anotherDoc, String srcScope, String destScope, int opacity)voidread()reads and parses given PDF document streamvoidsetAuthor(String author)voidsetCreator(String creator)voidsetKeywords(String keywords)voidsetModDate()sets the document modification date to "now"voidsetSubject(String subject)voidsetTitle(String title)voidunderlay(PD4DocumentBase anotherDoc, int opacity)voidunderlay(PD4DocumentBase anotherDoc, String srcScope, String destScope, int opacity)voidwrite(OutputStream out)writes current PDF document state to given output stream.voidwrite(OutputStream out, String password, int permissions)writes current PDF document state to given output stream.
-
-
-
Constructor Detail
-
PD4DocumentBase
public PD4DocumentBase(byte[] bytes, String password) throws PD4InvokeException- Parameters:
bytes- PDF document as an array of bytespassword- if any. "null" for not protected PDF documents- Throws:
PD4InvokeException- by invalid call parameters
-
PD4DocumentBase
public PD4DocumentBase(InputStream stream, String password) throws PD4InvokeException
- Parameters:
stream- PDF document input streampassword- if any. "null" for not protected PDF documents- Throws:
PD4InvokeException- by invalid call parameters
-
PD4DocumentBase
public PD4DocumentBase(URL url, String password) throws PD4InvokeException
- Parameters:
url- PDF document URLpassword- if any. "null" for not protected PDF documents- Throws:
PD4InvokeException- by invalid call parameters
-
-
Method Detail
-
write
public void write(OutputStream out) throws IOException, PD4InvokeException
writes current PDF document state to given output stream.- Parameters:
out- an output stream to write to- Throws:
IOException- write errorsPD4InvokeException- if the document is already appended to another one (document objects reassigned to another root).
-
write
public void write(OutputStream out, String password, int permissions) throws IOException, PD4InvokeException, PD4InvalidPasswordException
writes current PDF document state to given output stream.- Parameters:
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. UsePD4Constants#DefaultPermissionsfor defaults.- Throws:
IOException- write errorsPD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).PD4InvokeException- if the document is already appended to another one (document objects reassigned to another root).
-
append
public void append(PD4DocumentBase toMerge) throws IOException
- Parameters:
toMerge- another PDF document to append to the current one. Implicitly invokesread()if has not been triggered before.- Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).PD4InvokeException- by an attempt to merge with more than one document
-
overlay
public void overlay(PD4DocumentBase anotherDoc, int opacity) throws IOException
- Parameters:
anotherDoc- another PDF document whose page content is to be combined with the pages of the current document. Implicitly invokesread()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) = opaque- Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).PD4InvokeException- by an attempt to merge with more than one document- See Also:
computeScope(String, int)
-
overlay
public void overlay(PD4DocumentBase anotherDoc, String srcScope, String destScope, int opacity) throws IOException
- Parameters:
anotherDoc- another PDF document whose page content is to be combined with the pages of the current document. Implicitly invokesread()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) = opaque- Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).PD4InvokeException- by an attempt to merge with more than one document- See Also:
computeScope(String, int)
-
underlay
public void underlay(PD4DocumentBase anotherDoc, int opacity) throws IOException
- Parameters:
anotherDoc- another PDF document whose page content is to be placed under of the current document content. Implicitly invokesread()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) = opaque- Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).PD4InvokeException- by an attempt to merge with more than one document- See Also:
computeScope(String, int)
-
underlay
public void underlay(PD4DocumentBase anotherDoc, String srcScope, String destScope, int opacity) throws IOException
- Parameters:
anotherDoc- another PDF document whose page content is to be placed under of the current document content. Implicitly invokesread()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) = opaque- Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).PD4InvokeException- by an attempt to merge with more than one document- See Also:
computeScope(String, int)
-
getNumberOfPages
public int getNumberOfPages() throws IOException, PD4InvalidPasswordException- Returns:
- returns a number of pages in the current PDF. Implicitly invokes
read()if has not been triggered before. - Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
getPermissions
public int getPermissions() throws IOException, PD4InvalidPasswordException- Returns:
- returns permissions flag of the document
- Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
getTitle
public String getTitle() throws IOException, PD4InvalidPasswordException
- Returns:
- PDF "Title" metadata value (if any). Implicitly invokes
read()if has not been triggered before. - Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
setTitle
public void setTitle(String title) throws IOException, PD4InvalidPasswordException
- Parameters:
title- new document title. Implicitly invokesread()if has not been triggered before.- Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
getAuthor
public String getAuthor() throws IOException, PD4InvalidPasswordException
- Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
setAuthor
public void setAuthor(String author) throws IOException
- Parameters:
author- a value to override document "Author" name. Implicitly invokesread()if has not been triggered before.- Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
getPdfFormatVersion
public String getPdfFormatVersion() throws IOException, PD4InvalidPasswordException
- Returns:
- PDF format version from PDF document prefix.
- Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
getCreationDate
public String getCreationDate() throws IOException, PD4InvalidPasswordException
- Returns:
- PDF creation date as a string. Implicitly invokes
read()if has not been triggered before. - Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
dumpOutlines
public String dumpOutlines() throws IOException, PD4InvalidPasswordException
- Returns:
- dumps document outline (bookmark) structure. Implicitly invokes
read()if has not been triggered before. - Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
getKeywords
public String getKeywords() throws IOException, PD4InvalidPasswordException
- Returns:
- PDF "Keywords" metadata value (if any). Implicitly invokes
read()if has not been triggered before. - Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
setKeywords
public void setKeywords(String keywords) throws IOException, PD4InvalidPasswordException
- Parameters:
keywords- a value to override document "Keywords" string. Implicitly invokesread()if has not been triggered before.- Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
getCreator
public String getCreator() throws IOException, PD4InvalidPasswordException
- Returns:
- PDF "Creator" metadata value (if any). Implicitly invokes
read()if has not been triggered before. - Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
setCreator
public void setCreator(String creator) throws IOException, PD4InvalidPasswordException
- Parameters:
creator- a value to override document "Creator" name. Implicitly invokesread()if has not been triggered before.- Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
getProducer
public String getProducer() throws IOException, PD4InvalidPasswordException
- Returns:
- PDF "Producer" metadata value (if any). Implicitly invokes
read()if has not been triggered before. - Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
getSubject
public String getSubject() throws IOException, PD4InvalidPasswordException
- Returns:
- PDF "Subject" metadata value (if any). Implicitly invokes
read()if has not been triggered before. - Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
setSubject
public void setSubject(String subject) throws IOException, PD4InvalidPasswordException
- Parameters:
subject- a value to override document "Subject" string. Implicitly invokesread()if has not been triggered before.- Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
setModDate
public void setModDate() throws IOException, PD4InvalidPasswordExceptionsets the document modification date to "now"- Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
getModDate
public String getModDate() throws IOException, PD4InvalidPasswordException
- Returns:
- Document modification date. Implicitly invokes
read()if has not been triggered before. - Throws:
IOException- reflects a variety of PDF read/parse errors byread()PD4InvalidPasswordException- invalid password given to the object constructor, i.e.#PD4Document(byte[], String).
-
read
public void read() throws IOException, PD4InvokeException, PD4InvalidPasswordExceptionreads and parses given PDF document stream- Throws:
IOException- read/parsing errorsPD4InvokeException- PDF parsing specific errorsPD4InvalidPasswordException
-
getPageContent
public String getPageContent(int pageIndex) throws PD4InvalidPasswordException, IOException
-
deletePage
public int deletePage(int pageNumber) throws PD4InvalidPasswordException, IOExceptiondeletes a page of a loaded document. If the document has only one page or not existent page number is given, the method call takes no effect.- Parameters:
pageNumber- index of page to delete (first page is 1)- Returns:
- number of pages remain in the doc.
- Throws:
PD4InvalidPasswordExceptionIOException
-
computeScope
public static boolean[] computeScope(String scope, int pageNum)
Utility method converts page scope description to a boolean array of flags. "true" = page number matches the scope, "false" = does not. Note: in scope definition the first page is "1"; it corresponds to '0" index in the returned array.- Parameters:
scope- "null" = all pages. Allowed syntax: "1", "3-5", "2+", "last", "even", "odd", "1+,skiplast", "5+,even"pageNum- number of pages- Returns:
- an array of scope match flags. Each array item corresponds a page.
-
-