public class SDFDoc extends Doc
SDFDoc mydoc = new SDFDoc("in.pdf");
Obj trailer = mydoc.getTrailer();
or from a memory buffer or some other Filter/Stream such as a HTTP Filter connection:
MemoryFilter memory = ....
SDFDoc mydoc = new SDFDoc(memory);
Obj trailer = mydoc.getTrailer();
Finally SDF document can be accessed from a high-level PDF document as follows:
PDFDoc doc = new PDFDoc("in.pdf");
SDFDoc mydoc = doc.getSDFDoc();
Obj trailer = mydoc.getTrailer();
Note that the examples above used doc.GetTrailer() in order to access document
trailer, the starting SDF object (root node) in every document. Following the trailer
links, it is possible to visit all low-level objects in a document (e.g. all pages,
outlines, fonts, etc).
SDFDoc also provides utility methods used to import objects and object collections
from one document to another. These methods can be useful for copy operations between
documents such as a high-level page merge and document assembly.Modifier and Type | Field and Description |
---|---|
static int |
e_compatibility
Saves the document in a manner that maximizes compatibility with older PDF consumers (e.g.
|
static int |
e_hex_strings
Save all string in hexadecimal format.
|
static int |
e_incremental
Save the document using incremental mode.
|
static int |
e_linearized
Save the document in linearized (fast web-view) format.
|
static int |
e_omit_xref
Do not save cross-reference table
|
static int |
e_remove_unused
Remove unused objects.
|
Constructor and Description |
---|
SDFDoc()
Default constructor.
|
SDFDoc(byte[] buf)
Open a SDF/Cos document from a memory buffer.
|
SDFDoc(Filter stream)
Open a SDF/Cos document from a Filter (i.e.
|
SDFDoc(java.io.InputStream stream)
Instantiates a new SDFDoc from stream.
|
SDFDoc(java.io.InputStream stream,
int size)
Instantiates a new SDFDoc from stream with specified size.
|
SDFDoc(java.lang.String filepath)
Open a SDF/Cos document from a file.
|
Modifier and Type | Method and Description |
---|---|
static SDFDoc |
__Create(long impl,
java.lang.Object ref) |
long |
__GetHandle() |
java.lang.Object |
__GetRefHandle() |
void |
__SetRef(java.lang.Object ref) |
boolean |
canSaveToPath(java.lang.String path,
long flags)
Checks if a path is valid for a planned save operation
|
void |
clearMarks()
Removes 'marked' flag from all objects in cross reference table.
|
void |
close()
Close SDFDoc and release resources
Frees the native memory of the object.
|
Obj |
createIndirectArray()
Create an indirect array.
|
Obj |
createIndirectBool(boolean value)
Create an indirect boolean
|
Obj |
createIndirectDict()
Create an indirect dictionary
|
Obj |
createIndirectName(java.lang.String name)
The following list of methods is used to create SDF/Cos indirect objects.
|
Obj |
createIndirectNull()
Create an indirect null
|
Obj |
createIndirectNumber(double value)
Create an indirect number.
|
Obj |
createIndirectStream(byte[] data)
Create an indirect stream from buffer
|
Obj |
createIndirectStream(byte[] data,
Filter filter_chain)
Create an indirect stream
|
Obj |
createIndirectStream(FilterReader data)
Create an indirect stream from FilterReader
|
Obj |
createIndirectStream(FilterReader data,
Filter filter_chain)
Create an indirect stream from FilterReader
|
Obj |
createIndirectString(byte[] value)
Create an indirect string.
|
Obj |
createIndirectString(java.lang.String str)
Create an indirect string.
|
void |
enableDiskCaching(boolean use_cache)
Enable or disable disk caching feature
|
java.lang.String |
getFileName()
Get SDFDoc filename
|
java.lang.String |
getHeader()
Get the file header.
|
Obj |
getHintStream()
Get document's initial linearization hint stream if it is available.
|
Obj |
getLinearizationDict()
Get document's initial linearization dictionary if it is available.
|
Obj |
getObj(long obj_num)
Get the Obj with specified object number
|
SecurityHandler |
getSecurityHandler()
Get the security handler.
|
Obj |
getTrailer()
Get root of the document as Obj
|
boolean |
hasRepairedXRef()
Checks whether or not the underlying file has an XRef table that had to be repaired
when the file was opened.
|
Obj |
importObj(Obj obj,
boolean deep_copy)
Import obj to SDFDoc
|
Obj[] |
importObjs(Obj[] obj_list)
The function performs a deep copy of all objects specified in the 'obj_list'.
|
Obj[] |
importObjs(Obj[] obj_list,
Obj[] exclusion_list)
The function performs a deep copy of all objects specified in the 'obj_list'.
|
boolean |
initSecurityHandler()
Initializes document's SecurityHandler.
|
boolean |
initSecurityHandler(java.lang.Object custom_data)
Initializes document's SecurityHandler.
|
boolean |
initStdSecurityHandler(byte[] passwordBuffer)
Initializes document's SecurityHandler using the supplied
password.
|
boolean |
initStdSecurityHandler(java.lang.String password)
Initializes document's SecurityHandler using the supplied
password.
|
boolean |
isEncrypted()
Checks if SDFDoc is encrypted.
|
boolean |
isFullSaveRequired()
Checks if is full save required.
|
boolean |
isLinearized()
Call this function to determine whether the document is represented in
linearized (fast web view) format.
|
boolean |
isModified()
Checks if SDFDoc is modified.
|
void |
lock()
Locks the document to prevent competing threads from accessiong the document
at the same time.
|
void |
lockRead()
Locks the document to prevent competing write threads (using lock()) from accessing the document
at the same time.
|
void |
removeSecurity()
Removes all security from SDFDoc.
|
byte[] |
save(long flags,
com.pdftron.sdf.ProgressMonitor progress,
java.lang.String header)
Saves the document to a memory buffer.
|
void |
save(java.io.OutputStream stream,
long flags,
com.pdftron.sdf.ProgressMonitor progress,
java.lang.String header)
Save SDFDoc to output stream
|
void |
save(java.io.OutputStream stream,
long flags,
com.pdftron.sdf.ProgressMonitor progress,
java.lang.String header,
int size)
Save SDFDoc to output stream
|
void |
save(java.lang.String path,
long flags,
com.pdftron.sdf.ProgressMonitor progress,
java.lang.String header)
Saves the document to a file.
|
void |
setSecurityHandler(SecurityHandler handler)
The function sets a new SecurityHandler as the current security handler.
|
void |
swap(long obj_num1,
long obj_num2)
Sometimes it is desirable to modify all indirect references to a given
indirect object.
|
boolean |
timedLock(int milliseconds)
Try locking the document, waiting no longer than specified number of milliseconds.
|
boolean |
timedLockRead(int milliseconds)
Tries to obtain a read lock the document for <milliseconds> duration, and returns
true if the lock was successfully acquired
|
boolean |
tryLockRead()
Try obtaining a read lock on the document in non-blocking manner.
|
void |
unlock()
Removes the lock from the document.
|
void |
unlockRead()
Removes the read lock from the document.
|
long |
xRefSize()
Get size of the cross reference table
|
public static final int e_incremental
public static final int e_remove_unused
public static final int e_hex_strings
public static final int e_omit_xref
public static final int e_linearized
public static final int e_compatibility
public SDFDoc() throws PDFNetException
PDFNetException
public SDFDoc(java.lang.String filepath) throws PDFNetException
Note: Make sure to call InitStdSecurityHandler() or InitSecurityHandler() after SDFDoc(...) in case the document is encrypted.
filepath
- - path name to the file.PDFNetException
public SDFDoc(Filter stream) throws PDFNetException
Note: if the input stream doesn't support Seek() operation the document will load whole data stream in memory before parsing. In case of linearized PDF, the document may be parsed on-the-fly while it is being loaded in memory. Note that since StdFile implements Seek() interface, the document does not have to be fully in memory before it is used.
Make sure to call InitStdSecurityHandler() or InitSecurityHandler() after SDFDoc(...) in case the document is encrypted.
stream
- - input stream containing a serialized document. The input stream may be a
random-access file, memory buffer, slow HTTP connection etc.PDFNetException
public SDFDoc(byte[] buf) throws PDFNetException
Note: the document should be fully loaded in the memory buffer.
the buffer ownership is not transfered to the Document so the user should clean-up if necessary.
Make sure to call InitStdSecurityHandler() or InitSecurityHandler() after SDFDoc(...) in case the document is encrypted.
buf
- - a memory buffer containing the serialized documentPDFNetException
public SDFDoc(java.io.InputStream stream) throws PDFNetException, java.io.IOException
stream
- the input stream to create SDFDoc fromPDFNetException
java.io.IOException
- Signals that an I/O exception has occurred.public SDFDoc(java.io.InputStream stream, int size) throws PDFNetException, java.io.IOException
stream
- the input stream to create SDFDoc fromsize
- the sizePDFNetException
java.io.IOException
- Signals that an I/O exception has occurred.public void close() throws PDFNetException
PDFNetException
public boolean isEncrypted() throws PDFNetException
PDFNetException
public boolean initSecurityHandler() throws PDFNetException
PDFNetException
public boolean initSecurityHandler(java.lang.Object custom_data) throws PDFNetException
This version of InitSecurityHandler() works with Standard and Custom PDF security and can be used in situations where the password is obtained dynamically via user feedback. See EncTest sample for example code.
If the security handler was successfully initialized it can be later obtained using GetSecurityHandler() method.
Note: This function should be called immediately after an encrypted document is opened. The function does not have any side effects on documents that are not encrypted.
custom_data
- used to specify custom data that should be passed in
SecurityHandler.initialize() callback.PDFNetException
public boolean initStdSecurityHandler(java.lang.String password) throws PDFNetException
password
- Specifies the password used to open the document without
any user feedback. If you would like to dynamically obtain the password,
you need to derive a custom class from StdSecurityHandler() and use
InitSecurityHandler() without any parameters. See EncTest sample
for example code.PDFNetException
public boolean initStdSecurityHandler(byte[] passwordBuffer) throws PDFNetException
passwordBuffer
- Specifies the password used to open the document without
any user feedback. If you would like to dynamically obtain the password,
you need to derive a custom class from StdSecurityHandler() and use
InitSecurityHandler() without any parameters. See EncTest sample
for example code.PDFNetException
public boolean isModified() throws PDFNetException
PDFNetException
public boolean hasRepairedXRef() throws PDFNetException
PDFNetException
public void enableDiskCaching(boolean use_cache)
Note: A document uses a temporary file which is used to cache the contents of any new stream object created in the document (that is the default behavior).
use_cache
- If true, this PDFDoc will use a temporary file to cache
new content streams (this is the default behavior).public boolean isFullSaveRequired() throws PDFNetException
PDFNetException
public boolean canSaveToPath(java.lang.String path, long flags) throws PDFNetException
PDFNetException
public Obj getTrailer() throws PDFNetException
PDFNetException
public Obj getObj(long obj_num) throws PDFNetException
obj_num
- object number of the object to retrieve.PDFNetException
public Obj importObj(Obj obj, boolean deep_copy) throws PDFNetException
Note: If the object belongs to a document the function will perform deep or shallow clone depending whether deep_copy flag was specified. If the object does not belong to any document ImportObj does not take the object ownership. ImportObj copies the source object and it is users responibility to delete free objects.
obj
- - an object to import.deep_copy
- - a boolean indicating whether to perform a deep or shallow copy.
In case of shallow copy all indirect references will be set to null.PDFNetException
public Obj[] importObjs(Obj[] obj_list) throws PDFNetException
Note: - All object in the import list must belong to the same source document.
- The function does not perform the shallow copy since ImportObj() can be used instead.
obj_list
- the obj_listPDFNetException
public Obj[] importObjs(Obj[] obj_list, Obj[] exclusion_list) throws PDFNetException
Note: - All object in the import list must belong to the same source document.
- The function does not perform the shallow copy since ImportObj() can be used instead.
obj_list
- the obj_listexclusion_list
- a list of objects to not include in the deep copyPDFNetException
public long xRefSize() throws PDFNetException
PDFNetException
public void clearMarks() throws PDFNetException
PDFNetException
public void save(java.lang.String path, long flags, com.pdftron.sdf.ProgressMonitor progress, java.lang.String header) throws PDFNetException
Note: - Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.
Note: - If the original pdf has a corrupt xref table (see HasRepairedXref or pdftron.com/kb_corrupt_xref), then it can not be saved using the e_incremental flag.
path
- - The full path name to which the file is saved.flags
- - A bit field composed of an OR of the following values:
progress
- - A pointer to the progress interface. NULL if progress tracking is not required.header
- - File header. A new file header is set only during full save.PDFNetException
public byte[] save(long flags, com.pdftron.sdf.ProgressMonitor progress, java.lang.String header) throws PDFNetException
Note: This method ignores e_incremental flag.
- Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.
flags
- - A bit field composed of an OR of the following values:
progress
- - A pointer to the progress interface. NULL if progress tracking is not required.header
- - File header. A new file header is set only during full save.PDFNetException
public void save(java.io.OutputStream stream, long flags, com.pdftron.sdf.ProgressMonitor progress, java.lang.String header) throws PDFNetException, java.io.IOException
Note: This method ignores e_incremental flag.
- Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.
stream
- the output stream to save SDFDoc toflags
- - A bit field composed of an OR of the following values:
progress
- A pointer to the progress interface. NULL if progress tracking is not required.header
- File header. A new file header is set only during full save.PDFNetException
java.io.IOException
- Signals that an I/O exception has occurred.public void save(java.io.OutputStream stream, long flags, com.pdftron.sdf.ProgressMonitor progress, java.lang.String header, int size) throws PDFNetException, java.io.IOException
Note: This method ignores e_incremental flag.
- Save will modify the SDFDoc object's internal representation. As such, the user should acquire a write lock before calling save.
stream
- the output stream to save SDFDoc toflags
- - A bit field composed of an OR of the following values:
progress
- A pointer to the progress interface. NULL if progress tracking is not required.header
- File header. A new file header is set only during full save.size
- size of the document in bytesPDFNetException
java.io.IOException
- Signals that an I/O exception has occurred.public java.lang.String getHeader() throws PDFNetException
PDFNetException
public SecurityHandler getSecurityHandler()
Note: InitSecurityHandler() should be called before GetSecurityHandler() in order to initialize the handler.
Returned security handler can be modified in order to change the security settings of the exisitng document. Changes to the current handler will not invalidate the access to the original file and will take effect during document Save().
If the security handler is modified, document will perform a full save even if e_incremental was given as a flag in Save() method.
public void setSecurityHandler(SecurityHandler handler)
handler
- the new security handler
* Note: Setting a new security handler will not invalidate the access to the original file and will take effect during document Save().
* Note: If the security handler is modified, document will perform a full save even if e_incremental was given as a flag in Save() method.
public void swap(long obj_num1, long obj_num2) throws PDFNetException
obj_num1
- the obj_num1obj_num2
- the obj_num2PDFNetException
public Obj createIndirectName(java.lang.String name) throws PDFNetException
name
- the namePDFNetException
public Obj createIndirectArray() throws PDFNetException
PDFNetException
public Obj createIndirectBool(boolean value) throws PDFNetException
value
- of the indirect boolean objectPDFNetException
public Obj createIndirectDict() throws PDFNetException
PDFNetException
public Obj createIndirectNull() throws PDFNetException
PDFNetException
public Obj createIndirectNumber(double value) throws PDFNetException
value
- of the indirect numberPDFNetException
public Obj createIndirectString(byte[] value) throws PDFNetException
value
- of indirect stringPDFNetException
public Obj createIndirectString(java.lang.String str) throws PDFNetException
str
- value of indirect stringPDFNetException
public Obj createIndirectStream(FilterReader data) throws PDFNetException
data
- input FilterReaderPDFNetException
public Obj createIndirectStream(FilterReader data, Filter filter_chain) throws PDFNetException
data
- input FilterReaderfilter_chain
- chain of filtersPDFNetException
public Obj createIndirectStream(byte[] data) throws PDFNetException
data
- input bufferPDFNetException
public Obj createIndirectStream(byte[] data, Filter filter_chain) throws PDFNetException
data
- input bufferfilter_chain
- chain of filtersPDFNetException
public boolean isLinearized() throws PDFNetException
Note: any changes to the document can invalidate linearization. The function will return 'true' only if the original document is linearized and if it is not modified. In order to provide good performance over relatively slow communication links, PDFNet can generate PDF documents with linearized objects and hint tables that can allow a PDF viewer application to download and view one page of a PDF file at a time, rather than requiring the entire file (including fonts and images) to be downloaded before any of it can be viewed. To save a document in linearized (fast web view) format you only need to pass 'SDFDoc.e_linearized' flag in the Save method.
PDFNetException
public Obj getLinearizationDict() throws PDFNetException
PDFNetException
public Obj getHintStream() throws PDFNetException
PDFNetException
public void lock() throws PDFNetException
PDFNetException
public void unlock() throws PDFNetException
PDFNetException
public boolean timedLock(int milliseconds) throws PDFNetException
milliseconds
- the millisecondsPDFNetException
public void lockRead() throws PDFNetException
PDFNetException
public void unlockRead() throws PDFNetException
PDFNetException
public boolean tryLockRead() throws PDFNetException
PDFNetException
public boolean timedLockRead(int milliseconds) throws PDFNetException
milliseconds
- maximum time to waitPDFNetException
public java.lang.String getFileName() throws PDFNetException
PDFNetException
public static SDFDoc __Create(long impl, java.lang.Object ref)
public void __SetRef(java.lang.Object ref)
public java.lang.Object __GetRefHandle()
public long __GetHandle()
__GetHandle
in class Doc
public void removeSecurity()