Package org.zefer.pd4ml.npdf
Class PD4DocumentBase
java.lang.Object
org.zefer.pd4ml.npdf.PD4DocumentBase
- Direct Known Subclasses:
PD4Document
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]
protected short
protected boolean
protected PD4DocumentBase
protected boolean[]
protected int
protected boolean[]
protected String
PdfDocument
protected boolean
protected InputStream
protected PD4DocumentBase
protected boolean
protected URL
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
PD4DocumentBase
(byte[] bytes, String password) PD4DocumentBase
(InputStream stream, String password) PD4DocumentBase
(URL url, String password) -
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(PD4DocumentBase 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.int
protected int
getPageContent
(int pageIndex) int
getTitle()
void
overlay
(PD4DocumentBase anotherDoc, int opacity) void
overlay
(PD4DocumentBase anotherDoc, String srcScope, String destScope, int opacity) void
read()
reads and parses given PDF document streamprotected abstract void
read
(int objectCounter) reads and parses given PDF document streamprotected void
checks ifread()
has been already invoked.void
void
setCreator
(String creator) void
setKeywords
(String keywords) void
sets the document modification date to "now"void
setSubject
(String subject) void
void
underlay
(PD4DocumentBase anotherDoc, int opacity) void
underlay
(PD4DocumentBase 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.
-
Field Details
-
stream
-
url
-
bytes
protected byte[] bytes -
password
-
debug
protected short debug -
pdf
public PdfDocument pdf -
toMerge
-
overlay
-
overlaySrcScope
protected boolean[] overlaySrcScope -
overlayDestScope
protected boolean[] overlayDestScope -
overlayOpacity
protected int overlayOpacity -
underlayFlag
protected boolean underlayFlag -
newDocument
protected boolean newDocument -
reassignedToAnotherDocument
protected boolean reassignedToAnotherDocument
-
-
Constructor Details
-
PD4DocumentBase
protected PD4DocumentBase() -
PD4DocumentBase
- Parameters:
bytes
- PDF document as an array of bytespassword
- if any. "null" for not protected PDF documents- Throws:
PD4InvokeException
- by invalid call parameters
-
PD4DocumentBase
- Parameters:
stream
- PDF document input streampassword
- if any. "null" for not protected PDF documents- Throws:
PD4InvokeException
- by invalid call parameters
-
PD4DocumentBase
- Parameters:
url
- PDF document URLpassword
- if any. "null" for not protected PDF documents- Throws:
PD4InvokeException
- by invalid call parameters
-
-
Method Details
-
write
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#DefaultPermissions
for 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
- 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
- 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:
-
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:
-
underlay
- 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:
-
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:
-
readIfNeeded
checks ifread()
has been already invoked. Invokes if not.- Throws:
IOException
PD4InvalidPasswordException
- invalid password given to the object constructor, i.e.#PD4Document(byte[], String)
.
-
getNumberOfPages
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
sets 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
- 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
reads and parses given PDF document stream- Throws:
IOException
- read/parsing errorsPD4InvokeException
- PDF parsing specific errorsPD4InvalidPasswordException
-
read
reads and parses given PDF document stream- Parameters:
objectCounter
- initial object number to re-index PDF objects. Used by PDF merge scenarios- Throws:
IOException
- read/parsing errorsPD4InvalidPasswordException
-
getObjectCounter
protected int getObjectCounter()- Returns:
- number of already read PDF objects
-
getPageContent
-
deletePage
deletes 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:
PD4InvalidPasswordException
IOException
-
computeScope
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.
-