/* CHAPTER 1. Basics */ /* * cpdf_fromFile(filename, userpw) 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. */ int cpdf_fromFile(const char[], const char[]); /* * cpdf_fromFileLazy(pdf, userpw) 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. */ int cpdf_fromFileLazy(const char[], const char[]); /* * cpdf_fromMemory(data, length, userpw) loads a file from memory, given a * pointer and a length, and the user password. */ int cpdf_fromMemory(void *, int, const char[]); /* * cpdf_fromMemory(data, length, userpw) loads a file from memory, given a * pointer and a length, and the user password, but lazily like * cpdf_fromFileLazy. */ int cpdf_fromMemoryLazy(void *, int, const char[]); /* Remove a PDF from memory, given its number. */ void cpdf_deletePdf(int); /* * Calling cpdf_replacePdf(a, b) places PDF b under number a. Number b is no * longer available. */ void cpdf_replacePdf(int, int); /* * To enumerate the list of currently allocated PDFs, call * cpdf_startEnumeratePDFs which gives the number, n, of PDFs allocated, then * cpdf_enumeratePDFsInfo and cpdf_enumeratePDFsKey with index numbers from * 0...(n - 1). Call cpdf_endEnumeratePDFs to clean up. */ int cpdf_startEnumeratePDFs(void); int cpdf_enumeratePDFsKey(int); char *cpdf_enumeratePDFsInfo(int); void cpdf_endEnumeratePDFs(void); /* Convert a figure in centimetres to points (72 points to 1 inch) */ double cpdf_ptOfCm(double); /* Convert a figure in millimetres to points (72 points to 1 inch) */ double cpdf_ptOfMm(double); /* Convert a figure in inches to points (72 points to 1 inch) */ double cpdf_ptOfIn(double); /* Convert a figure in points to centimetres (72 points to 1 inch) */ double cpdf_cmOfPt(double); /* Convert a figure in points to millimetres (72 points to 1 inch) */ double cpdf_mmOfPt(double); /* Convert a figure in points to inches (72 points to 1 inch) */ double cpdf_inOfPt(double); /* * A page range is a list of page numbers used to restrict operations to * certain pages. A page specification is a textual description of a page * range, such as "1-12,18-end". Here is the syntax: * * o A range must contain no spaces. * * o A dash (-) defines ranges, e.g. 1-5 or 6-3. * * o A comma (,) allows one to specify several ranges, e.g. 1-2,4-5. * * o The word end represents the last page number. * * o The words odd and even can be used in place of or at the end of a page * range to restrict to just the odd or even pages. * * o The words portrait and landscape can be used in place of or at the end of * a page range to restrict to just those pages which are portrait or * landscape. Note that the meaning of "portrait" and "landscape" does not * take account of any viewing rotation in place (use cpdf_upright first, if * required). A page with equal width and height is considered neither * portrait nor landscape. * * o The word reverse is the same as end-1. * * o The word all is the same as 1-end. * * o A tilde (~) defines a page number counting from the end of the document * rather than the beginning. Page ~1 is the last page, ~2 the penultimate * page etc. */ /* * cpdf_parsePagespec(pdf, range) 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). */ int cpdf_parsePagespec(int, const char[]); /* * cpdf_validatePagespec(range) validates a page specification so far as is * possible in the absence of the actual document. Result is true if valid. */ int cpdf_validatePagespec(const char[]); /* * cpdf_stringOfPagespec(pdf, range) 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 "1-3,6-end" */ char *cpdf_stringOfPagespec(int, int); /* cpdf_blankRange() creates a range with no pages in. */ int cpdf_blankRange(void); /* cpdf_deleteRange(range) deletes a range. */ void cpdf_deleteRange(int); /* * cpdf_range(from, to) builds a range from one page to another inclusive. For * example, cpdf_range(3,7) gives the range 3,4,5,6,7 */ int cpdf_range(int, int); /* cpdf_all(pdf) is the range containing all the pages in a given document. */ int cpdf_all(int); /* * cpdf_even(range) makes a range which contains just the even pages of * another range. */ int cpdf_even(int); /* * cpdf_odd(range) makes a range which contains just the odd pages of another * range. */ int cpdf_odd(int); /* * cpdf_rangeUnion(a, b) makes the union of two ranges giving a range * containing the pages in range a and range b. */ int cpdf_rangeUnion(int, int); /* * cpdf_difference(a, b) makes the difference of two ranges, giving a range * containing all the pages in a except for those which are also in b. */ int cpdf_difference(int, int); /* cpdf_removeDuplicates(range) deduplicates a range, making a new one. */ int cpdf_removeDuplicates(int); /* cpdf_rangeLength gives the number of pages in a range. */ int cpdf_rangeLength(int); /* * cpdf_rangeGet(range, n) gets the page number at position n in a range, * where n runs from 0 to rangeLength - 1. */ int cpdf_rangeGet(int, int); /* * cpdf_rangeAdd(range, page) adds the page to a range, if it is not already * there. */ int cpdf_rangeAdd(int, int); /* * cpdf_isInRange(range, page) returns true if the page is in the range, * false otherwise. */ int cpdf_isInRange(int, int); /* cpdf_pages(pdf) returns the number of pages in a PDF. */ int cpdf_pages(int); /* * cpdf_pagesFast(password, filename) returns the number of pages in a given * PDF, with given user encryption password. It tries to do this as fast as * possible, without loading the whole file. */ int cpdf_pagesFast(const char[], const char[]); /* * cpdf_toFile (pdf, filename, linearize, make_id) 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. * * NB: Unlike with the command line tool, cpdf, streams decompressed during * processing will not automatically be compressed when writing. Call * cpdf_compress() first. */ void cpdf_toFile(int, const char[], int, int); /* * cpdf_toFileExt (pdf, filename, linearize, make_id, preserve_objstm, * generate_objstm, compress_objstm) 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 discarded. */ void cpdf_toFileExt(int, const char[], int, int, int, int, int); /* * cpdf_toFileMemory (pdf, linearize, make_id, sizse) writes a PDF file it * and returns the buffer. The buffer length is filled in. * * NB: Unlike with the command line tool, cpdf, streams decompressed during * processing will not automatically be compressed when writing. Call * cpdf_compress() first. */ void *cpdf_toMemory(int, int, int, int *); /* * cpdf_isEncrypted(pdf) returns true if a documented is encrypted, false * otherwise. */ int cpdf_isEncrypted(int); /* * cpdf_decryptPdf(pdf, userpw) attempts to decrypt a PDF using the given * user password. The error code is non-zero if the decryption fails. */ void cpdf_decryptPdf(int, const char[]); /* * cpdf_decryptPdfOwner(pdf, ownerpw) attempts to decrypt a PDF using the * given owner password. The error code is non-zero if the decryption fails. */ void cpdf_decryptPdfOwner(int, const char[]); /* * File permissions. These are inverted, in the sense that the presence of * one of them indicates a restriction. */ enum cpdf_permission { cpdf_noEdit, /* Cannot edit the document */ cpdf_noPrint, /* Cannot print the document */ cpdf_noCopy, /* Cannot copy the document */ cpdf_noAnnot, /* Cannot annotate the document */ cpdf_noForms, /* Cannot edit forms in the document */ cpdf_noExtract, /* Cannot extract information */ cpdf_noAssemble, /* Cannot assemble into a bigger document */ cpdf_noHqPrint /* Cannot print high quality */ }; /* * Encryption methods. Suffixes 'false' and 'true' indicates lack of or * presence of encryption for XMP metadata streams. */ enum cpdf_encryptionMethod { cpdf_pdf40bit, /* 40 bit RC4 encryption */ cpdf_pdf128bit, /* 128 bit RC4 encryption */ cpdf_aes128bitfalse, /* 128 bit AES encryption, do not encrypt * metadata. */ cpdf_aes128bittrue, /* 128 bit AES encryption, encrypt metadata */ cpdf_aes256bitfalse, /* Deprecated. Do not use for new files */ cpdf_aes256bittrue, /* Deprecated. Do not use for new files */ cpdf_aes256bitisofalse, /* 256 bit AES encryption, do not encrypt * metadata. */ cpdf_aes256bitisotrue /* 256 bit AES encryption, encrypt metadata */ }; /* * cpdf_toFileEncrypted(pdf, encryption_method, permissions, * permission_length, owner_password, user password, linearize, makeid, * filename) writes a file as encrypted. */ void cpdf_toFileEncrypted(int, int, int *, int, const char[], const char[], int, int, const char[]); /* * cpdf_toFileEncryptedExt(pdf, encryption_method, permissions, * permission_length, owner_password, user_password, linearize, makeid, * preserve_objstm, generate_objstm, compress_objstm, filename) WARNING: the * pdf argument will be invalid after this call, and should be discarded. */ void cpdf_toFileEncryptedExt(int, int, int *, int, const char[], const char[], int, int, int, int, int, const char[]); /* * cpdf_hasPermission(pdf, permission) returns true if the given permission * (restriction) is present. */ int cpdf_hasPermission(int, enum cpdf_permission); /* * cpdf_encryptionKind(pdf) return the encryption method currently in use on * a document. */ enum cpdf_encryptionMethod cpdf_encryptionKind(int); /* cpdf_loadFont(name, filename) loads a TrueType font from the given file * name, and names it. It may then be used when adding text or drawing, using * the name in place of a standard font name. */ void cpdf_loadFont(char *, char *);