org.zefer.pd4ml.npdf
Class PD4DocumentBase

java.lang.Object
  extended by org.zefer.pd4ml.npdf.PD4DocumentBase
Direct Known Subclasses:
PD4Document

public abstract class PD4DocumentBase
extends java.lang.Object


Field Summary
protected  byte[] bytes
           
protected  short debug
           
protected  boolean newDocument
           
protected  PD4DocumentBase overlay
           
protected  boolean[] overlayDestScope
           
protected  int overlayOpacity
           
protected  boolean[] overlaySrcScope
           
protected  java.lang.String password
           
 PdfDocument pdf
           
protected  boolean reassignedToAnotherDocument
           
protected  java.io.InputStream stream
           
protected  PD4DocumentBase toMerge
           
protected  boolean underlayFlag
           
protected  java.net.URL url
           
 
Constructor Summary
protected PD4DocumentBase()
           
  PD4DocumentBase(byte[] bytes, java.lang.String password)
           
  PD4DocumentBase(java.io.InputStream stream, java.lang.String password)
           
  PD4DocumentBase(java.net.URL url, java.lang.String password)
           
 
Method Summary
 void append(PD4DocumentBase toMerge)
           
static boolean[] computeScope(java.lang.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.
 java.lang.String dumpOutlines()
           
 java.lang.String getAuthor()
           
 java.lang.String getCreationDate()
           
 java.lang.String getCreator()
           
 java.lang.String getKeywords()
           
 java.lang.String getModDate()
           
 int getNumberOfPages()
           
protected  int getObjectCounter()
           
 java.lang.String getPageContent(int pageIndex)
           
 java.lang.String getPdfFormatVersion()
           
 int getPermissions()
           
 java.lang.String getProducer()
           
 java.lang.String getSubject()
           
 java.lang.String getTitle()
           
 void overlay(PD4DocumentBase anotherDoc, int opacity)
           
 void overlay(PD4DocumentBase anotherDoc, java.lang.String srcScope, java.lang.String destScope, int opacity)
           
 void read()
          reads and parses given PDF document stream
protected abstract  void read(int objectCounter)
          reads and parses given PDF document stream
protected  void readIfNeeded()
          checks if read() has been already invoked.
 void setAuthor(java.lang.String author)
           
 void setCreator(java.lang.String creator)
           
 void setKeywords(java.lang.String keywords)
           
 void setModDate()
          sets the document modification date to "now"
 void setSubject(java.lang.String subject)
           
 void setTitle(java.lang.String title)
           
 void underlay(PD4DocumentBase anotherDoc, int opacity)
           
 void underlay(PD4DocumentBase anotherDoc, java.lang.String srcScope, java.lang.String destScope, int opacity)
           
 void write(java.io.OutputStream out)
          writes current PDF document state to given output stream.
 void write(java.io.OutputStream out, java.lang.String password, int permissions)
          writes current PDF document state to given output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stream

protected java.io.InputStream stream

url

protected java.net.URL url

bytes

protected byte[] bytes

password

protected java.lang.String password

debug

protected short debug

pdf

public PdfDocument pdf

toMerge

protected PD4DocumentBase toMerge

overlay

protected PD4DocumentBase 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 Detail

PD4DocumentBase

protected PD4DocumentBase()

PD4DocumentBase

public PD4DocumentBase(byte[] bytes,
                       java.lang.String password)
                throws PD4InvokeException
Parameters:
bytes - PDF document as an array of bytes
password - if any. "null" for not protected PDF documents
Throws:
PD4InvokeException - by invalid call parameters

PD4DocumentBase

public PD4DocumentBase(java.io.InputStream stream,
                       java.lang.String password)
                throws PD4InvokeException
Parameters:
stream - PDF document input stream
password - if any. "null" for not protected PDF documents
Throws:
PD4InvokeException - by invalid call parameters

PD4DocumentBase

public PD4DocumentBase(java.net.URL url,
                       java.lang.String password)
                throws PD4InvokeException
Parameters:
url - PDF document URL
password - if any. "null" for not protected PDF documents
Throws:
PD4InvokeException - by invalid call parameters
Method Detail

write

public void write(java.io.OutputStream out)
           throws java.io.IOException,
                  PD4InvokeException
writes current PDF document state to given output stream.

Parameters:
out - an output stream to write to
Throws:
java.io.IOException - write errors
PD4InvokeException - if the document is already appended to another one (document objects reassigned to another root).

write

public void write(java.io.OutputStream out,
                  java.lang.String password,
                  int permissions)
           throws java.io.IOException,
                  PD4InvokeException,
                  PD4InvalidPasswordException
writes current PDF document state to given output stream.

Parameters:
out - an output stream to write to
password - password string. null if no password to be applied
permissions - PDF file access permissions See PD4Constants.Allow* constants. Example AllowAnnotate | AllowDegradedPrint. Use PD4Constants#DefaultPermissions for defaults.
Throws:
java.io.IOException - write errors
PD4InvalidPasswordException - 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 java.io.IOException
Parameters:
toMerge - another PDF document to append to the current one. Implicitly invokes read() if has not been triggered before.
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
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 java.io.IOException
Parameters:
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) = opaque
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
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,
                    java.lang.String srcScope,
                    java.lang.String destScope,
                    int opacity)
             throws java.io.IOException
Parameters:
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) = opaque
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
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 java.io.IOException
Parameters:
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) = opaque
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
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,
                     java.lang.String srcScope,
                     java.lang.String destScope,
                     int opacity)
              throws java.io.IOException
