mirror of
https://github.com/johnwhitington/cpdf-source.git
synced 2025-06-05 22:09:39 +02:00
more
This commit is contained in:
@@ -1,256 +1,166 @@
|
||||
/* CHAPTER 1. Basics */
|
||||
//CHAPTER 1. Basics
|
||||
|
||||
/** Loads a PDF document from a file. Supply
|
||||
a user password (possibly blank) in case the file is encrypted. It won't be
|
||||
decrypted, but sometimes the password is needed just to load the file.
|
||||
@param filename file name
|
||||
@param userpw user password */
|
||||
public Pdf fromFile(String filename, String userpw) throws CpdfError;
|
||||
/** Loads a PDF file from a given file. Supply a user password (possibly blank)
|
||||
in case the file is encrypted. It won't be decrypted, but sometimes the
|
||||
password is needed just to load the file. */
|
||||
function fromFile(filename, userpw)
|
||||
|
||||
/** Loads a PDF document from a file, doing only minimal
|
||||
parsing. The objects will be read and parsed when they are actually
|
||||
needed. Use this when the whole file won't be required. Also supply a user
|
||||
password (possibly blank) in case the file is encrypted. It won't be
|
||||
decrypted, but sometimes the password is needed just to load the file.
|
||||
/** Loads a PDF from a file, doing only minimal parsing. The objects will be
|
||||
read and parsed when they are actually needed. Use this when the whole file
|
||||
won't be required. Also supply a user password (possibly blank) in case the
|
||||
file is encrypted. It won't be decrypted, but sometimes the password is needed
|
||||
just to load the file. */
|
||||
function fromFileLazy(filename, userpw)
|
||||
|
||||
@param filename file name
|
||||
@param userpw user password */
|
||||
public Pdf fromFileLazy(String filename, String userpw) throws CpdfError;
|
||||
/** Loads a file from memory given any user password. */
|
||||
function fromMemory(data, userpw)
|
||||
|
||||
/** Loads a PDF document from memory. Supply
|
||||
a user password (possibly blank) in case the file is encrypted. It won't be
|
||||
decrypted, but sometimes the password is needed just to load the file.
|
||||
/** Loads a file from memory, given a pointer and a length, and the user
|
||||
password, but lazily like fromFileLazy. */
|
||||
function fromMemoryLazy(data, userpw)
|
||||
|
||||
@param data byte array containing the PDF file
|
||||
@param userpw user password */
|
||||
public Pdf fromMemory(byte[] data, String userpw) throws CpdfError;
|
||||
/** To enumerate the list of currently allocated PDFs, call startEnumeratePDFs
|
||||
which gives the number, n, of PDFs allocated, then enumeratePDFsInfo and
|
||||
enumeratePDFsKey with index numbers from 0...(n - 1). Call endEnumeratePDFs to
|
||||
clean up. */
|
||||
function startEnumeratePDFs()
|
||||
|
||||
/** Loads a file from memory and the user
|
||||
password, but lazily like {@link #fromFileLazy(String, String)
|
||||
fromFileLazy}. The caller must use {@link #fromMemoryLazyRelease(byte[])
|
||||
fromMemoryLazyRelease} to free the memory. It must not free the memory
|
||||
until the PDF is also gone. */
|
||||
public Pdf fromMemoryLazy(byte[] data, String userpw) throws CpdfError;
|
||||
/** To enumerate the list of currently allocated PDFs, call startEnumeratePDFs
|
||||
which gives the number, n, of PDFs allocated, then enumeratePDFsInfo and
|
||||
enumeratePDFsKey with index numbers from 0...(n - 1). Call endEnumeratePDFs to
|
||||
clean up. */
|
||||
function enumeratePDFsKey(n)
|
||||
|
||||
/** Releases memory returned from
|
||||
<code>{@link #fromMemoryLazy(byte[], String) fromMemoryLazy}</code>
|
||||
@param data byte array previously passed to {@link #fromMemoryLazy(byte[],
|
||||
String) fromMemoryLazy} */
|
||||
public native void fromMemoryLazyRelease(byte[] data) throws CpdfError;
|
||||
/** To enumerate the list of currently allocated PDFs, call startEnumeratePDFs
|
||||
which gives the number, n, of PDFs allocated, then enumeratePDFsInfo and
|
||||
enumeratePDFsKey with index numbers from 0...(n - 1). Call endEnumeratePDFs to
|
||||
clean up. */
|
||||
function enumeratePDFsInfo(n)
|
||||
|
||||
/** Begins enumerating currently allocated PDFs.
|
||||
/** To enumerate the list of currently allocated PDFs, call startEnumeratePDFs
|
||||
which gives the number, n, of PDFs allocated, then enumeratePDFsInfo and
|
||||
enumeratePDFsKey with index numbers from 0...(n - 1). Call endEnumeratePDFs to
|
||||
clean up. */
|
||||
function endEnumeratePDFs()
|
||||
|
||||
<p>To enumerate the list of currently allocated PDFs, call
|
||||
{@link #startEnumeratePDFs() startEnumeratePDFs} which gives the number,
|
||||
<code>n</code>, of PDFs allocated, then {@link #enumeratePDFsInfo(int)
|
||||
enumeratePDFsInfo} and {@link #enumeratePDFsKey(int) enumeratePDFsKey} with
|
||||
index numbers from <code>0...(n - 1)</code>. Call
|
||||
{@link #endEnumeratePDFs() endEnumeratePDFs} to clean up. */
|
||||
public native int startEnumeratePDFs() throws CpdfError;
|
||||
/** Converts a figure in centimetres to points (72 points to 1 inch) */
|
||||
function ptOfCm(i)
|
||||
|
||||
/** Returns the key for a given PDF number. */
|
||||
public native int enumeratePDFsKey(int n) throws CpdfError;
|
||||
/** Converts a figure in millimetres to points (72 points to 1 inch) */
|
||||
function ptOfMm(i)
|
||||
|
||||
/** Returns the info for a given PDF number. */
|
||||
public native String enumeratePDFsInfo(int n) throws CpdfError;
|
||||
/** Converts a figure in inches to points (72 points to 1 inch) */
|
||||
function ptOfIn(i)
|
||||
|
||||
/** Ends enumeration of currently allocated PDFs. */
|
||||
public native void endEnumeratePDFs() throws CpdfError;
|
||||
/** Converts a figure in points to centimetres (72 points to 1 inch) */
|
||||
function cmOfPt(i)
|
||||
|
||||
/** Converts a figure in centimetres to points. (72 points to 1 inch) */
|
||||
public native double ptOfCm(double f) throws CpdfError;
|
||||
/** Converts a figure in points to millimetres (72 points to 1 inch) */
|
||||
function mmOfPt(i)
|
||||
|
||||
/** Converts a figure in millimetres to points. (72 points to 1 inch) */
|
||||
public native double ptOfMm(double f) throws CpdfError;
|
||||
/** Converts a figure in points to inches (72 points to 1 inch) */
|
||||
function inOfPt(i)
|
||||
|
||||
/** Converts a figure in inches to points (72. points to 1 inch) */
|
||||
public native double ptOfIn(double f) throws CpdfError;
|
||||
|
||||
/** Converts a figure in points to centimetres. (72 points to 1 inch) */
|
||||
public native double cmOfPt(double f) throws CpdfError;
|
||||
|
||||
/** Converts a figure in points to millimetres. (72 points to 1 inch) */
|
||||
public native double mmOfPt(double f) throws CpdfError;
|
||||
|
||||
/** Converts a figure in points to millimetres. (72 points to 1 inch) */
|
||||
public native double inOfPt(double f) throws CpdfError;
|
||||
|
||||
/** Parses a page specification such as <code>1,2,6-end</code> with
|
||||
reference to a given PDF. (The PDF is supplied so that page ranges which
|
||||
reference pages which do not exist are rejected).
|
||||
|
||||
@param pdf PDF document
|
||||
@param pagespec page specification */
|
||||
public native Range parsePagespec(Pdf pdf, String pagespec)
|
||||
throws CpdfError;
|
||||
/** Parses a page specification with reference to a given PDF (the PDF is
|
||||
supplied so that page ranges which reference pages which do not exist are
|
||||
rejected). */
|
||||
function parsePagespec(pdf, pagespec)
|
||||
|
||||
/** Validates a page specification so far as is possible in the absence of
|
||||
the actual document. Result is <code>true</code> if valid. */
|
||||
public native boolean validatePagespec(String pagespec) throws CpdfError;
|
||||
the actual document. Result is true if valid. */
|
||||
function validatePagespec(pagespec)
|
||||
|
||||
/** Builds a page specification from a page range. For example, the range
|
||||
containing 1,2,3,6,7,8 in a document of 8 pages might yield
|
||||
<code>"1-3,6-end"</code>
|
||||
containing 1,2,3,6,7,8 in a document of 8 pages might yield "1-3,6-end" */
|
||||
function stringOfPagespec(pdf, r)
|
||||
|
||||
@param pdf PDF document
|
||||
@param r page range
|
||||
*/
|
||||
public String stringOfPagespec(Pdf pdf, Range r) throws CpdfError;
|
||||
/** Creates a range with no pages in. */
|
||||
function blankRange()
|
||||
|
||||
/** The range containing no pages. */
|
||||
public native Range blankRange() throws CpdfError;
|
||||
/** Builds a range from one page to another inclusive. For example, range(3,7)
|
||||
gives the range 3,4,5,6,7 */
|
||||
function range(f, t)
|
||||
|
||||
/** The page range containing all page numbers from one page number to
|
||||
another.
|
||||
@param from page number to begin at (inclusive)
|
||||
@param to page number to end at (inclusive) */
|
||||
public native Range range(int from, int to) throws CpdfError;
|
||||
/** The range containing all the pages in a given document. */
|
||||
function all(pdf)
|
||||
|
||||
/** The page range contaning all pages in a given document. */
|
||||
public native Range all(Pdf pdf) throws CpdfError;
|
||||
/** Makes a range which contains just the even pages of another range. */
|
||||
function even(r_in)
|
||||
|
||||
/** The page range containing all odd-numbered pages from an existing
|
||||
range. */
|
||||
public native Range odd(Range r) throws CpdfError;
|
||||
/** Makes a range which contains just the odd pages of another range. */
|
||||
function odd(r_in)
|
||||
|
||||
/** The page range containing all even-numbered pages from an existing
|
||||
range. */
|
||||
public native Range even(Range r) throws CpdfError;
|
||||
/** Makes the union of two ranges giving a range containing the pages in range
|
||||
a and range b. */
|
||||
function rangeUnion(a, b)
|
||||
|
||||
/** The union of two ranges - all those pages in either. */
|
||||
public native Range rangeUnion(Range r, Range s) throws CpdfError;
|
||||
/** Makes the difference of two ranges, giving a range containing all the
|
||||
pages in a except for those which are also in b. */
|
||||
function difference(a, b)
|
||||
|
||||
/** The range containing all pages in the first given range which are not
|
||||
in the second. */
|
||||
public native Range difference(Range r, Range s) throws CpdfError;
|
||||
/** Deduplicates a range, making a new one. */
|
||||
function removeDuplicates(a)
|
||||
|
||||
/** Remove duplicates from a range, returning a new one. */
|
||||
public native Range removeDuplicates(Range r) throws CpdfError;
|
||||
/** Gives the number of pages in a range. */
|
||||
function rangeLength(r)
|
||||
|
||||
/** The length of a range. */
|
||||
public native int rangeLength(Range r) throws CpdfError;
|
||||
/** Gets the page number at position n in a range, where n runs from 0 to
|
||||
rangeLength - 1. */
|
||||
function rangeGet(r, n)
|
||||
|
||||
/** Gets a page number from a range at the given offset. */
|
||||
public native int rangeGet(Range r, int n) throws CpdfError;
|
||||
/** Adds the page to a range, if it is not already there. */
|
||||
function rangeAdd(r, page)
|
||||
|
||||
/** Adds a page number to a range, returning a new one. */
|
||||
public native Range rangeAdd(Range r, int n) throws CpdfError;
|
||||
|
||||
/** Tests to see if a given number is in a page range. */
|
||||
public native boolean isInRange(Range r, int n) throws CpdfError;
|
||||
/** Returns true if the page is in the range, false otherwise. */
|
||||
function isInRange(r, page)
|
||||
|
||||
/** Returns the number of pages in a PDF. */
|
||||
public native int pages(Pdf pdf) throws CpdfError;
|
||||
function pages(pdf)
|
||||
|
||||
/** Returns the number of pages in a given
|
||||
PDF, with given user password. It tries to do this as fast as
|
||||
possible, without loading the whole file.
|
||||
@param userpw user password
|
||||
@param filename file name */
|
||||
public int pagesFast(String userpw, String filename) throws CpdfError;
|
||||
/** Returns the number of pages in a given PDF, with given user password. It
|
||||
tries to do this as fast as possible, without loading the whole file. */
|
||||
function pagesFast(password, filename)
|
||||
|
||||
/** Writes the PDF document to a given filename. If <code>linearize</code>
|
||||
is <code>true</code>, it will be linearized if a linearizer is available.
|
||||
If <code>make_id</code> is <code>true</code>, it will be given a new ID.
|
||||
@param pdf PDF document
|
||||
@param filename file name
|
||||
@param linearize linearize
|
||||
@param make_id make new ID
|
||||
*/
|
||||
public void toFile(Pdf pdf, String filename, boolean linearize,
|
||||
boolean make_id)
|
||||
throws CpdfError;
|
||||
/** Writes the file to a given filename. If linearize is true, it will be
|
||||
linearized if a linearizer is available. If make_id is true, it will be
|
||||
given a new ID. */
|
||||
function toFile(pdf, filename, linearize, make_id)
|
||||
|
||||
/** Writes the PDF document to a given filename, with extra parameters. If
|
||||
<code>make_id</code> is true, it will be given a new ID. If
|
||||
<code>preserve_objstm</code> is true, existing object streams will be
|
||||
preserved. If <code>generate_objstm</code> is true, object streams will be
|
||||
generated even if not originally present. If <code>compress_objstm</code>
|
||||
is true, object streams will be compressed (what we usually want).
|
||||
WARNING: the pdf argument will be invalid after this call, and should not
|
||||
be used again.
|
||||
@param pdf PDF document
|
||||
@param filename file name
|
||||
@param linearize linearize
|
||||
@param make_id make new ID
|
||||
@param preserve_objstm preserve object streams
|
||||
@param create_objstm create new object streams
|
||||
@param compress_objstm compress object streams
|
||||
*/
|
||||
public void toFileExt(Pdf pdf, String filename, boolean linearize,
|
||||
boolean make_id, boolean preserve_objstm,
|
||||
boolean create_objstm, boolean compress_objstm)
|
||||
throws CpdfError;
|
||||
/** Writes the file to a given filename. If make_id is true, it will be given
|
||||
a new ID. If preserve_objstm is true, existing object streams will be
|
||||
preserved. If generate_objstm is true, object streams will be generated even if
|
||||
not originally present. If compress_objstm is true, object streams will be
|
||||
compressed (what we usually want). WARNING: the pdf argument will be invalid
|
||||
after this call, and should be not be used again. */
|
||||
function toFileExt(pdf, filename, linearize, make_id, preserve_objstm,
|
||||
create_objstm, compress_objstm)
|
||||
|
||||
/** Writes a PDF document and returns it as an array of bytes.
|
||||
@param pdf PDF document
|
||||
@param linearize linearize
|
||||
@param make_id make new ID
|
||||
*/
|
||||
public native byte[] toMemory(Pdf pdf, boolean linearize, boolean make_id)
|
||||
throws CpdfError;
|
||||
/** Writes a PDF file and returns as an array of bytes. */
|
||||
function toMemory(pdf, linearize, make_id)
|
||||
|
||||
/** Returns <code>true</code> if a document is encrypted,
|
||||
<code>false</code> otherwise. */
|
||||
public native boolean isEncrypted(Pdf pdf) throws CpdfError;
|
||||
/** Returns true if a document is encrypted, false otherwise. */
|
||||
function isEncrypted(pdf)
|
||||
|
||||
/** Attempts to decrypt a PDF using the given
|
||||
user password. An exception is raised if the decryption fails.
|
||||
@param pdf PDF document
|
||||
@param userpw user password */
|
||||
public void decryptPdf(Pdf pdf, String userpw) throws CpdfError;
|
||||
/** Attempts to decrypt a PDF using the given user password. An exception is
|
||||
raised if the decryption fails. */
|
||||
function decryptPdf(pdf, userpw)
|
||||
|
||||
/** Attempts to decrypt a PDF using the given owner password. Raises an
|
||||
exception if the decryption fails.
|
||||
@param pdf PDF document
|
||||
@param ownerpw owner password */
|
||||
public void decryptPdfOwner(Pdf pdf, String ownerpw) throws CpdfError;
|
||||
exception if the decryption fails. */
|
||||
function decryptPdfOwner(pdf, ownerpw)
|
||||
|
||||
/** Writes a PDF document as encrypted. The encryption method and
|
||||
permissions are drawn from Jcpdf's fields, documented above.
|
||||
@param pdf PDF document
|
||||
@param encryption_method encryption method, e.g
|
||||
{@link #aes256bitisofalse aes256bitisofalse}
|
||||
@param permissions array of permissions e.g {@link #noEdit noEdit}
|
||||
@param owner_password owner password
|
||||
@param user_password user password
|
||||
@param linearize linearize
|
||||
@param makeid make new ID
|
||||
@param filename file name */
|
||||
public void toFileEncrypted(Pdf pdf, int encryption_method,
|
||||
int[] permissions, String owner_password,
|
||||
String user_password, boolean linearize,
|
||||
boolean makeid, String filename)
|
||||
throws CpdfError;
|
||||
/** Writes a file as encrypted. */
|
||||
function toFileEncrypted(pdf, encryption_method, permissions, ownerpw, userpw,
|
||||
linearize, makeid, filename)
|
||||
|
||||
/** Writes a file as encrypted with extra parameters. WARNING: the pdf
|
||||
argument will be invalid after this call, and should not be used again.
|
||||
/** Writes a file as encrypted with extra parameters. WARNING: the pdf argument
|
||||
will be invalid after this call, and should not be used again. */
|
||||
function toFileEncryptedExt(pdf, encryption_method, permissions, ownerpw, userpw,
|
||||
linearize, makeid, preserve_objstm, generate_objstm,
|
||||
compress_objstm, filename)
|
||||
|
||||
@param pdf PDF document
|
||||
@param encryption_method encryption method, e.g
|
||||
{@link #aes256bitisofalse aes256bitisofalse}
|
||||
@param permissions array of permissions e.g {@link #noEdit noEdit}
|
||||
@param owner_password owner password
|
||||
@param user_password user password
|
||||
@param linearize linearize
|
||||
@param makeid make new ID
|
||||
@param preserve_objstm preserve existing object streams
|
||||
@param generate_objstm generate new object streams
|
||||
@param compress_objstm compress object streams
|
||||
@param filename file name */
|
||||
public void toFileEncryptedExt(Pdf pdf, int encryption_method,
|
||||
int[] permissions, String owner_password,
|
||||
String user_password, boolean linearize,
|
||||
boolean makeid, boolean preserve_objstm,
|
||||
boolean generate_objstm,
|
||||
boolean compress_objstm, String filename)
|
||||
throws CpdfError;
|
||||
/** Returns true if the given permission (restriction) is present. */
|
||||
function hasPermission(pdf, permission)
|
||||
|
||||
/** Returns <code>true</code> if the given permission (restriction) such as
|
||||
{@link #noEdit noEdit} is present. */
|
||||
public native boolean hasPermission(Pdf pdf, int permission)
|
||||
throws CpdfError;
|
||||
|
||||
/** Returns the encryption method currently in use on a document, such as
|
||||
{@link #aes256bitisofalse aes256bitisofalse}. */
|
||||
public native int encryptionKind(Pdf pdf) throws CpdfError;
|
||||
/** Returns the encryption method currently in use on a document. */
|
||||
function encryptionKind(pdf)
|
||||
|
Reference in New Issue
Block a user