Parameters:
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) = opaque
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
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)

readIfNeeded

protected void readIfNeeded()
                     throws java.io.IOException,
                            PD4InvalidPasswordException
checks if read() has been already invoked. Invokes if not.

Throws:
java.io.IOException
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

getNumberOfPages

public int getNumberOfPages()
                     throws java.io.IOException,
                            PD4InvalidPasswordException
Returns:
returns a number of pages in the current PDF. Implicitly invokes read() if has not been triggered before.
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

getPermissions

public int getPermissions()
                   throws java.io.IOException,
                          PD4InvalidPasswordException
Returns:
returns permissions flag of the document
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

getTitle

public java.lang.String getTitle()
                          throws java.io.IOException,
                                 PD4InvalidPasswordException
Returns:
PDF "Title" metadata value (if any). Implicitly invokes read() if has not been triggered before.
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

setTitle

public void setTitle(java.lang.String title)
              throws java.io.IOException,
                     PD4InvalidPasswordException
Parameters:
title - new document title. Implicitly invokes read() if has not been triggered before.
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

getAuthor

public java.lang.String getAuthor()
                           throws java.io.IOException,
                                  PD4InvalidPasswordException
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

setAuthor

public void setAuthor(java.lang.String author)
               throws java.io.IOException
Parameters:
author - a value to override document "Author" name. Implicitly invokes read() if has not been triggered before.
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

getPdfFormatVersion

public java.lang.String getPdfFormatVersion()
                                     throws java.io.IOException,
                                            PD4InvalidPasswordException
Returns:
PDF format version from PDF document prefix.
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

getCreationDate

public java.lang.String getCreationDate()
                                 throws java.io.IOException,
                                        PD4InvalidPasswordException
Returns:
PDF creation date as a string. Implicitly invokes read() if has not been triggered before.
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

dumpOutlines

public java.lang.String dumpOutlines()
                              throws java.io.IOException,
                                     PD4InvalidPasswordException
Returns:
dumps document outline (bookmark) structure. Implicitly invokes read() if has not been triggered before.
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

getKeywords

public java.lang.String getKeywords()
                             throws java.io.IOException,
                                    PD4InvalidPasswordException
Returns:
PDF "Keywords" metadata value (if any). Implicitly invokes read() if has not been triggered before.
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

setKeywords

public void setKeywords(java.lang.String keywords)
                 throws java.io.IOException,
                        PD4InvalidPasswordException
Parameters:
keywords - a value to override document "Keywords" string. Implicitly invokes read() if has not been triggered before.
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

getCreator

public java.lang.String getCreator()
                            throws java.io.IOException,
                                   PD4InvalidPasswordException
Returns:
PDF "Creator" metadata value (if any). Implicitly invokes read() if has not been triggered before.
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

setCreator

public void setCreator(java.lang.String creator)
                throws java.io.IOException,
                       PD4InvalidPasswordException
Parameters:
creator - a value to override document "Creator" name. Implicitly invokes read() if has not been triggered before.
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

getProducer

public java.lang.String getProducer()
                             throws java.io.IOException,
                                    PD4InvalidPasswordException
Returns:
PDF "Producer" metadata value (if any). Implicitly invokes read() if has not been triggered before.
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

getSubject

public java.lang.String getSubject()
                            throws java.io.IOException,
                                   PD4InvalidPasswordException
Returns:
PDF "Subject" metadata value (if any). Implicitly invokes read() if has not been triggered before.
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

setSubject

public void setSubject(java.lang.String subject)
                throws java.io.IOException,
                       PD4InvalidPasswordException
Parameters:
subject - a value to override document "Subject" string. Implicitly invokes read() if has not been triggered before.
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

setModDate

public void setModDate()
                throws java.io.IOException,
                       PD4InvalidPasswordException
sets the document modification date to "now"

Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

getModDate

public java.lang.String getModDate()
                            throws java.io.IOException,
                                   PD4InvalidPasswordException
Returns:
Document modification date. Implicitly invokes read() if has not been triggered before.
Throws:
java.io.IOException - reflects a variety of PDF read/parse errors by read()
PD4InvalidPasswordException - invalid password given to the object constructor, i.e. #PD4Document(byte[], String).

read

public void read()
          throws java.io.IOException,
                 PD4InvokeException,
                 PD4InvalidPasswordException
reads and parses given PDF document stream

Throws:
java.io.IOException - read/parsing errors
PD4InvokeException - PDF parsing specific errors
PD4InvalidPasswordException

read

protected abstract void read(int objectCounter)
                      throws java.io.IOException,
                             PD4InvalidPasswordException
reads and parses given PDF document stream

Parameters:
objectCounter - initial object number to re-index PDF objects. Used by PDF merge scenarios
Throws:
java.io.IOException - read/parsing errors
PD4InvalidPasswordException

getObjectCounter

protected int getObjectCounter()
Returns:
number of already read PDF objects

getPageContent

public java.lang.String getPageContent(int pageIndex)
                                throws PD4InvalidPasswordException,
                                       java.io.IOException
Throws:
PD4InvalidPasswordException
java.io.IOException

deletePage

public int deletePage(int pageNumber)
               throws PD4InvalidPasswordException,
                      java.io.IOException
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
java.io.IOException

computeScope

public static boolean[] computeScope(java.lang.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.


Copyright © 2004-15 zefer.org. All Rights Reserved.