├── ACKNOWLEDGEMENTS.md ├── Changes ├── CoherentPDF.2.5.2.nupkg ├── LICENSE.md ├── README.md ├── cpdflibmanual.pdf ├── cpdflibwrapper.h ├── dotnet ├── dotnet-libcpdf.deps.json ├── dotnet-libcpdf.dll ├── dotnet-libcpdf.pdb └── dotnet-libcpdf.xml ├── dotnetcpdflibmanual.pdf ├── java └── coherentpdf.jar ├── jcpdflibmanual.pdf ├── linux32 ├── .gitignore ├── libcpdf.a ├── libcpdf.so ├── libjcpdf.so ├── libpycpdf.so └── readme.txt ├── linux64 ├── .gitignore ├── libcpdf.a ├── libcpdf.so ├── libjcpdf.so ├── libpycpdf.so └── readme.txt ├── macosx-arm ├── .gitignore ├── libcpdf.a ├── libcpdf.so ├── libjcpdf.dylib ├── libpycpdf.so └── readme.txt ├── macosx ├── .gitignore ├── libcpdf.a ├── libcpdf.so ├── libjcpdf.dylib ├── libpycpdf.so └── readme.txt ├── pycpdflib.py ├── pycpdflibmanual.pdf ├── windows32 ├── .gitignore ├── jcpdf.dll ├── libcpdf.a ├── libcpdf.dll ├── libgcc_s_sjlj-1.dll ├── libpycpdf.dll └── readme.txt └── windows64 ├── jcpdf.dll ├── libcpdf.a ├── libcpdf.dll ├── libpycpdf.dll └── readme.txt /ACKNOWLEDGEMENTS.md: -------------------------------------------------------------------------------- 1 | These binaries contain YoJson: 2 | ============================== 3 | 4 | Copyright (c) 2010-2012, Martin Jambon All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | Redistributions in binary form must reproduce the above copyright notice, this 13 | list of conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. 15 | 16 | Neither the name of nor the names of its contributors may be used to endorse or 17 | promote products derived from this software without specific prior written 18 | permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | These binaries contain Xmlm: 32 | ============================ 33 | 34 | Copyright (c) 2007 Daniel C. Bünzli 35 | 36 | Permission to use, copy, modify, and/or distribute this software for any 37 | purpose with or without fee is hereby granted, provided that the above 38 | copyright notice and this permission notice appear in all copies. 39 | 40 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 41 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 42 | FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 43 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 44 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 45 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 46 | PERFORMANCE OF THIS SOFTWARE. 47 | 48 | These binaries contain Oliver Gay's SHA Implementation 49 | ====================================================== 50 | 51 | FIPS 180-2 SHA-224/256/384/512 implementation 52 | Last update: 02/02/2007 53 | Issue date: 04/30/2005 54 | 55 | Copyright (C) 2005, 2007 Olivier Gay All rights 56 | reserved. 57 | 58 | Redistribution and use in source and binary forms, with or without 59 | modification, are permitted provided that the following conditions are met: 60 | 61 | 1. Redistributions of source code must retain the above copyright notice, this 62 | list of conditions and the following disclaimer. 63 | 2. Redistributions in binary form must reproduce the above copyright notice, 64 | this list of conditions and the following disclaimer in the documentation 65 | and/or other materials provided with the distribution. 66 | 3. Neither the name of the project nor the names of its contributors may be 67 | used to endorse or promote products derived from this software without 68 | specific prior written permission. 69 | 70 | THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND ANY 71 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 72 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 73 | DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY 74 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 75 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 76 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 77 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 78 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 79 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 80 | 81 | These binaries contain Miniz: 82 | ============================= 83 | 84 | Copyright 2013-2014 RAD Game Tools and Valve Software 85 | Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC 86 | All Rights Reserved. 87 | 88 | Permission is hereby granted, free of charge, to any person obtaining a copy of 89 | this software and associated documentation files (the "Software"), to deal in 90 | the Software without restriction, including without limitation the rights to 91 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 92 | of the Software, and to permit persons to whom the Software is furnished to do 93 | so, subject to the following conditions: 94 | 95 | The above copyright notice and this permission notice shall be included in all 96 | copies or substantial portions of the Software. 97 | 98 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 99 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 100 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 101 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 102 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 103 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 104 | SOFTWARE. 105 | 106 | Further Acknowledgments: 107 | ======================== 108 | 109 | These binaries contain a slightly modified version of some parts of CamlZip by 110 | Xavier Leroy. The originals are available here: 111 | 112 | http://pauillac.inria.fr/~xleroy/software.html 113 | 114 | The Rijndael implementation was written by Vincent Rijmen, Antoon Bosselaers 115 | and Paulo Barreto. 116 | -------------------------------------------------------------------------------- /Changes: -------------------------------------------------------------------------------- 1 | Aug 2022: Added v2.5.2a bugfix to addTextSimple 2 | 3 | Apr 2022: Added v2.5.2, .NET and JAVA. Per-platform readmes 4 | 5 | Mar 2022: Added v2.5.1 (including MacOS ARM) 6 | 7 | Jan 2022: Added v2.5 (except MacOS ARM : to come Feb 2022) 8 | 9 | Sep 2021: Added Python API 10 | 11 | June 2021: First release of renewed libcpdf/libpycpdf. For earlier work, see the cpdf changelog 12 | -------------------------------------------------------------------------------- /CoherentPDF.2.5.2.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/CoherentPDF.2.5.2.nupkg -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published by 637 | the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | 663 | ------------------------------------------------------------------------------- 664 | 665 | This software includes the contents of the file sjcl.js, which is redistributed 666 | under these license terms: 667 | 668 | Copyright (c) 2009-2015, Emily Stark, Mike Hamburg and Dan Boneh at 669 | Stanford University. All rights reserved. 670 | 671 | Redistribution and use in source and binary forms, with or without 672 | modification, are permitted provided that the following conditions are 673 | met: 674 | 675 | 1. Redistributions of source code must retain the above copyright 676 | notice, this list of conditions and the following disclaimer. 677 | 678 | 2. Redistributions in binary form must reproduce the above copyright 679 | notice, this list of conditions and the following disclaimer in the 680 | documentation and/or other materials provided with the distribution. 681 | 682 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 683 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 684 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 685 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 686 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 687 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 688 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 689 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 690 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 691 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 692 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 693 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | cpdflib-binary 2 | ============== 3 | 4 | libcpdf is a C/C++/.Net/Java/Python library version of the Coherent PDF Command 5 | Line Tools, which are available in binary form: 6 | 7 | http://github.com/coherentgraphics/cpdf-binaries 8 | 9 | and also in source form. 10 | 11 | It is distributed under the AGPL - see LICENSE.md. If you are unable to abide 12 | by the terms of the AGPL, you will need a commercial license. 13 | 14 | For commercial licenses, email 15 | [contact@coherentgraphics.co.uk](mailto:contact@coherentgraphics.co.uk) or 16 | visit [https://www.coherentpdf.com/](https://www.coherentpdf.com/) 17 | 18 | The website for commercial sales of the Command Line Tools and 19 | C/C++/.NET/Java/Python APIs is 20 | 21 | http://www.coherentpdf.com/ 22 | 23 | Contact: contact@coherentgraphics.co.uk 24 | 25 | 26 | Use 27 | === 28 | 29 | See the individual README in the directory for your platform. 30 | 31 | 32 | Documentation 33 | ============= 34 | 35 | See 36 | cpdflibmanual.pdf for C/C++ 37 | pycpdflibmanual.pdf for Python 38 | dotnetcpdflibmanual.pdf for .NET 39 | jcpdflibmanual.pdf for Java 40 | -------------------------------------------------------------------------------- /cpdflibmanual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/cpdflibmanual.pdf -------------------------------------------------------------------------------- /cpdflibwrapper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * A C wrapper to cpdf PDF tools library. Free for non-commercial use. See 3 | * LICENSE for details. To purchase a license, please visit 4 | * http://www.coherentpdf.com/ 5 | * 6 | * Text arguments and results are in UTF8. 7 | */ 8 | 9 | /* CHAPTER 0. Preliminaries */ 10 | 11 | /* The function cpdf_startup(argv) must be called before using the library. */ 12 | void cpdf_startup(char **); 13 | 14 | /* Return the version of the cpdflib library as a string */ 15 | char *cpdf_version(); 16 | 17 | /* 18 | * Some operations have a fast mode. The default is 'slow' mode, which works 19 | * even on old-fashioned files. For more details, see section 1.13 of the 20 | * CPDF manual. These functions set the mode globally. 21 | */ 22 | void cpdf_setFast(); 23 | void cpdf_setSlow(); 24 | 25 | /* 26 | * Errors. cpdf_lastError and cpdf_lastErrorString hold information about the 27 | * last error to have occurred. They should be consulted after each call. If 28 | * cpdf_lastError is non-zero, there was an error, and cpdf_lastErrorString 29 | * gives details. If cpdf_lastError is zero, there was no error on the most 30 | * recent cpdf call. 31 | */ 32 | extern int cpdf_lastError; 33 | extern char *cpdf_lastErrorString; 34 | 35 | /* In some contexts, for example, .NET or JNI, constants in DLLs can be 36 | * difficult or impossible to access. we provide functions in addition. */ 37 | int cpdf_fLastError(void); 38 | char *cpdf_fLastErrorString(void); 39 | 40 | /* cpdf_clearError clears the current error state. */ 41 | void cpdf_clearError(void); 42 | 43 | /* 44 | * cpdf_onExit is a debug function which prints some information about 45 | * resource usage. This can be used to detect if PDFs or ranges are being 46 | * deallocated properly. Contrary to its name, it may be run at any time. 47 | */ 48 | void cpdf_onExit(void); 49 | 50 | /* CHAPTER 1. Basics */ 51 | 52 | /* 53 | * cpdf_fromFile(filename, userpw) loads a PDF file from a given file. Supply 54 | * a user password (possibly blank) in case the file is encrypted. It won't be 55 | * decrypted, but sometimes the password is needed just to load the file. 56 | */ 57 | int cpdf_fromFile(const char[], const char[]); 58 | 59 | /* 60 | * cpdf_fromFileLazy(pdf, userpw) loads a PDF from a file, doing only minimal 61 | * parsing. The objects will be read and parsed when they are actually 62 | * needed. Use this when the whole file won't be required. Also supply a user 63 | * password (possibly blank) in case the file is encrypted. It won't be 64 | * decrypted, but sometimes the password is needed just to load the file. 65 | */ 66 | int cpdf_fromFileLazy(const char[], const char[]); 67 | 68 | /* 69 | * cpdf_fromMemory(data, length, userpw) loads a file from memory, given a 70 | * pointer and a length, and the user password. 71 | */ 72 | int cpdf_fromMemory(void *, int, const char[]); 73 | 74 | /* 75 | * cpdf_fromMemory(data, length, userpw) loads a file from memory, given a 76 | * pointer and a length, and the user password, but lazily like 77 | * cpdf_fromFileLazy. 78 | */ 79 | int cpdf_fromMemoryLazy(void *, int, const char[]); 80 | 81 | /* Remove a PDF from memory, given its number. */ 82 | void cpdf_deletePdf(int); 83 | 84 | /* 85 | * Calling cpdf_replacePdf(a, b) places PDF b under number a. Number b is no 86 | * longer available. 87 | */ 88 | void cpdf_replacePdf(int, int); 89 | 90 | /* 91 | * To enumerate the list of currently allocated PDFs, call 92 | * cpdf_startEnumeratePDFs which gives the number, n, of PDFs allocated, then 93 | * cpdf_enumeratePDFsInfo and cpdf_enumeratePDFsKey with index numbers from 94 | * 0...(n - 1). Call cpdf_endEnumeratePDFs to clean up. 95 | */ 96 | int cpdf_startEnumeratePDFs(void); 97 | int cpdf_enumeratePDFsKey(int); 98 | char *cpdf_enumeratePDFsInfo(int); 99 | void cpdf_endEnumeratePDFs(void); 100 | 101 | /* Convert a figure in centimetres to points (72 points to 1 inch) */ 102 | double cpdf_ptOfCm(double); 103 | 104 | /* Convert a figure in millimetres to points (72 points to 1 inch) */ 105 | double cpdf_ptOfMm(double); 106 | 107 | /* Convert a figure in inches to points (72 points to 1 inch) */ 108 | double cpdf_ptOfIn(double); 109 | 110 | /* Convert a figure in points to centimetres (72 points to 1 inch) */ 111 | double cpdf_cmOfPt(double); 112 | 113 | /* Convert a figure in points to millimetres (72 points to 1 inch) */ 114 | double cpdf_mmOfPt(double); 115 | 116 | /* Convert a figure in points to inches (72 points to 1 inch) */ 117 | double cpdf_inOfPt(double); 118 | 119 | /* 120 | * A page range is a list of page numbers used to restrict operations to 121 | * certain pages. A page specification is a textual description of a page 122 | * range, such as "1-12,18-end". Here is the syntax: 123 | * 124 | * o A range must contain no spaces. 125 | * 126 | * o A dash (-) defines ranges, e.g. 1-5 or 6-3. 127 | * 128 | * o A comma (,) allows one to specify several ranges, e.g. 1-2,4-5. 129 | * 130 | * o The word end represents the last page number. 131 | * 132 | * o The words odd and even can be used in place of or at the end of a page 133 | * range to restrict to just the odd or even pages. 134 | * 135 | * o The words portrait and landscape can be used in place of or at the end of 136 | * a page range to restrict to just those pages which are portrait or 137 | * landscape. Note that the meaning of "portrait" and "landscape" does not 138 | * take account of any viewing rotation in place (use cpdf_upright first, if 139 | * required). A page with equal width and height is considered neither 140 | * portrait nor landscape. 141 | * 142 | * o The word reverse is the same as end-1. 143 | * 144 | * o The word all is the same as 1-end. 145 | * 146 | * o A tilde (~) defines a page number counting from the end of the document 147 | * rather than the beginning. Page ~1 is the last page, ~2 the penultimate 148 | * page etc. 149 | */ 150 | 151 | /* 152 | * cpdf_parsePagespec(pdf, range) parses a page specification with reference 153 | * to a given PDF (the PDF is supplied so that page ranges which reference 154 | * pages which do not exist are rejected). 155 | */ 156 | int cpdf_parsePagespec(int, const char[]); 157 | 158 | /* 159 | * cpdf_validatePagespec(range) validates a page specification so far as is 160 | * possible in the absence of the actual document. Result is true if valid. 161 | */ 162 | int cpdf_validatePagespec(const char[]); 163 | 164 | /* 165 | * cpdf_stringOfPagespec(pdf, range) builds a page specification from a page 166 | * range. For example, the range containing 1,2,3,6,7,8 in a document of 8 167 | * pages might yield "1-3,6-end" 168 | */ 169 | char *cpdf_stringOfPagespec(int, int); 170 | 171 | /* cpdf_blankRange() creates a range with no pages in. */ 172 | int cpdf_blankRange(void); 173 | 174 | /* cpdf_deleteRange(range) deletes a range. */ 175 | void cpdf_deleteRange(int); 176 | 177 | /* 178 | * cpdf_range(from, to) builds a range from one page to another inclusive. For 179 | * example, cpdf_range(3,7) gives the range 3,4,5,6,7 180 | */ 181 | int cpdf_range(int, int); 182 | 183 | /* cpdf_all(pdf) is the range containing all the pages in a given document. */ 184 | int cpdf_all(int); 185 | 186 | /* 187 | * cpdf_even(range) makes a range which contains just the even pages of 188 | * another range. 189 | */ 190 | int cpdf_even(int); 191 | 192 | /* 193 | * cpdf_odd(range) makes a range which contains just the odd pages of another 194 | * range. 195 | */ 196 | int cpdf_odd(int); 197 | 198 | /* 199 | * cpdf_rangeUnion(a, b) makes the union of two ranges giving a range 200 | * containing the pages in range a and range b. 201 | */ 202 | int cpdf_rangeUnion(int, int); 203 | 204 | /* 205 | * cpdf_difference(a, b) makes the difference of two ranges, giving a range 206 | * containing all the pages in a except for those which are also in b. 207 | */ 208 | int cpdf_difference(int, int); 209 | 210 | /* cpdf_removeDuplicates(range) deduplicates a range, making a new one. */ 211 | int cpdf_removeDuplicates(int); 212 | 213 | /* cpdf_rangeLength gives the number of pages in a range. */ 214 | int cpdf_rangeLength(int); 215 | 216 | /* 217 | * cpdf_rangeGet(range, n) gets the page number at position n in a range, 218 | * where n runs from 0 to rangeLength - 1. 219 | */ 220 | int cpdf_rangeGet(int, int); 221 | 222 | /* 223 | * cpdf_rangeAdd(range, page) adds the page to a range, if it is not already 224 | * there. 225 | */ 226 | int cpdf_rangeAdd(int, int); 227 | 228 | /* 229 | * cpdf_isInRange(range, page) returns true if the page is in the range, 230 | * false otherwise. 231 | */ 232 | int cpdf_isInRange(int, int); 233 | 234 | /* cpdf_pages(pdf) returns the number of pages in a PDF. */ 235 | int cpdf_pages(int); 236 | 237 | /* 238 | * cpdf_pagesFast(password, filename) returns the number of pages in a given 239 | * PDF, with given user encryption password. It tries to do this as fast as 240 | * possible, without loading the whole file. 241 | */ 242 | int cpdf_pagesFast(const char[], const char[]); 243 | 244 | /* 245 | * cpdf_toFile (pdf, filename, linearize, make_id) writes the file to a given 246 | * filename. If linearize is true, it will be linearized if a linearizer is 247 | * available. If make_id is true, it will be given a new ID. 248 | */ 249 | void cpdf_toFile(int, const char[], int, int); 250 | 251 | /* 252 | * cpdf_toFileExt (pdf, filename, linearize, make_id, preserve_objstm, 253 | * generate_objstm, compress_objstm) writes the file to a given filename. If 254 | * make_id is true, it will be given a new ID. If preserve_objstm is true, 255 | * existing object streams will be preserved. If generate_objstm is true, 256 | * object streams will be generated even if not originally present. If 257 | * compress_objstm is true, object streams will be compressed (what we 258 | * usually want). WARNING: the pdf argument will be invalid after this call, 259 | * and should be discarded. 260 | */ 261 | void cpdf_toFileExt(int, const char[], int, int, int, int, int); 262 | 263 | /* 264 | * cpdf_toFileMemory (pdf, linearize, make_id, &length) writes a PDF file it 265 | * and returns the buffer. The buffer length is filled in &length. 266 | */ 267 | void *cpdf_toMemory(int, int, int, int *); 268 | 269 | /* 270 | * cpdf_isEncrypted(pdf) returns true if a documented is encrypted, false 271 | * otherwise. 272 | */ 273 | int cpdf_isEncrypted(int); 274 | 275 | /* 276 | * cpdf_decryptPdf(pdf, userpw) attempts to decrypt a PDF using the given 277 | * user password. The error code is non-zero if the decryption fails. 278 | */ 279 | void cpdf_decryptPdf(int, const char[]); 280 | 281 | /* 282 | * cpdf_decryptPdfOwner(pdf, ownerpw) attempts to decrypt a PDF using the 283 | * given owner password. The error code is non-zero if the decryption fails. 284 | */ 285 | void cpdf_decryptPdfOwner(int, const char[]); 286 | 287 | /* 288 | * File permissions. These are inverted, in the sense that the presence of 289 | * one of them indicates a restriction. 290 | */ 291 | enum cpdf_permission { 292 | cpdf_noEdit, /* Cannot edit the document */ 293 | cpdf_noPrint, /* Cannot print the document */ 294 | cpdf_noCopy, /* Cannot copy the document */ 295 | cpdf_noAnnot, /* Cannot annotate the document */ 296 | cpdf_noForms, /* Cannot edit forms in the document */ 297 | cpdf_noExtract, /* Cannot extract information */ 298 | cpdf_noAssemble, /* Cannot assemble into a bigger document */ 299 | cpdf_noHqPrint /* Cannot print high quality */ 300 | }; 301 | 302 | /* 303 | * Encryption methods. Suffixes 'false' and 'true' indicates lack of or 304 | * presence of encryption for XMP metadata streams. 305 | */ 306 | enum cpdf_encryptionMethod { 307 | cpdf_pdf40bit, /* 40 bit RC4 encryption */ 308 | cpdf_pdf128bit, /* 128 bit RC4 encryption */ 309 | cpdf_aes128bitfalse, /* 128 bit AES encryption, do not encrypt 310 | * metadata. */ 311 | cpdf_aes128bittrue, /* 128 bit AES encryption, encrypt metadata */ 312 | cpdf_aes256bitfalse, /* Deprecated. Do not use for new files */ 313 | cpdf_aes256bittrue, /* Deprecated. Do not use for new files */ 314 | cpdf_aes256bitisofalse, /* 256 bit AES encryption, do not encrypt 315 | * metadata. */ 316 | cpdf_aes256bitisotrue /* 256 bit AES encryption, encrypt metadata */ 317 | }; 318 | 319 | /* 320 | * cpdf_toFileEncrypted(pdf, encryption_method, permissions, 321 | * permission_length, owner_password, user password, linearize, makeid, 322 | * filename) writes a file as encrypted. 323 | */ 324 | void cpdf_toFileEncrypted(int, int, int *, int, const char[], const char[], int, 325 | int, const char[]); 326 | 327 | /* 328 | * cpdf_toFileEncryptedExt(pdf, encryption_method, permissions, 329 | * permission_length, owner_password, user_password, linearize, makeid, 330 | * preserve_objstm, generate_objstm, compress_objstm, filename) WARNING: the 331 | * pdf argument will be invalid after this call, and should be discarded. 332 | */ 333 | void cpdf_toFileEncryptedExt(int, int, int *, int, const char[], const char[], 334 | int, int, int, int, int, const char[]); 335 | 336 | /* 337 | * cpdf_hasPermission(pdf, permission) returns true if the given permission 338 | * (restriction) is present. 339 | */ 340 | int cpdf_hasPermission(int, enum cpdf_permission); 341 | 342 | /* 343 | * cpdf_encryptionKind(pdf) return the encryption method currently in use on 344 | * a document. 345 | */ 346 | enum cpdf_encryptionMethod cpdf_encryptionKind(int); 347 | 348 | /* CHAPTER 2. Merging and Splitting */ 349 | 350 | /* 351 | * cpdf_mergeSimple(pdfs, length) given an array of PDFs, and its length, 352 | * merges the files into a new one, which is returned. 353 | */ 354 | int cpdf_mergeSimple(int *, int); 355 | 356 | /* 357 | * cpdf_merge(pdfs, len, retain_numbering, remove_duplicate_fonts) merges the 358 | * PDFs. If retain_numbering is true page labels are not rewritten. If 359 | * remove_duplicate_fonts is true, duplicate fonts are merged. This is useful 360 | * when the source documents for merging originate from the same source. 361 | */ 362 | int cpdf_merge(int *, int, int, int); 363 | 364 | /* 365 | * cpdf_mergeSame(pdfs, len, retain_numbering, remove_duplicate_fonts, 366 | * ranges) is the same as cpdf_merge, except that it has an additional 367 | * argument - an array of page ranges. This is used to select the pages to 368 | * pick from each PDF. This avoids duplication of information when multiple 369 | * discrete parts of a source PDF are included. 370 | */ 371 | int cpdf_mergeSame(int *, int, int, int, int *); 372 | 373 | /* 374 | * cpdf_selectPages(pdf, range) returns a new document which just those pages 375 | * in the page range. 376 | */ 377 | int cpdf_selectPages(int, int); 378 | 379 | /* CHAPTER 3. Pages */ 380 | 381 | /* 382 | * cpdf_scalePages(pdf, range, x scale, y scale) scales the page dimensions 383 | * and content by the given scale, about (0, 0). Other boxes (crop etc. are 384 | * altered as appropriate) 385 | */ 386 | void cpdf_scalePages(int, int, double, double); 387 | 388 | /* 389 | * cpdf_scaleToFit(pdf, range, width, height, scale) scales the content to fit 390 | * new page dimensions (width x height) multiplied by scale (typically 1.0). 391 | * Other boxes (crop etc. are altered as appropriate) 392 | */ 393 | void cpdf_scaleToFit(int, int, double, double, double); 394 | 395 | /* Standard page sizes. */ 396 | enum cpdf_papersize { 397 | cpdf_a0portrait, /* A0 portrait */ 398 | cpdf_a1portrait, /* A1 portrait */ 399 | cpdf_a2portrait, /* A2 portrait */ 400 | cpdf_a3portrait, /* A3 portrait */ 401 | cpdf_a4portrait, /* A4 portrait */ 402 | cpdf_a5portrait, /* A5 portrait */ 403 | cpdf_a0landscape, /* A0 landscape */ 404 | cpdf_a1landscape, /* A1 landscape */ 405 | cpdf_a2landscape, /* A2 landscape */ 406 | cpdf_a3landscape, /* A3 landscape */ 407 | cpdf_a4landscape, /* A4 landscape */ 408 | cpdf_a5landscape, /* A5 landscape */ 409 | cpdf_usletterportrait, /* US Letter portrait */ 410 | cpdf_usletterlandscape, /* US Letter landscape */ 411 | cpdf_uslegalportrait, /* US Legal portrait */ 412 | cpdf_uslegallandscape /* US Legal landscape */ 413 | }; 414 | 415 | /* 416 | * cpdf_scaleToFitPaper(pdf, range, papersize, scale) scales the page content 417 | * to fit the given page size, possibly multiplied by scale (typically 1.0) 418 | */ 419 | void cpdf_scaleToFitPaper(int, int, enum cpdf_papersize, double); 420 | 421 | /* Positions on the page. Used for scaling about a point, and adding text. */ 422 | enum cpdf_anchor { 423 | cpdf_posCentre, /* Absolute centre */ 424 | cpdf_posLeft, /* Absolute left */ 425 | cpdf_posRight, /* Absolute right */ 426 | cpdf_top, /* Top top centre of the page */ 427 | cpdf_topLeft, /* The top left of the page */ 428 | cpdf_topRight, /* The top right of the page */ 429 | cpdf_left, /* The left hand side of the page, halfway 430 | * down */ 431 | cpdf_bottomLeft, /* The bottom left of the page */ 432 | cpdf_bottom, /* The bottom middle of the page */ 433 | cpdf_bottomRight, /* The bottom right of the page */ 434 | cpdf_right, /* The right hand side of the page, halfway 435 | * down */ 436 | cpdf_diagonal, /* Diagonal, bottom left to top right */ 437 | cpdf_reverseDiagonal /* Diagonal, top left to bottom right */ 438 | }; 439 | 440 | /* 441 | * A cpdf_position is an anchor (above) and zero or one or two parameters 442 | * (cpdf_coord1, cpdf_coord2). 443 | * 444 | * cpdf_posCentre: Two parameters, x and y 445 | * 446 | * cpdf_posLeft: Two parameters, x and y 447 | * 448 | * cpdf_posRight: Two parameters, x and y 449 | * 450 | * cpdf_top: One parameter -- distance from top 451 | * 452 | * cpdf_topLeft: One parameter -- distance from top left 453 | * 454 | * cpdf_topRight: One parameter -- distance from top right 455 | * 456 | * cpdf_left: One parameter -- distance from left middle 457 | * 458 | * cpdf_bottomLeft: One parameter -- distance from bottom left 459 | * 460 | * cpdf_bottom: One parameter -- distance from bottom 461 | * 462 | * cpdf_bottomRight: One parameter -- distance from bottom right 463 | * 464 | * cpdf_right: One parameter -- distance from right 465 | * 466 | * cpdf_diagonal: Zero parameters 467 | * 468 | * cpdf_reverseDiagonal: Zero parameters 469 | */ 470 | struct cpdf_position { 471 | int cpdf_anchor; /* Position anchor */ 472 | double cpdf_coord1; /* Parameter one */ 473 | double cpdf_coord2; /* Parameter two */ 474 | }; 475 | 476 | /* 477 | * cpdf_scaleContents(pdf, range, position, scale) scales the contents of the 478 | * pages in the range about the point given by the cpdf_position, by the 479 | * scale given. 480 | */ 481 | void cpdf_scaleContents(int, int, struct cpdf_position, double); 482 | 483 | /* 484 | * cpdf_shiftContents(pdf, range, dx, dy) shifts the content of the pages in 485 | * the range. 486 | */ 487 | void cpdf_shiftContents(int, int, double, double); 488 | 489 | /* 490 | * cpdf_rotate(pdf, range, rotation) changes the viewing rotation to an 491 | * absolute value. Appropriate rotations are 0, 90, 180, 270. 492 | */ 493 | void cpdf_rotate(int, int, int); 494 | 495 | /* 496 | * cpdf_rotateBy(pdf, range, rotation) changes the viewing rotation by a 497 | * given number of degrees. Appropriate values are 90, 180, 270. 498 | */ 499 | void cpdf_rotateBy(int, int, int); 500 | 501 | /* 502 | * cpdf_rotateContents(pdf, range, angle) rotates the content about the 503 | * centre of the page by the given number of degrees, in a clockwise 504 | * direction. 505 | */ 506 | void cpdf_rotateContents(int, int, double); 507 | 508 | /* 509 | * cpdf_upright(pdf, range) changes the viewing rotation of the pages in the 510 | * range, counter-rotating the dimensions and content such that there is no 511 | * visual change. 512 | */ 513 | void cpdf_upright(int, int); 514 | 515 | /* cpdf_hFlip(pdf, range) flips horizontally the pages in the range. */ 516 | void cpdf_hFlip(int, int); 517 | 518 | /* cpdf_vFlip(pdf, range) flips vertically the pages in the range. */ 519 | void cpdf_vFlip(int, int); 520 | 521 | /* 522 | * cpdf_crop(pdf, range, x, y, w, h) crops a page, replacing any existing 523 | * crop box. The dimensions are in points. 524 | */ 525 | void cpdf_crop(int, int, double, double, double, double); 526 | 527 | /* cpdf_removeCrop(pdf, range) removes any crop box from pages in the range. */ 528 | void cpdf_removeCrop(int, int); 529 | 530 | /* cpdf_removeTrim(pdf, range) removes any trim box from pages in the range. */ 531 | void cpdf_removeTrim(int, int); 532 | 533 | /* cpdf_removeArt(pdf, range) removes any art box from pages in the range. */ 534 | void cpdf_removeArt(int, int); 535 | 536 | /* cpdf_removeBleed(pdf, range) removes any bleed box from pages in the range. */ 537 | void cpdf_removeBleed(int, int); 538 | 539 | /* 540 | * cpdf_trimMarks(pdf, range) adds trim marks to the given pages, if the 541 | * trimbox exists. 542 | */ 543 | void cpdf_trimMarks(int, int); 544 | 545 | /* cpdf_showBoxes(pdf, range) shows the boxes on the given pages, for debug. */ 546 | void cpdf_showBoxes(int, int); 547 | 548 | /* cpdf_hardBox makes a given box a 'hard box' i.e clips it explicitly. */ 549 | void cpdf_hardBox(int, int, const char[]); 550 | 551 | /* CHAPTER 4. Encryption */ 552 | 553 | /* Encryption covered under Chapter 1 in cpdflib. */ 554 | 555 | /* CHAPTER 5. Compression */ 556 | 557 | /* 558 | * cpdf_compress(pdf) compresses any uncompressed streams in the given PDF 559 | * using the Flate algorithm. 560 | */ 561 | void cpdf_compress(int); 562 | 563 | /* 564 | * cpdf_decompress(pdf) decompresses any streams in the given PDF, so long as 565 | * the compression method is supported. 566 | */ 567 | void cpdf_decompress(int); 568 | 569 | /* cpdf_squeezeToMemory(pdf) squeezes a pdf in memory. */ 570 | void cpdf_squeezeInMemory(int); 571 | 572 | /* CHAPTER 6. Bookmarks */ 573 | 574 | /* 575 | * cpdf_startGetBookmarkInfo(pdf) starts the bookmark retrieval process for a 576 | * given PDF. 577 | */ 578 | void cpdf_startGetBookmarkInfo(int); 579 | 580 | /* 581 | * cpdf_numberBookmarks gets the number of bookmarks for the PDF given to 582 | * cpdf_startGetBookmarkInfo. 583 | */ 584 | int cpdf_numberBookmarks(void); 585 | 586 | /* 587 | * cpdf_getBookmarkLevel(serial) get bookmark level for the given bookmark 588 | * (0...(n - 1)). 589 | */ 590 | int cpdf_getBookmarkLevel(int); 591 | 592 | /* 593 | * cpdf_getBookmarkPage gets the bookmark target page for the given PDF 594 | * (which must be the same as the PDF passed to cpdf_startSetBookmarkInfo) 595 | * and bookmark (0...(n - 1)). 596 | */ 597 | int cpdf_getBookmarkPage(int, int); 598 | 599 | /* cpdf_getBookmarkText returns the text of bookmark (0...(n - 1)). */ 600 | char *cpdf_getBookmarkText(int); 601 | 602 | /* cpdf_getBookmarkOpenStatus(pdf) is true if the bookmark is open. */ 603 | int cpdf_getBookmarkOpenStatus(int); 604 | 605 | /* cpdf_endGetBookmarkInfo ends the bookmark retrieval process, cleaning up. */ 606 | void cpdf_endGetBookmarkInfo(void); 607 | 608 | /* 609 | * cpdf_startGetBookmarkInfo(n) start the bookmark setting process for n 610 | * bookmarks. 611 | */ 612 | void cpdf_startSetBookmarkInfo(int); 613 | 614 | /* 615 | * cpdf_setBookmarkLevel(n, level) set bookmark level for the given bookmark 616 | * (0...(n - 1)). 617 | */ 618 | void cpdf_setBookmarkLevel(int, int); 619 | 620 | /* 621 | * cpdf_setBookmarkPage(pdf, bookmark, targetpage) sets the bookmark target 622 | * page for the given PDF (which must be the same as the PDF to be passed to 623 | * cpdf_endSetBookmarkInfo) and bookmark (0...(n - 1)). 624 | */ 625 | void cpdf_setBookmarkPage(int, int, int); 626 | 627 | /* 628 | * cpdf_setBookmarkOpenStatus(n, status) set the open status of a bookmark, 629 | * true or false. 630 | */ 631 | void cpdf_setBookmarkOpenStatus(int, int); 632 | 633 | /* cpdf_setBookmarkText(n, text) sets the text of bookmark (0...(n - 1)). */ 634 | void cpdf_setBookmarkText(int, const char[]); 635 | 636 | /* 637 | * cpdf_endSetBookmarkInfo(pdf) end the bookmark setting process, writing the 638 | * bookmarks to the given PDF. 639 | */ 640 | void cpdf_endSetBookmarkInfo(int); 641 | 642 | /* cpdf_getBookmarksJSON(pdf, length) returns the bookmark data and sets the 643 | * length. */ 644 | void *cpdf_getBookmarksJSON(int, int *); 645 | 646 | /* cpdf_setBookmarksJSON(pdf, data, datalength) sets the bookmarks from JSON 647 | * bookmark data. */ 648 | void cpdf_setBookmarksJSON(int, void *, int); 649 | 650 | /* cpdf_tableOfContents(pdf, font, fontsize, title, bookmark) typesets a table 651 | * of contents from existing bookmarks and prepends it to the document. If 652 | * bookmark is set, the table of contents gets its own bookmark. */ 653 | void cpdf_tableOfContents(int, int, double, const char[], int); 654 | 655 | /* CHAPTER 7. Presentations */ 656 | 657 | /* Not included in the library version. */ 658 | 659 | /* CHAPTER 8. Logos, Watermarks and Stamps */ 660 | 661 | /* 662 | * cpdf_stampOn(stamp_pdf, pdf, range) stamps stamp_pdf on top of all the 663 | * pages in the document which are in the range. The stamp is placed with its 664 | * origin at the origin of the target document. 665 | */ 666 | void cpdf_stampOn(int, int, int); 667 | 668 | /* 669 | * cpdf_stampUnder(stamp_pdf, pdf, range) stamps stamp_pdf under all the 670 | * pages in the document which are in the range. The stamp is placed with its 671 | * origin at the origin of the target document. 672 | */ 673 | void cpdf_stampUnder(int, int, int); 674 | 675 | /* 676 | * cpdf_stampExtended(pdf, pdf2, range, isover, scale_stamp_to_fit, pos, 677 | * relative_to_cropbox) is a stamping function with extra features. - isover 678 | * true, pdf goes over pdf2, isover false, pdf goes under pdf2 - 679 | * scale_stamp_to_fit scales the stamp to fit the page - pos gives the 680 | * position to put the stamp - relative_to_cropbox: if true, pos is relative 681 | * to cropbox not mediabox. 682 | */ 683 | void cpdf_stampExtended(int, int, int, int, int, struct cpdf_position, int); 684 | 685 | /* 686 | * cpdf_combinePages(under, over) combines the PDFs page-by-page, putting 687 | * each page of 'over' over each page of 'under'. 688 | */ 689 | int cpdf_combinePages(int, int); 690 | 691 | /* Adding text. */ 692 | 693 | /* 694 | * Special codes 695 | * 696 | * %Page Page number in arabic notation (1, 2, 3...) 697 | * 698 | * %roman Page number in lower-case roman notation (i, ii, iii...) 699 | * 700 | * %Roman Page number in upper-case roman notation (I, II, III...) 701 | * 702 | * %EndPage Last page of document in arabic notation 703 | * 704 | * %Label The page label of the page 705 | * 706 | * %EndLabel The page label of the last page 707 | * 708 | * %filename The full file name of the input document 709 | * 710 | * %a Abbreviated weekday name (Sun, Mon etc.) 711 | * 712 | * %A Full weekday name (Sunday, Monday etc.) 713 | * 714 | * %b Abbreviated month name (Jan, Feb etc.) 715 | * 716 | * %B Full month name (January, February etc.) 717 | * 718 | * %d Day of the month (01-31) 719 | * 720 | * %e Day of the month (1-31) 721 | * 722 | * %H Hour in 24-hour clock (00-23) 723 | * 724 | * %I Hour in 12-hour clock (01-12) 725 | * 726 | * %j Day of the year (001-366) 727 | * 728 | * %m Month of the year (01-12) 729 | * 730 | * %M Minute of the hour (00-59) 731 | * 732 | * %p "a.m" or "p.m" 733 | * 734 | * %S Second of the minute (00-61) 735 | * 736 | * %T Same as %H:%M:%S 737 | * 738 | * %u Weekday (1-7, 1 = Monday) 739 | * 740 | * %w Weekday (0-6, 0 = Monday) 741 | * 742 | * %Y Year (0000-9999) 743 | * 744 | * %% The % character 745 | */ 746 | 747 | /* The standard fonts */ 748 | enum cpdf_font { 749 | cpdf_timesRoman, /* Times Roman */ 750 | cpdf_timesBold, /* Times Bold */ 751 | cpdf_timesItalic, /* Times Italic */ 752 | cpdf_timesBoldItalic, /* Times Bold Italic */ 753 | cpdf_helvetica, /* Helvetica */ 754 | cpdf_helveticaBold, /* Helvetica Bold */ 755 | cpdf_helveticaOblique, /* Helvetica Oblique */ 756 | cpdf_helveticaBoldOblique, /* Helvetica Bold Oblique */ 757 | cpdf_courier, /* Courier */ 758 | cpdf_courierBold, /* Courier Bold */ 759 | cpdf_courierOblique, /* Courier Oblique */ 760 | cpdf_courierBoldOblique /* Courier Bold Oblique */ 761 | }; 762 | 763 | /* Justifications for multi line text */ 764 | enum cpdf_justification { 765 | cpdf_leftJustify, /* Left justify */ 766 | cpdf_CentreJustify, /* Centre justify */ 767 | cpdf_RightJustify /* Right justify */ 768 | }; 769 | 770 | /* Add text */ 771 | void cpdf_addText(int, /* If true, don't actually add text but 772 | * collect metrics. */ 773 | int, /* Document */ 774 | int, /* Page Range */ 775 | const char[], /* The text to add */ 776 | struct cpdf_position, /* Position to add text at */ 777 | double, /* Linespacing, 1.0 = normal */ 778 | int, /* Starting Bates number */ 779 | enum cpdf_font, /* Font */ 780 | double, /* Font size in points */ 781 | double, /* Red component of colour, 0.0 - 1.0 */ 782 | double, /* Green component of colour, 0.0 - 1.0 */ 783 | double, /* Blue component of colour, 0.0 - 1.0 */ 784 | int, /* If true, text is added underneath rather 785 | * than on top */ 786 | int, /* If true, position is relative to crop box 787 | * not media box */ 788 | int, /* If true, text is outline rather than 789 | * filled */ 790 | double, /* Opacity, 1.0 = opaque, 0.0 = wholly 791 | * transparent */ 792 | enum cpdf_justification, /* Justification */ 793 | int, /* If true, position is relative to midline 794 | * of text, not baseline */ 795 | int, /* If true, position is relative to topline 796 | * of text, not baseline */ 797 | const char[], /* filename that this document was read from 798 | * (optional) */ 799 | double, /* line width */ 800 | int /* embed fonts */ 801 | ); 802 | 803 | /* Add text, with most parameters default. */ 804 | void cpdf_addTextSimple(int, /* Document */ 805 | int, /* Page range */ 806 | const char[], /* The text to add */ 807 | struct cpdf_position, /* Position to add text 808 | * at */ 809 | enum cpdf_font, /* font */ 810 | double); /* font size */ 811 | 812 | /* 813 | * cpdf_removeText(pdf, range) will remove any text added by libcpdf from the 814 | * given pages. 815 | */ 816 | void cpdf_removeText(int, int); 817 | 818 | /* 819 | * Return the width of a given string in the given font in thousandths of a 820 | * point. 821 | */ 822 | int cpdf_textWidth(enum cpdf_font, const char[]); 823 | 824 | /* cpdf_addContent(content, before, pdf, range) adds page content before (if 825 | * true) or after (if false) the existing content to pages in the given range 826 | * in the given PDF. */ 827 | void cpdf_addContent(const char[], int, int, int); 828 | 829 | /* cpdf_stampAsXObject(pdf, range, stamp_pdf) stamps stamp_pdf onto the pages 830 | * in the given range in pdf as a shared Form XObject. The name of the 831 | * newly-created XObject is returned. */ 832 | char *cpdf_stampAsXObject(int, int, int); 833 | 834 | /* CHAPTER 9. Multipage facilities */ 835 | 836 | /* cpdf_impose(pdf, x, y, fit, columns, rtl, btt, center, margin, spacing, 837 | * linewidth) imposes a PDF. There are two modes: imposing x * y, or imposing 838 | * to fit a page of size x * y. This is controlled by fit. Columns imposes by 839 | * columns rather than rows. rtl is right-to-left, btt bottom-to-top. Center is 840 | * unused for now. Margin is the margin around the output, spacing the spacing 841 | * between imposed inputs. */ 842 | void cpdf_impose(int, double, double, int, int, int, int, int, double, double, 843 | double); 844 | 845 | /* 846 | * Impose a document two up. cpdf_twoUp does so by retaining the existing 847 | * page size, scaling pages down. cpdf_twoUpStack does so by doubling the 848 | * page size, to fit two pages on one. 849 | */ 850 | void cpdf_twoUp(int); 851 | void cpdf_twoUpStack(int); 852 | 853 | /* 854 | * cpdf_padBefore(pdf, range) adds a blank page before each page in the given 855 | * range. 856 | */ 857 | void cpdf_padBefore(int, int); 858 | 859 | /* 860 | * cpdf_padAfter(pdf, range) adds a blank page after each page in the given 861 | * range. 862 | */ 863 | void cpdf_padAfter(int, int); 864 | 865 | /* cpdf_pageEvery(pdf, n) adds a blank page after every n pages. */ 866 | void cpdf_padEvery(int, int); 867 | 868 | /* 869 | * cpdf_padMultiple(pdf, n) adds pages at the end to pad the file to a 870 | * multiple of n pages in length. 871 | */ 872 | void cpdf_padMultiple(int, int); 873 | 874 | /* 875 | * cpdf_padMultiple(pdf, n) adds pages at the beginning to pad the file to a 876 | * multiple of n pages in length. 877 | */ 878 | void cpdf_padMultipleBefore(int, int); 879 | 880 | /* CHAPTER 10. Annotations */ 881 | 882 | /* Return the annotations from a PDF in JSON format, returning also its length. 883 | */ 884 | void *cpdf_annotationsJSON(int, int *); 885 | 886 | /* CHAPTER 11. Document Information and Metadata */ 887 | 888 | /* 889 | * cpdf_isLinearized(filename) finds out if a document is linearized as 890 | * quickly as possible without loading it. 891 | */ 892 | int cpdf_isLinearized(const char[]); 893 | 894 | /* cpdf_getVersion(pdf) returns the minor version number of a document. */ 895 | int cpdf_getVersion(int); 896 | 897 | /* cpdf_getMajorVersion(pdf) returns the minor version number of a document. */ 898 | int cpdf_getMajorVersion(int); 899 | 900 | /* cpdf_getTitle(pdf) returns the title of a document. */ 901 | char *cpdf_getTitle(int); 902 | 903 | /* cpdf_getAuthor(pdf) returns the author of a document. */ 904 | char *cpdf_getAuthor(int); 905 | 906 | /* cpdf_getSubject(pdf) returns the subject of a document. */ 907 | char *cpdf_getSubject(int); 908 | 909 | /* cpdf_getKeywords(pdf) returns the keywords of a document. */ 910 | char *cpdf_getKeywords(int); 911 | 912 | /* cpdf_getCreator(pdf) returns the creator of a document. */ 913 | char *cpdf_getCreator(int); 914 | 915 | /* cpdf_getProducer(pdf) returns the producer of a document. */ 916 | char *cpdf_getProducer(int); 917 | 918 | /* cpdf_getCreationDate(pdf) returns the creation date of a document. */ 919 | char *cpdf_getCreationDate(int); 920 | 921 | /* cpdf_getModificationDate(pdf) returns the modification date of a document. */ 922 | char *cpdf_getModificationDate(int); 923 | 924 | /* cpdf_getTitleXMP(pdf) returns the XMP title of a document. */ 925 | char *cpdf_getTitleXMP(int); 926 | 927 | /* cpdf_getAuthorXMP(pdf) returns the XMP author of a document. */ 928 | char *cpdf_getAuthorXMP(int); 929 | 930 | /* cpdf_getSubjectXMP(pdf) returns the XMP subject of a document. */ 931 | char *cpdf_getSubjectXMP(int); 932 | 933 | /* cpdf_getKeywordsXMP(pdf) returns the XMP keywords of a document. */ 934 | char *cpdf_getKeywordsXMP(int); 935 | 936 | /* cpdf_getCreatorXMP(pdf) returns the XMP creator of a document. */ 937 | char *cpdf_getCreatorXMP(int); 938 | 939 | /* cpdf_getProducerXMP(pdf) returns the XMP producer of a document. */ 940 | char *cpdf_getProducerXMP(int); 941 | 942 | /* cpdf_getCreationDateXMP(pdf) returns the XMP creation date of a document. */ 943 | char *cpdf_getCreationDateXMP(int); 944 | 945 | /* 946 | * cpdf_getModificationDateXMP(pdf) returns the XMP modification date of a 947 | * document. 948 | */ 949 | char *cpdf_getModificationDateXMP(int); 950 | 951 | /* cpdf_setTitle(pdf) sets the title of a document. */ 952 | void cpdf_setTitle(int, const char[]); 953 | 954 | /* cpdf_setAuthor(pdf) sets the author of a document. */ 955 | void cpdf_setAuthor(int, const char[]); 956 | 957 | /* cpdf_setSubject(pdf) sets the subject of a document. */ 958 | void cpdf_setSubject(int, const char[]); 959 | 960 | /* cpdf_setKeywords(pdf) sets the keywords of a document. */ 961 | void cpdf_setKeywords(int, const char[]); 962 | 963 | /* cpdf_setCreator(pdf) sets the creator of a document. */ 964 | void cpdf_setCreator(int, const char[]); 965 | 966 | /* cpdf_setProducer(pdf) sets the producer of a document. */ 967 | void cpdf_setProducer(int, const char[]); 968 | 969 | /* cpdf_setCreationDate(pdf) sets the creation date of a document. */ 970 | void cpdf_setCreationDate(int, const char[]); 971 | 972 | /* cpdf_setModificationDate(pdf) sets the modifcation date of a document. */ 973 | void cpdf_setModificationDate(int, const char[]); 974 | 975 | /* cpdf_setTitleXMP(pdf) sets the XMP title of a document. */ 976 | void cpdf_setTitleXMP(int, const char[]); 977 | 978 | /* cpdf_setAuthorXMP(pdf) sets the XMP author of a document. */ 979 | void cpdf_setAuthorXMP(int, const char[]); 980 | 981 | /* cpdf_setSubjectXMP(pdf) sets the XMP subject of a document. */ 982 | void cpdf_setSubjectXMP(int, const char[]); 983 | 984 | /* cpdf_setKeywordsXMP(pdf) sets the XMP keywords of a document. */ 985 | void cpdf_setKeywordsXMP(int, const char[]); 986 | 987 | /* cpdf_setCreatorXMP(pdf) sets the XMP creator of a document. */ 988 | void cpdf_setCreatorXMP(int, const char[]); 989 | 990 | /* cpdf_setProducerXMP(pdf) sets the XMP producer of a document. */ 991 | void cpdf_setProducerXMP(int, const char[]); 992 | 993 | /* cpdf_setCreationDateXMP(pdf) sets the XMP creation date of a document. */ 994 | void cpdf_setCreationDateXMP(int, const char[]); 995 | 996 | /* 997 | * cpdf_setModificationDateXMP(pdf) sets the XMP modification date of a 998 | * document. 999 | */ 1000 | void cpdf_setModificationDateXMP(int, const char[]); 1001 | 1002 | /* 1003 | * Dates: Month 1-31, day 1-31, hours (0-23), minutes (0-59), seconds (0-59), 1004 | * hour_offset is the offset from UT in hours (-23 to 23); minute_offset is 1005 | * the offset from UT in minutes (-59 to 59). 1006 | */ 1007 | 1008 | /* 1009 | * cpdf_getDateComponents(datestring, year, month, day, hour, minute, second, 1010 | * hour_offset, minute_offset) returns the components from a PDF date string. 1011 | */ 1012 | void cpdf_getDateComponents(const char[], int *, int *, int *, int *, int *, 1013 | int *, int *, int *); 1014 | 1015 | /* 1016 | * cpdf_dateStringOfComponents(year, month, day, hour, minute, second, 1017 | * hour_offset, minute_offset) builds a PDF date string from individual 1018 | * components. 1019 | */ 1020 | char *cpdf_dateStringOfComponents(int, int, int, int, int, int, int, int); 1021 | 1022 | /* 1023 | * cpdf_getPageRotation(pdf, pagenumber) gets the viewing rotation for a 1024 | * given page. 1025 | */ 1026 | int cpdf_getPageRotation(int, int); 1027 | 1028 | /* 1029 | * cpdf_hasBox(pdf, pagenumber, boxname) returns true, if that page has the 1030 | * given box. E.g "/CropBox". 1031 | */ 1032 | int cpdf_hasBox(int, int, const char[]); 1033 | 1034 | /* 1035 | * These functions get a box given the document, page number, min x, max x, 1036 | * min y, max y in points. Only succeeds if such a box exists, as checked by 1037 | * cpdf_hasBox. 1038 | */ 1039 | void cpdf_getMediaBox(int, int, double *, double *, double *, double *); 1040 | void cpdf_getCropBox(int, int, double *, double *, double *, double *); 1041 | void cpdf_getTrimBox(int, int, double *, double *, double *, double *); 1042 | void cpdf_getArtBox(int, int, double *, double *, double *, double *); 1043 | void cpdf_getBleedBox(int, int, double *, double *, double *, double *); 1044 | 1045 | /* 1046 | * These functions set a box given the document, page range, min x, max x, 1047 | * min y, max y in points. 1048 | */ 1049 | void cpdf_setMediabox(int, int, double, double, double, double); 1050 | void cpdf_setCropBox(int, int, double, double, double, double); 1051 | void cpdf_setTrimBox(int, int, double, double, double, double); 1052 | void cpdf_setArtBox(int, int, double, double, double, double); 1053 | void cpdf_setBleedBox(int, int, double, double, double, double); 1054 | 1055 | /* cpdf_markTrapped(pdf) marks a document as trapped. */ 1056 | void cpdf_markTrapped(int); 1057 | 1058 | /* cpdf_markUntrapped(pdf) marks a document as untrapped. */ 1059 | void cpdf_markUntrapped(int); 1060 | 1061 | /* cpdf_markTrappedXMP(pdf) marks a document as trapped in XMP metadata. */ 1062 | void cpdf_markTrappedXMP(int); 1063 | 1064 | /* cpdf_markUntrappedXMP(pdf) marks a document as untrapped in XMP metadata. */ 1065 | void cpdf_markUntrappedXMP(int); 1066 | 1067 | /* Document Layouts. */ 1068 | enum cpdf_layout { 1069 | cpdf_singlePage, 1070 | cpdf_oneColumn, 1071 | cpdf_twoColumnLeft, 1072 | cpdf_twoColumnRight, 1073 | cpdf_twoPageLeft, 1074 | cpdf_twoPageRight 1075 | }; 1076 | 1077 | /* cpdf_setPageLayout(pdf, layout) sets the page layout for a document. */ 1078 | void cpdf_setPageLayout(int, enum cpdf_layout); 1079 | 1080 | /* Document page modes. */ 1081 | enum cpdf_pageMode { 1082 | cpdf_useNone, 1083 | cpdf_useOutlines, 1084 | cpdf_useThumbs, 1085 | cpdf_useOC, 1086 | cpdf_useAttachments 1087 | }; 1088 | 1089 | /* cpdf_setPageMode(pdf, mode) sets the page mode for a document. */ 1090 | void cpdf_setPageMode(int, enum cpdf_pageMode); 1091 | 1092 | /* cpdf_hideToolbar(pdf, flag) sets the hide toolbar flag. */ 1093 | void cpdf_hideToolbar(int, int); 1094 | 1095 | /* cpdf_hideMenubar(pdf, flag) sets the hide menu bar flag. */ 1096 | void cpdf_hideMenubar(int, int); 1097 | 1098 | /* cpdf_hideWindowUi(pdf, flag) sets the hide window UI flag. */ 1099 | void cpdf_hideWindowUi(int, int); 1100 | 1101 | /* cpdf_fitWindow(pdf, flag) sets the fit window flag. */ 1102 | void cpdf_fitWindow(int, int); 1103 | 1104 | /* cpdf_centerWindow(pdf, flag) sets the center window flag. */ 1105 | void cpdf_centerWindow(int, int); 1106 | 1107 | /* cpdf_displayDocTitle(pdf, flag) sets the display doc title flag. */ 1108 | void cpdf_displayDocTitle(int, int); 1109 | 1110 | /* cpdf_openAtPage(pdf, fit, pagenumber) sets the PDF to open, possibly with 1111 | * zoom-to-fit, at the given page number. */ 1112 | void cpdf_openAtPage(int, int, int); 1113 | 1114 | /* 1115 | * cpdf_setMetadataFromFile(pdf, filename) set the XMP metadata of a 1116 | * document, given a file name. 1117 | */ 1118 | void cpdf_setMetadataFromFile(int, const char[]); 1119 | 1120 | /* 1121 | * cpdf_setMetadataFromByteArray(pdf, data, length) set the XMP metadata from 1122 | * an array of bytes. 1123 | */ 1124 | void cpdf_setMetadataFromByteArray(int, void *, int); 1125 | 1126 | /* 1127 | * cpdf_getMetadata(pdf, &length) returns the XMP metadata and fills in 1128 | * length. 1129 | */ 1130 | void *cpdf_getMetadata(int, int *); 1131 | 1132 | /* cpdf_removeMetadata(pdf) removes the XMP metadata from a document. */ 1133 | void cpdf_removeMetadata(int); 1134 | 1135 | /* 1136 | * cpdf_createMetadata(pdf) builds fresh metadata as best it can from 1137 | * existing metadata in the document. 1138 | */ 1139 | void cpdf_createMetadata(int); 1140 | 1141 | /* 1142 | * cpdf_setMetadataDate(pdf, date) sets the metadata date for a PDF. The date 1143 | * is given in PDF date format -- cpdf will convert it to XMP format. The 1144 | * date 'now' means now. 1145 | */ 1146 | void cpdf_setMetadataDate(int, const char[]); 1147 | 1148 | /* Styles of page label */ 1149 | enum cpdf_pageLabelStyle { 1150 | cpdf_decimalArabic, /* 1, 2, 3... */ 1151 | cpdf_uppercaseRoman, /* I, II, III... */ 1152 | cpdf_lowercaseRoman, /* i, ii, iii... */ 1153 | cpdf_uppercaseLetters, /* A, B, C... */ 1154 | cpdf_lowercaseLetters /* a, b, c... */ 1155 | }; 1156 | 1157 | /* 1158 | * Add page labels. 1159 | * 1160 | * cpdf_addPageLabels(pdf, style, prefix, offset, range, progress) 1161 | * 1162 | * The prefix is prefix text for each label. The range is the page range the 1163 | * labels apply to. Offset can be used to shift the numbering up or down. 1164 | */ 1165 | void cpdf_addPageLabels(int, enum cpdf_pageLabelStyle, const char[], int, int, 1166 | int); 1167 | 1168 | /* cpdf_removePageLabels(pdf) removes the page labels from the document. */ 1169 | void cpdf_removePageLabels(int); 1170 | 1171 | /* 1172 | * cpdf_getPageLabelStringForPage(pdf, page number) calculates the full label 1173 | * string for a given page, and returns it. 1174 | */ 1175 | char *cpdf_getPageLabelStringForPage(int, int); 1176 | 1177 | /* 1178 | * Get page label data. Call cpdf_startGetPageLabels to find out how many 1179 | * there are, then use these serial numbers to get the style, prefix, offset 1180 | * and start value (note not a range). Call cpdf_endGetPageLabels to clean up. 1181 | * 1182 | * For example, a document might have five pages of introduction with roman 1183 | * numerals, followed by the rest of the pages in decimal arabic, numbered from 1184 | * one: 1185 | * 1186 | * labelstyle = LowercaseRoman 1187 | * labelprefix = "" 1188 | * startpage = 1 1189 | * startvalue = 1 1190 | * 1191 | * labelstyle = DecimalArabic 1192 | * labelprefix = "" 1193 | * startpage = 6 1194 | * startvalue = 1 1195 | */ 1196 | int cpdf_startGetPageLabels(int); 1197 | enum cpdf_pageLabelStyle cpdf_getPageLabelStyle(int); 1198 | char *cpdf_getPageLabelPrefix(int); 1199 | int cpdf_getPageLabelOffset(int); 1200 | int cpdf_getPageLabelRange(int); 1201 | void cpdf_endGetPageLabels(); 1202 | 1203 | /* CHAPTER 12. File Attachments */ 1204 | 1205 | /* 1206 | * cpdf_attachFile(filename, pdf) attaches a file to the pdf. It is attached 1207 | * at document level. 1208 | */ 1209 | void cpdf_attachFile(const char[], int); 1210 | 1211 | /* 1212 | * cpdf_attachFileToPage(filename, pdf, pagenumber) attaches a file, given 1213 | * its file name, pdf, and the page number to which it should be attached. 1214 | */ 1215 | void cpdf_attachFileToPage(const char[], int, int); 1216 | 1217 | /* 1218 | * cpdf_attachFileFromMemory(memory, length, filename, pdf) attaches from 1219 | * memory, just like cpdf_attachFile. 1220 | */ 1221 | void cpdf_attachFileFromMemory(void *, int, const char[], int); 1222 | 1223 | /* 1224 | * cpdf_attachFileToPageFromMemory(memory, length, filename, pdf, pagenumber) 1225 | * attaches from memory, just like cpdf_attachFileToPage. 1226 | */ 1227 | void cpdf_attachFileToPageFromMemory(void *, int, const char[], int, int); 1228 | 1229 | /* Remove all page- and document-level attachments from a document. */ 1230 | void cpdf_removeAttachedFiles(int); 1231 | 1232 | /* 1233 | * List information about attachments. Call cpdf_startGetAttachments(pdf) 1234 | * first, then cpdf_numberGetAttachments to find out how many there are. Then 1235 | * cpdf_getAttachmentName etc. to return each one 0...(n - 1). Finally, call 1236 | * cpdf_endGetAttachments to clean up. 1237 | */ 1238 | void cpdf_startGetAttachments(int); 1239 | 1240 | /* Get the number of attachments. */ 1241 | int cpdf_numberGetAttachments(void); 1242 | 1243 | /* Get the name of the attachment. */ 1244 | char *cpdf_getAttachmentName(int); 1245 | 1246 | /* Gets the page number. 0 = document level. */ 1247 | int cpdf_getAttachmentPage(int); 1248 | 1249 | /* 1250 | * cpdf_getAttachmentData(serial number, &length) returns a pointer to the 1251 | * data, and its length. 1252 | */ 1253 | void *cpdf_getAttachmentData(int, int *); 1254 | 1255 | /* Clean up after getting attachments. */ 1256 | void cpdf_endGetAttachments(void); 1257 | 1258 | /* CHAPTER 13. Images. */ 1259 | 1260 | /* 1261 | * Get image data, including resolution at all points of use. Call 1262 | * cpdf_startGetImageResolution(pdf, min_required_resolution) will begin the 1263 | * process of obtaining data on all image uses below min_required_resolution, 1264 | * returning the total number. So, to return all image uses, specify a very 1265 | * high min_required_resolution. Then, call the other functions giving a 1266 | * serial number 0.. - 1, to retrieve the data. Finally, call 1267 | * cpdf_endGetImageResolution to clean up. 1268 | */ 1269 | int cpdf_startGetImageResolution(int, float); 1270 | int cpdf_getImageResolutionPageNumber(int); 1271 | char *cpdf_getImageResolutionImageName(int); 1272 | int cpdf_getImageResolutionXPixels(int); 1273 | int cpdf_getImageResolutionYPixels(int); 1274 | double cpdf_getImageResolutionXRes(int); 1275 | double cpdf_getImageResolutionYRes(int); 1276 | void cpdf_endGetImageResolution(void); 1277 | 1278 | /* CHAPTER 14. Fonts. */ 1279 | 1280 | /* 1281 | * Retrieving font information. First, call cpdf_startGetFontInfo(pdf). Now 1282 | * call cpdf_numberFonts to return the number of fonts. For each font, call 1283 | * one or more of cpdf_getFontPage, cpdf_getFontName, cpdf_getFontType, and 1284 | * cpdf_getFontEncoding giving a serial number 0.. - 1 to 1285 | * return information. Finally, call cpdf_endGetFontInfo to clean up. 1286 | */ 1287 | void cpdf_startGetFontInfo(int); 1288 | int cpdf_numberFonts(void); 1289 | int cpdf_getFontPage(int); 1290 | char *cpdf_getFontName(int); 1291 | char *cpdf_getFontType(int); 1292 | char *cpdf_getFontEncoding(int); 1293 | void cpdf_endGetFontInfo(void); 1294 | 1295 | /* cpdf_removeFonts(pdf) removes all font data from a file. */ 1296 | void cpdf_removeFonts(int); 1297 | 1298 | /* 1299 | * cpdf_copyFont(from, to, range, pagenumber, fontname) copies the given font 1300 | * from the given page in the 'from' PDF to every page in the 'to' PDF. The 1301 | * new font is stored under its font name. 1302 | */ 1303 | void cpdf_copyFont(int, int, int, int, const char[]); 1304 | 1305 | /* CHAPTER 15. PDF and JSON */ 1306 | 1307 | /* cpdf_outputJSON(filename, parse_content, no_stream_data, pdf) outputs a PDF 1308 | * in JSON format to the given filename. If parse_content is true, page content 1309 | * is parsed. If no_stream_data is true, all stream data is suppressed entirely. 1310 | * */ 1311 | void cpdf_outputJSON(const char[], int, int, int, int); 1312 | 1313 | /* cpdf_outputJSONMemory(parse_content, no_stream_data, pdf, &length) is like 1314 | * outputJSON, but it writes to a buffer in memory. The length is filled in. */ 1315 | void *cpdf_outputJSONMemory(int, int, int, int, int *); 1316 | 1317 | /* Load a PDF from a JSON file given its filename. */ 1318 | int cpdf_fromJSON(const char[]); 1319 | 1320 | /* Load a PDF from a JSON file in memory, given the buffer and its length. */ 1321 | int cpdf_fromJSONMemory(void *, int); 1322 | 1323 | /* CHAPTER 16. Optional Content Groups */ 1324 | 1325 | /* Begin retrieving optional content group names. The serial number 0.. 1326 | * is returned. */ 1327 | int cpdf_startGetOCGList(int pdf); 1328 | 1329 | /* Retrieve an OCG name, given its serial number 0... */ 1330 | char *cpdf_OCGListEntry(int i); 1331 | 1332 | /* End retrieval of optional content group names. */ 1333 | void cpdf_endGetOCGList(void); 1334 | 1335 | /* cpdf_OCGRename(pdf, from, to) will rename an optional content group. */ 1336 | void cpdf_OCGRename(int, const char[], const char[]); 1337 | 1338 | /* Ensure that every optional content group appears in the OCG order list. */ 1339 | void cpdf_OCGOrderAll(int); 1340 | 1341 | /* Coalesce optional content groups. For example, if we merge or stamp two 1342 | * files both with an OCG called "Layer 1", we will have two different optional 1343 | * content groups. This function will merge the two into a single optional 1344 | * content group. */ 1345 | void cpdf_OCGCoalesce(int); 1346 | 1347 | /* CHAPTER 17. Creating New PDFs */ 1348 | 1349 | /* cpdf_blankDocument(width, height, num_pages) creates a blank document with 1350 | * pages of the given width (in points), height (in points), and number of 1351 | * pages. 1352 | */ 1353 | int cpdf_blankDocument(double, double, int); 1354 | 1355 | /* 1356 | * cpdf_blankDocumentPaper(papersize, num_pages) makes a blank document given 1357 | * a page size and number of pages. 1358 | */ 1359 | int cpdf_blankDocumentPaper(enum cpdf_papersize, int); 1360 | 1361 | /* cpdf_textToPDF(w, h, font, fontsize, filename) typesets a UTF8 text file 1362 | * ragged right on a page of size w * h in points in the given font and font 1363 | * size. */ 1364 | int cpdf_textToPDF(double, double, int, double, const char[]); 1365 | 1366 | /* cpdf_textToPDF(papersize font, fontsize, filename) typesets a UTF8 text file 1367 | * ragged right on a page of the given size in the given font and font size. */ 1368 | int cpdf_textToPDFPaper(int, int, double, const char[]); 1369 | 1370 | /* CHAPTER 18. Miscellaneous */ 1371 | 1372 | /* 1373 | * cpdf_draft(pdf, range, boxes) removes images on the given pages, replacing 1374 | * them with crossed boxes if 'boxes' is true. 1375 | */ 1376 | void cpdf_draft(int, int, int); 1377 | 1378 | /* 1379 | * cpdf_removeAllText(pdf, range) removes all text from the given pages in a 1380 | * given document. 1381 | */ 1382 | void cpdf_removeAllText(int, int); 1383 | 1384 | /* cpdf_blackText(pdf, range) blackens all text on the given pages. */ 1385 | void cpdf_blackText(int, int); 1386 | 1387 | /* cpdf_blackLines(pdf, range) blackens all lines on the given pages. */ 1388 | void cpdf_blackLines(int, int); 1389 | 1390 | /* cpdf_blackFills(pdf, range) blackens all fills on the given pages. */ 1391 | void cpdf_blackFills(int, int); 1392 | 1393 | /* 1394 | * cpdf_thinLines(pdf, range, min_thickness) thickens every line less than 1395 | * min_thickness to min_thickness. Thickness given in points. 1396 | */ 1397 | void cpdf_thinLines(int, int, double); 1398 | 1399 | /* cpdf_copyId(from, to) copies the /ID from one document to another. */ 1400 | void cpdf_copyId(int, int); 1401 | 1402 | /* cpdf_removeId(pdf) removes a document's /ID. */ 1403 | void cpdf_removeId(int); 1404 | 1405 | /* cpdf_setVersion(pdf, version) sets the minor version number of a document. */ 1406 | void cpdf_setVersion(int, int); 1407 | 1408 | /* cpdf_setFullVersion(pdf, major_version, minor_version) sets the full version 1409 | * number of a document. */ 1410 | void cpdf_setFullVersion(int, int, int); 1411 | 1412 | /* 1413 | * cpdf_removeDictEntry(pdf, key) removes any dictionary entry with the given 1414 | * key anywhere in the document. 1415 | */ 1416 | void cpdf_removeDictEntry(int, const char[]); 1417 | 1418 | /* cpdf_removeDictEntrySearch(pdf, key, seachterm) removes any dictionary entry 1419 | * with the given key whose value matches the given search term. */ 1420 | void cpdf_removeDictEntrySearch(int, const char[], const char[]); 1421 | 1422 | /* cpdf_replaceDictEntry(pdf, key, newvalue) replaces the value associated with 1423 | * the given key. */ 1424 | void cpdf_replaceDictEntry(int, const char[], const char[]); 1425 | 1426 | /* cpdf_replaceDictEntry(pdf, key, newvalue, searchterm) replaces the value 1427 | * associated with the given key if the existing value matches the search term. 1428 | */ 1429 | void cpdf_replaceDictEntrySearch(int, const char[], const char[], const char[]); 1430 | 1431 | /* cpdf_getDictEntries(pdf, key, length) returns a JSON array containing any 1432 | * and all values associated with the given key, and fills in its length. */ 1433 | void *cpdf_getDictEntries(int, const char[], int *retlen); 1434 | 1435 | /* 1436 | * cpdf_removeClipping(pdf, range) removes all clipping from pages in the 1437 | * given range. 1438 | */ 1439 | void cpdf_removeClipping(int, int); 1440 | -------------------------------------------------------------------------------- /dotnet/dotnet-libcpdf.deps.json: -------------------------------------------------------------------------------- 1 | { 2 | "runtimeTarget": { 3 | "name": ".NETCoreApp,Version=v5.0", 4 | "signature": "" 5 | }, 6 | "compilationOptions": {}, 7 | "targets": { 8 | ".NETCoreApp,Version=v5.0": { 9 | "dotnet-libcpdf/2.5.2": { 10 | "runtime": { 11 | "dotnet-libcpdf.dll": {} 12 | } 13 | } 14 | } 15 | }, 16 | "libraries": { 17 | "dotnet-libcpdf/2.5.2": { 18 | "type": "project", 19 | "serviceable": false, 20 | "sha512": "" 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /dotnet/dotnet-libcpdf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/dotnet/dotnet-libcpdf.dll -------------------------------------------------------------------------------- /dotnet/dotnet-libcpdf.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/dotnet/dotnet-libcpdf.pdb -------------------------------------------------------------------------------- /dotnetcpdflibmanual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/dotnetcpdflibmanual.pdf -------------------------------------------------------------------------------- /java/coherentpdf.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/java/coherentpdf.jar -------------------------------------------------------------------------------- /jcpdflibmanual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/jcpdflibmanual.pdf -------------------------------------------------------------------------------- /linux32/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/linux32/.gitignore -------------------------------------------------------------------------------- /linux32/libcpdf.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/linux32/libcpdf.a -------------------------------------------------------------------------------- /linux32/libcpdf.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/linux32/libcpdf.so -------------------------------------------------------------------------------- /linux32/libjcpdf.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/linux32/libjcpdf.so -------------------------------------------------------------------------------- /linux32/libpycpdf.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/linux32/libpycpdf.so -------------------------------------------------------------------------------- /linux32/readme.txt: -------------------------------------------------------------------------------- 1 | COHERENT PDF C API 2 | 3 | There is one header file, cpdflibwrapper.h, and a static library and DLL(s). 4 | 5 | Sample linking on Linux with static libraries: 6 | 7 | cc program.c -o program -L. -lcpdf -lm -ldl 8 | 9 | Sample linking on Windows with DLL: 10 | 11 | cc program.c -o program.exe -Wl,-rpath,. -L. -l:libcpdf.dll 12 | 13 | Sample linking on OS X with static libraries: 14 | 15 | cc program.c -o program -L. -lcpdf 16 | 17 | 18 | COHERENT PDF Python API 19 | 20 | Use pycpdflib.py and import Pycpdflib with the DLLs libcpdf and pylibcpdf. 21 | Further instruction in pycpdflibmanual.pdf. 22 | 23 | Also available directly with "pip install pycpdflib" (just installs 24 | pycpdflib.py). 25 | 26 | Online docs: https://python-libcpdf.readthedocs.io/en/latest/ 27 | 28 | 29 | COHERENT PDF .NET API 30 | 31 | A nuget package, and the plain assembly in the dotnet folder are provided. 32 | 33 | Full manual (required reading): dotnetcpdflibmanual.pdf in this folder. Follow 34 | the instructions at the end of Chapter 1 to write your first program. 35 | 36 | In addition, the assembly and nuget package provide Intellisense documentation 37 | with each function. 38 | 39 | Before using the library, you must make sure your project or build environment 40 | has access to the cpdf DLL libcpdf.so, which is not part of the .NET assembly 41 | or nuget package. You can add it to a Visual Studio project as a file, set to 42 | copy-to-output-folder. Or, you can install it in a standard location such as 43 | the /usr/local/lib. 44 | 45 | 46 | COHERENT PDF JAVA API 47 | 48 | Use the .jar supplied in the java folder. 49 | 50 | Full manual (required reading): jcpdflibmanual.pdf in this folder. Follow 51 | the instructions at the end of Chapter 1 to write your first program. 52 | 53 | You will also require the jcpdf DLL from the platform folder, and the main cpdf 54 | DLL too. 55 | 56 | The java library invokes LoadLibrary on the jcpdf DLL, and so it must be placed 57 | in your java.library.path. The cpdf DLL itself will be searched for not by 58 | Java, but by your system, as a dependency of jcpdf. 59 | 60 | Files should be named libjcpdf.so and libcpdf.so. Put libjcpdf.so in your 61 | java.library.path. You must put libcpdf.so in a standard location such as 62 | /usr/local/lib, or set LD_LIBRARY_PATH. Simply putting it in the same folder as 63 | libjcpdf.so will not work. 64 | -------------------------------------------------------------------------------- /linux64/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/linux64/.gitignore -------------------------------------------------------------------------------- /linux64/libcpdf.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/linux64/libcpdf.a -------------------------------------------------------------------------------- /linux64/libcpdf.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/linux64/libcpdf.so -------------------------------------------------------------------------------- /linux64/libjcpdf.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/linux64/libjcpdf.so -------------------------------------------------------------------------------- /linux64/libpycpdf.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/linux64/libpycpdf.so -------------------------------------------------------------------------------- /linux64/readme.txt: -------------------------------------------------------------------------------- 1 | COHERENT PDF C API 2 | 3 | There is one header file, cpdflibwrapper.h, and a static library and DLL(s). 4 | 5 | Sample linking on Linux with static libraries: 6 | 7 | cc program.c -o program -L. -lcpdf -lm -ldl 8 | 9 | Sample linking on Windows with DLL: 10 | 11 | cc program.c -o program.exe -Wl,-rpath,. -L. -l:libcpdf.dll 12 | 13 | Sample linking on OS X with static libraries: 14 | 15 | cc program.c -o program -L. -lcpdf 16 | 17 | 18 | COHERENT PDF Python API 19 | 20 | Use pycpdflib.py and import Pycpdflib with the DLLs libcpdf and pylibcpdf. 21 | Further instruction in pycpdflibmanual.pdf. 22 | 23 | Also available directly with "pip install pycpdflib" (just installs 24 | pycpdflib.py). 25 | 26 | Online docs: https://python-libcpdf.readthedocs.io/en/latest/ 27 | 28 | 29 | COHERENT PDF .NET API 30 | 31 | A nuget package, and the plain assembly in the dotnet folder are provided. 32 | 33 | Full manual (required reading): dotnetcpdflibmanual.pdf in this folder. Follow 34 | the instructions at the end of Chapter 1 to write your first program. 35 | 36 | In addition, the assembly and nuget package provide Intellisense documentation 37 | with each function. 38 | 39 | Before using the library, you must make sure your project or build environment 40 | has access to the cpdf DLL libcpdf.so, which is not part of the .NET assembly 41 | or nuget package. You can add it to a Visual Studio project as a file, set to 42 | copy-to-output-folder. Or, you can install it in a standard location such as 43 | the /usr/local/lib. 44 | 45 | 46 | COHERENT PDF JAVA API 47 | 48 | Use the .jar supplied in the java folder. 49 | 50 | Full manual (required reading): jcpdflibmanual.pdf in this folder. Follow 51 | the instructions at the end of Chapter 1 to write your first program. 52 | 53 | You will also require the jcpdf DLL from the platform folder, and the main cpdf 54 | DLL too. 55 | 56 | The java library invokes LoadLibrary on the jcpdf DLL, and so it must be placed 57 | in your java.library.path. The cpdf DLL itself will be searched for not by 58 | Java, but by your system, as a dependency of jcpdf. 59 | 60 | Files should be named libjcpdf.so and libcpdf.so. Put libjcpdf.so in your 61 | java.library.path. You must put libcpdf.so in a standard location such as 62 | /usr/local/lib, or set LD_LIBRARY_PATH. Simply putting it in the same folder as 63 | libjcpdf.so will not work. 64 | -------------------------------------------------------------------------------- /macosx-arm/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/macosx-arm/.gitignore -------------------------------------------------------------------------------- /macosx-arm/libcpdf.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/macosx-arm/libcpdf.a -------------------------------------------------------------------------------- /macosx-arm/libcpdf.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/macosx-arm/libcpdf.so -------------------------------------------------------------------------------- /macosx-arm/libjcpdf.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/macosx-arm/libjcpdf.dylib -------------------------------------------------------------------------------- /macosx-arm/libpycpdf.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/macosx-arm/libpycpdf.so -------------------------------------------------------------------------------- /macosx-arm/readme.txt: -------------------------------------------------------------------------------- 1 | COHERENT PDF C API 2 | 3 | There is one header file, cpdflibwrapper.h, and a static library and DLL(s). 4 | 5 | Sample linking on Linux with static libraries: 6 | 7 | cc program.c -o program -L. -lcpdf -lm -ldl 8 | 9 | Sample linking on Windows with DLL: 10 | 11 | cc program.c -o program.exe -Wl,-rpath,. -L. -l:libcpdf.dll 12 | 13 | Sample linking on OS X with static libraries: 14 | 15 | cc program.c -o program -L. -lcpdf 16 | 17 | The libraries are codesigned, but not notarized, so you may need to codesign 18 | them to build your software, and notarize as part of releasing your software. 19 | 20 | 21 | COHERENT PDF Python API 22 | 23 | Use pycpdflib.py and import Pycpdflib with the DLLs libcpdf and pylibcpdf. 24 | Further instruction in pycpdflibmanual.pdf. 25 | 26 | Also available directly with "pip install pycpdflib" (just installs 27 | pycpdflib.py). 28 | 29 | Online docs: https://python-libcpdf.readthedocs.io/en/latest/ 30 | 31 | 32 | COHERENT PDF .NET API 33 | 34 | A nuget package, and the plain assembly in the dotnet folder are provided. 35 | 36 | Full manual (required reading): dotnetcpdflibmanual.pdf in this folder. Follow 37 | the instructions at the end of Chapter 1 to write your first program. 38 | 39 | In addition, the assembly and nuget package provide Intellisense documentation 40 | with each function. 41 | 42 | Before using the library, you must make sure your project or build environment 43 | has access to the cpdf DLL libcpdf.so, which is not part of the .NET assembly 44 | or nuget package. You can add it to a Visual Studio project as a file, set to 45 | copy-to-output-folder. Or, you can install it in a standard location such as 46 | the /usr/local/lib. 47 | 48 | ***IMPORTANT The DLL libcpdf.so must be renamed libcpdf.dylib for .NET to be 49 | able to find it.*** 50 | 51 | 52 | COHERENT PDF JAVA API 53 | 54 | Use the .jar supplied in the java folder. 55 | 56 | Full manual (required reading): jcpdflibmanual.pdf in this folder. Follow 57 | the instructions at the end of Chapter 1 to write your first program. 58 | 59 | You will also require the jcpdf DLL from the platform folder, and the main cpdf 60 | DLL too. 61 | 62 | The java library invokes LoadLibrary on the jcpdf DLL, and so it must be placed 63 | in your java.library.path. The cpdf DLL itself will be searched for not by 64 | Java, but by your system, as a dependency of jcpdf. 65 | 66 | Files should be named libjcpdf.dylib and libcpdf.so. Put libjcpdf.dylib in 67 | java.library.path. You can put libcpdf.so in the same folder 68 | - it will be picked up automatically. 69 | -------------------------------------------------------------------------------- /macosx/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/macosx/.gitignore -------------------------------------------------------------------------------- /macosx/libcpdf.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/macosx/libcpdf.a -------------------------------------------------------------------------------- /macosx/libcpdf.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/macosx/libcpdf.so -------------------------------------------------------------------------------- /macosx/libjcpdf.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/macosx/libjcpdf.dylib -------------------------------------------------------------------------------- /macosx/libpycpdf.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/macosx/libpycpdf.so -------------------------------------------------------------------------------- /macosx/readme.txt: -------------------------------------------------------------------------------- 1 | COHERENT PDF C API 2 | 3 | There is one header file, cpdflibwrapper.h, and a static library and DLL(s). 4 | 5 | Sample linking on Linux with static libraries: 6 | 7 | cc program.c -o program -L. -lcpdf -lm -ldl 8 | 9 | Sample linking on Windows with DLL: 10 | 11 | cc program.c -o program.exe -Wl,-rpath,. -L. -l:libcpdf.dll 12 | 13 | Sample linking on OS X with static libraries: 14 | 15 | cc program.c -o program -L. -lcpdf 16 | 17 | The libraries are codesigned, but not notarized, so you may need to codesign 18 | them to build your software, and notarize as part of releasing your software. 19 | 20 | 21 | COHERENT PDF Python API 22 | 23 | Use pycpdflib.py and import Pycpdflib with the DLLs libcpdf and pylibcpdf. 24 | Further instruction in pycpdflibmanual.pdf. 25 | 26 | Also available directly with "pip install pycpdflib" (just installs 27 | pycpdflib.py). 28 | 29 | Online docs: https://python-libcpdf.readthedocs.io/en/latest/ 30 | 31 | 32 | COHERENT PDF .NET API 33 | 34 | A nuget package, and the plain assembly in the dotnet folder are provided. 35 | 36 | Full manual (required reading): dotnetcpdflibmanual.pdf in this folder. Follow 37 | the instructions at the end of Chapter 1 to write your first program. 38 | 39 | In addition, the assembly and nuget package provide Intellisense documentation 40 | with each function. 41 | 42 | Before using the library, you must make sure your project or build environment 43 | has access to the cpdf DLL libcpdf.so, which is not part of the .NET assembly 44 | or nuget package. You can add it to a Visual Studio project as a file, set to 45 | copy-to-output-folder. Or, you can install it in a standard location such as 46 | the /usr/local/lib. 47 | 48 | ***IMPORTANT The DLL libcpdf.so must be renamed libcpdf.dylib for .NET to be 49 | able to find it.*** 50 | 51 | 52 | COHERENT PDF JAVA API 53 | 54 | Use the .jar supplied in the java folder. 55 | 56 | Full manual (required reading): jcpdflibmanual.pdf in this folder. Follow 57 | the instructions at the end of Chapter 1 to write your first program. 58 | 59 | You will also require the jcpdf DLL from the platform folder, and the main cpdf 60 | DLL too. 61 | 62 | The java library invokes LoadLibrary on the jcpdf DLL, and so it must be placed 63 | in your java.library.path. The cpdf DLL itself will be searched for not by 64 | Java, but by your system, as a dependency of jcpdf. 65 | 66 | Files should be named libjcpdf.dylib and libcpdf.so. Put libjcpdf.dylib in 67 | java.library.path. You can put libcpdf.so in the same folder 68 | - it will be picked up automatically. 69 | -------------------------------------------------------------------------------- /pycpdflib.py: -------------------------------------------------------------------------------- 1 | """Pycpdflib: a python interface to cpdf. 2 | 3 | Before using the library, you must load the libpycpdf and libcpdf DLLs. This is 4 | achieved with the pycpdflib.loadDLL function, given the filename or full path 5 | of the libpycpdf DLL. On Windows, you may have to call os.add_dll_directory 6 | first. On MacOS, you may need to give the full path, and you may need to 7 | install libcpdf.so in a standard location /usr/local/lib/, or use the 8 | install_name_tool command to tell libpycpdf.so where to find libcpdf.so. 9 | """ 10 | 11 | """ 12 | Loading the libpypcdf and libcpdf DLLs 13 | -------------------------------------- 14 | 15 | Before using the library, you must load the ``libpycpdf`` and ``libcpdf`` DLLs. 16 | This is achieved with the ``pycpdflib.loadDLL`` function, given the filename or 17 | full path of the ``libpycpdf`` DLL. 18 | 19 | On Windows, you may have to call ``os.add_dll_directory`` first. On MacOS, you 20 | may need to give the full path, and you may need to install ``libcpdf.so`` in a 21 | standard location ``/usr/local/lib/``, or use the ``install_name_tool`` command 22 | to tell ``libpycpdf.so`` where to find ``libcpdf.so``. 23 | 24 | Conventions 25 | ----------- 26 | 27 | Any function may raise the exception ``CPDFError``, carrying a string describing 28 | the error. 29 | 30 | A 'range' is a list of integers specifying page numbers. Page numbers start at 31 | 1. Range arguments are called `r`. 32 | 33 | Text arguments and results are in UTF8. 34 | 35 | Units are in PDF points (1/72 inch). 36 | 37 | Angles are in degrees. 38 | 39 | 40 | Built-in values 41 | --------------- 42 | 43 | Paper sizes: 44 | 45 | a0portrait a1portrait a2portrait a3portrait a4portrait a5portrait a0landscape 46 | a1landscape a2landscape a3landscape a4landscape a5landscape usletterportrait 47 | usletterlandscape uslegalportrait uslegallandscape 48 | 49 | Permissions: 50 | 51 | noEdit noPrint noCopy noAnnot noForms noExtract noAssemble noHqPrint 52 | 53 | Encryption methods: 54 | 55 | pdf40bit pdf128bit aes128bitfalse aes128bittrue aes256bitfalse aes256bittrue 56 | aes256bitisofalse aes256bitisotrue 57 | 58 | Positions: 59 | 60 | Positions with two numbers in a tuple e.g (posLeft, 10.0, 20.0) 61 | 62 | posCentre posLeft posRight 63 | 64 | Positions with one number in a tuple e.g (top, 5.0) 65 | 66 | top topLeft topRight left bottomLeft bottomRight right 67 | 68 | Positions with no numbers e.g diagonal 69 | 70 | diagonal reverseDiagonal 71 | 72 | Fonts: 73 | 74 | timesRoman timesBold timesItalic timesBoldItalic helvetica helveticaBold 75 | helveticaOblique helveticaBoldOblique courier courierBold courierOblique 76 | courierBoldOblique 77 | 78 | Justification: 79 | 80 | leftJustify centreJustify rightJustify 81 | 82 | Page layouts: 83 | 84 | singlePage oneColumn twoColumnLeft twoColumnRight twoPageLeft twoPageRight 85 | 86 | Page modes: 87 | 88 | useNone useOutlines useThumbs useOC useAttachments 89 | 90 | Page label styles: 91 | 92 | decimalArabic uppercaseRoman lowercaseRoman uppercaseLetters lowercaseLetters 93 | """ 94 | 95 | 96 | from ctypes import * 97 | import sys 98 | libc = None 99 | 100 | # CHAPTER 0. Preliminaries 101 | 102 | 103 | class Pdf: 104 | """The type of PDF documents.""" 105 | pdf = -1 106 | 107 | def __init__(self, pdfnum): 108 | self.pdf = pdfnum 109 | 110 | def __del__(self): 111 | libc.pycpdf_deletePdf(self.pdf) 112 | 113 | 114 | def loadDLL(f): 115 | """Load the libpycpdf DLL from a given file, and set up pycpdflib. Must be 116 | called prior to using any other function in the library.""" 117 | global libc 118 | libc = CDLL(f) 119 | libc.pycpdf_tableOfContents.argtypes = [ 120 | c_int, c_int, c_double, POINTER(c_char), c_int] 121 | libc.pycpdf_version.restype = POINTER(c_char) 122 | libc.pycpdf_lastErrorString.restype = POINTER(c_char) 123 | libc.pycpdf_blankDocument.argtypes = [c_double, c_double, c_int] 124 | libc.pycpdf_textToPDF.argtypes = [ 125 | c_double, c_double, c_int, c_double, POINTER(c_char)] 126 | libc.pycpdf_textToPDFPaper.argtypes = [ 127 | c_int, c_int, c_double, POINTER(c_char)] 128 | libc.pycpdf_ptOfCm.argtypes = [c_double] 129 | libc.pycpdf_ptOfCm.restype = c_double 130 | libc.pycpdf_ptOfMm.argtypes = [c_double] 131 | libc.pycpdf_ptOfMm.restype = c_double 132 | libc.pycpdf_ptOfIn.argtypes = [c_double] 133 | libc.pycpdf_ptOfIn.restype = c_double 134 | libc.pycpdf_cmOfPt.argtypes = [c_double] 135 | libc.pycpdf_cmOfPt.restype = c_double 136 | libc.pycpdf_mmOfPt.argtypes = [c_double] 137 | libc.pycpdf_mmOfPt.restype = c_double 138 | libc.pycpdf_inOfPt.argtypes = [c_double] 139 | libc.pycpdf_inOfPt.restype = c_double 140 | libc.pycpdf_stringOfPagespec.restype = POINTER(c_char) 141 | libc.pycpdf_toMemory.restype = POINTER(c_uint8) 142 | libc.pycpdf_outputJSONMemory.restype = POINTER(c_uint8) 143 | libc.pycpdf_annotationsJSON.restype = POINTER(c_uint8) 144 | libc.pycpdf_getBookmarksJSON.restype = POINTER(c_uint8) 145 | libc.pycpdf_scalePages.argtypes = [c_int, c_int, c_double, c_double] 146 | libc.pycpdf_scaleToFit.argtypes =\ 147 | [c_int, c_int, c_double, c_double, c_double] 148 | libc.pycpdf_scaleToFitPaper.argtypes = [c_int, c_int, c_int, c_double] 149 | libc.pycpdf_scaleContents.argtypes =\ 150 | [c_int, c_int, c_int, c_double, c_double, c_double] 151 | libc.pycpdf_shiftContents.argtypes = [c_int, c_int, c_double, c_double] 152 | libc.pycpdf_rotateContents.argtypes = [c_int, c_int, c_double] 153 | libc.pycpdf_crop.argtypes =\ 154 | [c_int, c_int, c_double, c_double, c_double, c_double] 155 | libc.pycpdf_thinLines.argtypes = [c_int, c_int, c_double] 156 | libc.pycpdf_stampAsXObject.restype = POINTER(c_char) 157 | libc.pycpdf_getTitle.restype = POINTER(c_char) 158 | libc.pycpdf_getAuthor.restype = POINTER(c_char) 159 | libc.pycpdf_getSubject.restype = POINTER(c_char) 160 | libc.pycpdf_getKeywords.restype = POINTER(c_char) 161 | libc.pycpdf_getCreator.restype = POINTER(c_char) 162 | libc.pycpdf_getProducer.restype = POINTER(c_char) 163 | libc.pycpdf_getCreationDate.restype = POINTER(c_char) 164 | libc.pycpdf_getModificationDate.restype = POINTER(c_char) 165 | libc.pycpdf_getTitleXMP.restype = POINTER(c_char) 166 | libc.pycpdf_getAuthorXMP.restype = POINTER(c_char) 167 | libc.pycpdf_getSubjectXMP.restype = POINTER(c_char) 168 | libc.pycpdf_getKeywordsXMP.restype = POINTER(c_char) 169 | libc.pycpdf_getCreatorXMP.restype = POINTER(c_char) 170 | libc.pycpdf_getProducerXMP.restype = POINTER(c_char) 171 | libc.pycpdf_getCreationDateXMP.restype = POINTER(c_char) 172 | libc.pycpdf_getModificationDateXMP.restype = POINTER(c_char) 173 | libc.pycpdf_setMediaBox.argtypes =\ 174 | [c_int, c_int, c_double, c_double, c_double, c_double] 175 | libc.pycpdf_setCropBox.argtypes =\ 176 | [c_int, c_int, c_double, c_double, c_double, c_double] 177 | libc.pycpdf_setTrimBox.argtypes =\ 178 | [c_int, c_int, c_double, c_double, c_double, c_double] 179 | libc.pycpdf_setArtBox.argtypes =\ 180 | [c_int, c_int, c_double, c_double, c_double, c_double] 181 | libc.pycpdf_setBleedBox.argtypes =\ 182 | [c_int, c_int, c_double, c_double, c_double, c_double] 183 | libc.pycpdf_getBookmarkText.restype = POINTER(c_char) 184 | libc.pycpdf_addText.argtypes =\ 185 | [c_int, c_int, c_int, POINTER(c_char), c_int, c_double, c_double, 186 | c_double, c_int, c_int, c_double, c_double, c_double, c_double, c_int, 187 | c_int, c_int, c_double, c_int, c_int, c_int, POINTER(c_char), 188 | c_double, c_int] 189 | libc.pycpdf_addTextSimple.argtypes =\ 190 | [c_int, c_int, POINTER(c_char), c_int, c_double, 191 | c_double, c_int, c_double] 192 | libc.pycpdf_getMetadata.restype = POINTER(c_uint8) 193 | libc.pycpdf_getDictEntries.restype = POINTER(c_uint8) 194 | libc.pycpdf_getAttachmentData.restype = POINTER(c_uint8) 195 | libc.pycpdf_getAttachmentName.restype = POINTER(c_char) 196 | libc.pycpdf_startGetImageResolution.argtypes = [c_int, c_double] 197 | libc.pycpdf_getImageResolutionImageName.restype = POINTER(c_char) 198 | libc.pycpdf_getFontName.restype = POINTER(c_char) 199 | libc.pycpdf_getFontType.restype = POINTER(c_char) 200 | libc.pycpdf_getFontEncoding.restype = POINTER(c_char) 201 | libc.pycpdf_getPageLabelStringForPage.restype = POINTER(c_char) 202 | libc.pycpdf_getPageLabelPrefix.restype = POINTER(c_char) 203 | libc.pycpdf_dateStringOfComponents.restype = POINTER(c_char) 204 | libc.pycpdf_OCGListEntry.restype = POINTER(c_char) 205 | libc.pycpdf_stampExtended.argtypes = [ 206 | c_int, c_int, c_int, c_int, c_int, c_int, c_double, c_double, c_int] 207 | libc.pycpdf_getImageResolutionXRes.restype = c_double 208 | libc.pycpdf_getImageResolutionYRes.restype = c_double 209 | libc.pycpdf_impose.argtypes = [c_int, c_double, c_double, c_int, 210 | c_int, c_int, c_int, c_int, c_double, c_double, c_double] 211 | LP_c_char = POINTER(c_char) 212 | LP_LP_c_char = POINTER(LP_c_char) 213 | argc = len(sys.argv) 214 | argv = (LP_c_char * (argc + 1))() 215 | for i, arg in enumerate(sys.argv): 216 | enc_arg = arg.encode('utf-8') 217 | argv[i] = create_string_buffer(enc_arg) 218 | libc.pycpdf_startup.argtypes = [LP_LP_c_char] 219 | libc.pycpdf_startup(argv) 220 | checkerror() 221 | 222 | 223 | class CPDFError(Exception): 224 | """Any function may raise an exception CPDFError, carrying a string 225 | describing what went wrong.""" 226 | 227 | def __init__(self, message): 228 | self.message = message 229 | super().__init__(self.message) 230 | 231 | 232 | def lastError(): 233 | """Return the last error. Not usually used directly, since pycpdflib 234 | functions raise exceptions.""" 235 | return libc.pycpdf_lastError() 236 | 237 | 238 | def lastErrorString(): 239 | """Return the last error string. Not usually used directly, since pycpdflib 240 | functions raise exceptions.""" 241 | return string_at(libc.pycpdf_lastErrorString()).decode() 242 | 243 | 244 | def checkerror(): 245 | """Raise an exception if the last function call resulted in an error. Not 246 | used directly, since pycpdflib functions will raise the exception 247 | directly.""" 248 | if lastError() != 0: 249 | s = lastErrorString() 250 | clearError() 251 | raise CPDFError(s) 252 | 253 | 254 | def version(): 255 | """Return the version number of the pycpdflib library.""" 256 | v = string_at(libc.pycpdf_version()).decode() 257 | checkerror() 258 | return v 259 | 260 | 261 | def setFast(): 262 | """ Set fast mode. Some operations have a fast mode. The default is 'slow' 263 | mode, which works even on old-fashioned files. For more details, see 264 | section 1.13 of the CPDF manual. This function sets the mode globally. """ 265 | libc.pycpdf_setFast() 266 | checkerror() 267 | 268 | 269 | def setSlow(): 270 | """ Set slow mode. Some operations have a fast mode. The default is 'slow' 271 | mode, which works even on old-fashioned files. For more details, see 272 | section 1.13 of the CPDF manual. This function sets the mode globally. """ 273 | libc.pycpdf_setSlow() 274 | checkerror() 275 | 276 | 277 | def clearError(): 278 | """ Clear the current error state. """ 279 | libc.pycpdf_clearError() 280 | checkerror() 281 | 282 | 283 | def onExit(): 284 | """ A debug function which prints some information about 285 | resource usage. This can be used to detect if PDFs or ranges are being 286 | deallocated properly.""" 287 | libc.pycpdf_onExit() 288 | checkerror() 289 | 290 | # CHAPTER 1. Basics 291 | 292 | 293 | def fromFile(filename, userpw): 294 | """ Load a PDF file from a given file. 295 | Supply a user password (possibly blank) in case the file is encypted. It 296 | won't be decrypted, but sometimes the password is needed just to load the 297 | file.""" 298 | pdf = Pdf(libc.pycpdf_fromFile(str.encode(filename), str.encode(userpw))) 299 | checkerror() 300 | return pdf 301 | 302 | 303 | def fromFileLazy(filename, userpw): 304 | """ Loads a PDF from a file, doing only 305 | minimal parsing. The objects will be read and parsed when they are actually 306 | needed. Use this when the whole file won't be required. Also supply a user 307 | password (possibly blank) in case the file is encypted. It won't be 308 | decrypted, but sometimes the password is needed just to load the file.""" 309 | pdf = Pdf(libc.pycpdf_fromFileLazy( 310 | str.encode(filename), str.encode(userpw))) 311 | checkerror() 312 | return pdf 313 | 314 | 315 | def fromMemory(data, userpw): 316 | """ Load a file from a byte array and the user password (blank if none).""" 317 | pdf = Pdf(libc.pycpdf_fromMemory(data, len(data), str.encode(userpw))) 318 | checkerror() 319 | return pdf 320 | 321 | 322 | def fromMemoryLazy(data, userpw): 323 | """ Load a file from from a byte array and the user password (blank if 324 | none), but lazily like fromFileLazy.""" 325 | pdf = Pdf(libc.pycpdf_fromMemoryLazy(data, len(data), str.encode(userpw))) 326 | checkerror() 327 | return pdf 328 | 329 | 330 | def ptOfCm(i): 331 | """Convert a figure in centimetres to points (72 points to 1 inch).""" 332 | r = libc.pycpdf_ptOfCm(i) 333 | checkerror() 334 | return r 335 | 336 | 337 | def ptOfMm(i): 338 | """Convert a figure in millimetres to points (72 points to 1 inch).""" 339 | r = libc.pycpdf_ptOfMm(i) 340 | checkerror() 341 | return r 342 | 343 | 344 | def ptOfIn(i): 345 | """Convert a figure in inches to points (72 points to 1 inch).""" 346 | r = libc.pycpdf_ptOfIn(i) 347 | checkerror() 348 | return r 349 | 350 | 351 | def cmOfPt(i): 352 | """Convert a figure in points to centimetres (72 points to 1 inch).""" 353 | r = libc.pycpdf_cmOfPt(i) 354 | checkerror() 355 | return r 356 | 357 | 358 | def mmOfPt(i): 359 | """Convert a figure in points to millimetres (72 points to 1 inch).""" 360 | r = libc.pycpdf_mmOfPt(i) 361 | checkerror() 362 | return r 363 | 364 | 365 | def inOfPt(i): 366 | """Convert a figure in points to inches (72 points to 1 inch).""" 367 | r = libc.pycpdf_inOfPt(i) 368 | checkerror() 369 | return r 370 | 371 | 372 | def parsePagespec(pdf, pagespec): 373 | """Parse a page specification such as "1-3,8-end" to a range with reference 374 | to a given PDF (the PDF is supplied so that page ranges which reference 375 | pages which do not exist are rejected).""" 376 | rn = libc.pycpdf_parsePagespec(pdf.pdf, str.encode(pagespec)) 377 | r = list_of_range(rn) 378 | deleteRange(rn) 379 | checkerror() 380 | return r 381 | 382 | 383 | def validatePagespec(pagespec): 384 | """Validate a page specification, returning True or False, so far as is 385 | possible in the absence of the actual document.""" 386 | r = libc.pycpdf_validatePagespec(str.encode(pagespec)) 387 | checkerror() 388 | return r 389 | 390 | 391 | def stringOfPagespec(pdf, r): 392 | """Build a page specification from a page 393 | range. For example, the range containing 1,2,3,6,7,8 in a document of 8 394 | pages might yield "1-3,6-end" """ 395 | rn = range_of_list(r) 396 | r = string_at(libc.pycpdf_stringOfPagespec(pdf.pdf, rn)).decode() 397 | deleteRange(rn) 398 | checkerror() 399 | return r 400 | 401 | 402 | def blankRange(): 403 | """Create a range with no pages in.""" 404 | r = libc.pycpdf_blankRange() 405 | checkerror() 406 | l = list_of_range(r) 407 | deleteRange(r) 408 | return l 409 | 410 | 411 | def pageRange(f, t): 412 | """ Nuild a range from one page to another inclusive. 413 | For example, pageRange(3,7) gives the range 3,4,5,6,7. """ 414 | rn = libc.pycpdf_pageRange(f, t) 415 | r = list_of_range(rn) 416 | deleteRange(rn) 417 | checkerror() 418 | return r 419 | 420 | 421 | def all(pdf): 422 | """The range containing all the pages in a given document.""" 423 | rn = libc.pycpdf_all(pdf.pdf) 424 | r = list_of_range(rn) 425 | deleteRange(rn) 426 | checkerror() 427 | return r 428 | 429 | 430 | def even(r): 431 | """A range which contains just the even pages of another 432 | range.""" 433 | rn = range_of_list(r) 434 | reven = libc.pycpdf_even(rn) 435 | rout = list_of_range(reven) 436 | deleteRange(rn) 437 | deleteRange(reven) 438 | checkerror() 439 | return rout 440 | 441 | 442 | def odd(r): 443 | """A range which contains just the odd pages of another 444 | range.""" 445 | rn = range_of_list(r) 446 | rodd = libc.pycpdf_odd(rn) 447 | rout = list_of_range(rodd) 448 | deleteRange(rn) 449 | deleteRange(rodd) 450 | checkerror() 451 | return rout 452 | 453 | 454 | def rangeUnion(a, b): 455 | """The union of two ranges giving a range containing 456 | the pages in range a and range b.""" 457 | ra = range_of_list(a) 458 | rb = range_of_list(b) 459 | runion = libc.pycpdf_rangeUnion(ra, rb) 460 | rout = list_of_range(runion) 461 | deleteRange(ra) 462 | deleteRange(rb) 463 | deleteRange(runion) 464 | checkerror() 465 | return rout 466 | 467 | 468 | def difference(a, b): 469 | """The difference of two ranges, giving a range 470 | containing all the pages in a except for those which are also in b.""" 471 | ra = range_of_list(a) 472 | rb = range_of_list(b) 473 | rdiff = libc.pycpdf_difference(ra, rb) 474 | rout = list_of_range(rdiff) 475 | deleteRange(ra) 476 | deleteRange(rb) 477 | deleteRange(rdiff) 478 | checkerror() 479 | return rout 480 | 481 | 482 | def removeDuplicates(r): 483 | """Deduplicates a range, returning a new one.""" 484 | rn = range_of_list(r) 485 | rdup = libc.pycpdf_removeDuplicates(rn) 486 | rout = list_of_range(rdup) 487 | deleteRange(rn) 488 | deleteRange(rdup) 489 | checkerror() 490 | return rout 491 | 492 | 493 | def rangeLength(r): 494 | """The number of pages in a range.""" 495 | rn = range_of_list(r) 496 | l = libc.pycpdf_rangeLength(rn) 497 | deleteRange(rn) 498 | checkerror() 499 | return l 500 | 501 | 502 | def rangeGet(r, n): 503 | """Get the page number at position n in a range, where 504 | n runs from 0 to rangeLength - 1.""" 505 | rn = range_of_list(r) 506 | r2 = libc.pycpdf_rangeGet(rn, n) 507 | deleteRange(rn) 508 | checkerror() 509 | return r2 510 | 511 | 512 | def rangeAdd(r, p): 513 | """Add the page to a range, if it is not already 514 | there.""" 515 | rn = range_of_list(r) 516 | radd = libc.pycpdf_rangeAdd(rn, p) 517 | rout = list_of_range(radd) 518 | deleteRange(rn) 519 | deleteRange(radd) 520 | checkerror() 521 | return rout 522 | 523 | 524 | def isInRange(r, p): 525 | """Returns True if the page p is in the range r, False otherwise.""" 526 | rn = range_of_list(r) 527 | r2 = libc.pycpdf_isInRange(rn, p) 528 | deleteRange(rn) 529 | checkerror() 530 | return r2 531 | 532 | 533 | def pages(pdf): 534 | """Return the number of pages in a PDF.""" 535 | r = libc.pycpdf_pages(pdf.pdf) 536 | checkerror() 537 | return r 538 | 539 | 540 | def pagesFast(userpw, filename): 541 | """Return the number of pages in a given 542 | PDF, with given user password. It tries to do this as fast as 543 | possible, without loading the whole file.""" 544 | r = libc.pycpdf_pagesFast(str.encode(userpw), str.encode(filename)) 545 | checkerror() 546 | return r 547 | 548 | 549 | def toFile(pdf, filename, linearize, make_id): 550 | """Write the file to a given filename. If linearize is True, it will be 551 | linearized, if supported by libcpdf. If make_id is True, it will be given a 552 | new ID.""" 553 | libc.pycpdf_toFile(pdf.pdf, str.encode(filename), False, False) 554 | checkerror() 555 | 556 | 557 | def toFileExt(pdf, filename, linearize, make_id, preserve_objstm, 558 | generate_objstm, compress_objstm): 559 | """Write the file to a given filename. If linearize is True, it will be 560 | linearized, if supported by libcpdf. If make_id is True, it will be given a 561 | new ID. If preserve_objstm is True, existing object streams will be 562 | preserved. If generate_objstm is True, object streams will be generated 563 | even if not originally present. If compress_objstm is True, object streams 564 | will be compressed (what we usually want). WARNING: the pdf argument will 565 | be invalid after this call and should not be used again.""" 566 | libc.pycpdf_toFileExt(pdf.pdf, str.encode(filename), linearize, make_id, 567 | preserve_objstm, generate_objstm, compress_objstm) 568 | checkerror() 569 | 570 | 571 | def toMemory(pdf, linearize, make_id): 572 | """Write a file to memory, returning the buffer as a byte array of type 573 | bytes.""" 574 | length = c_int32() 575 | data = libc.pycpdf_toMemory(pdf.pdf, linearize, make_id, byref(length)) 576 | out_data = create_string_buffer(length.value) 577 | memmove(out_data, data, length.value) 578 | libc.pycpdf_toMemoryFree() 579 | checkerror() 580 | return out_data.raw 581 | 582 | 583 | def isEncrypted(pdf): 584 | """Returns True if a documented is encrypted, False otherwise.""" 585 | r = libc.pycpdf_isEncrypted(pdf.pdf) 586 | checkerror() 587 | return r 588 | 589 | 590 | """Permissions.""" 591 | noEdit = 0 592 | noPrint = 1 593 | noCopy = 2 594 | noAnnot = 3 595 | noForms = 4 596 | noExtract = 5 597 | noAssemble = 6 598 | noHqPrint = 7 599 | 600 | """Encryption Methods.""" 601 | pdf40bit = 0 602 | pdf128bit = 1 603 | aes128bitfalse = 2 604 | aes128bittrue = 3 605 | aes256bitfalse = 4 606 | aes256bittrue = 5 607 | aes256bitisofalse = 6 608 | aes256bitisotrue = 7 609 | 610 | 611 | def toFileEncrypted(pdf, method, permissions, ownerpw, userpw, linearize, 612 | makeid, filename): 613 | """Write the file to a given filename encrypted with the given encryption 614 | method, permissions list, and owener and user passwords. If linearize is 615 | True, it will be linearized, if supported by libcpdf. If make_id is True, 616 | it will be given a new ID.""" 617 | c_perms = (c_uint8 * len(permissions))(*permissions) 618 | libc.pycpdf_toFileEncrypted(pdf.pdf, method, c_perms, len(permissions), 619 | str.encode(ownerpw), str.encode(userpw), 620 | linearize, makeid, str.encode(filename)) 621 | checkerror() 622 | 623 | 624 | def toFileEncryptedExt(pdf, method, permissions, ownerpw, userpw, linearize, 625 | makeid, preserve_objstm, generate_objstm, 626 | compress_objstm, filename): 627 | """Write the file to a given filename encrypted with the given encryption 628 | method, permissions list, and owener and user passwords. If linearize is 629 | True, it will be linearized, if supported by libcpdf. If make_id is True, 630 | it will be given a new ID. If preserve_objstm is True, existing object 631 | streams will be preserved. If generate_objstm is True, object streams will 632 | be generated even if not originally present. If compress_objstm is True, 633 | object streams will be compressed (what we usually want). WARNING: the pdf 634 | argument will be invalid after this call and should not be used again.""" 635 | c_perms = (c_uint8 * len(permissions))(*permissions) 636 | libc.pycpdf_toFileEncryptedExt(pdf.pdf, method, c_perms, len(permissions), 637 | str.encode(ownerpw), str.encode(userpw), 638 | linearize, makeid, preserve_objstm, 639 | generate_objstm, compress_objstm, 640 | str.encode(filename)) 641 | checkerror() 642 | 643 | 644 | def decryptPdf(pdf, userpw): 645 | """Attempts to decrypt a PDF using the given user password. An exception is 646 | raised in the event of a bad password.""" 647 | libc.pycpdf_decryptPdf(pdf.pdf, str.encode(userpw)) 648 | checkerror() 649 | 650 | 651 | def decryptPdfOwner(pdf, ownerpw): 652 | """Attempts to decrypt a PDF using the given owner password. An exception 653 | is raised in the event of a bad password.""" 654 | libc.pycpdf_decryptPdfOwner(pdf.pdf, str.encode(ownerpw)) 655 | checkerror() 656 | 657 | 658 | def hasPermission(pdf, perm): 659 | """Returns True if the given permission (restriction) is present.""" 660 | r = libc.pycpdf_hasPermission(pdf.pdf, perm) 661 | checkerror() 662 | return r 663 | 664 | 665 | def encryptionKind(pdf): 666 | """Return the encryption method currently in use on a document.""" 667 | r = libc.pycpdf_encryptionKind(pdf.pdf) 668 | checkerror() 669 | return r 670 | 671 | # CHAPTER 2. Merging and Splitting 672 | 673 | 674 | def mergeSimple(pdfs): 675 | """Given a list of PDFs, merges the documents into a new PDF, which is 676 | returned.""" 677 | raw_pdfs = list(map(lambda p: p.pdf, pdfs)) 678 | c_pdfs = (c_int * len(pdfs))(*raw_pdfs) 679 | r = Pdf(libc.pycpdf_mergeSimple(c_pdfs, len(pdfs))) 680 | checkerror() 681 | return r 682 | 683 | 684 | def merge(pdfs, retain_numbering, remove_duplicate_fonts): 685 | """Merges the list of PDFs. If retain_numbering is True page labels are not 686 | rewritten. If remove_duplicate_fonts is True, duplicate fonts are merged. 687 | This is useful when the source documents for merging originate from the 688 | same source.""" 689 | raw_pdfs = map(lambda p: p.pdf, pdfs) 690 | c_pdfs = (c_int * len(pdfs))(*raw_pdfs) 691 | r = Pdf(libc.pycpdf_merge(c_pdfs, len(pdfs), 692 | retain_numbering, remove_duplicate_fonts)) 693 | checkerror() 694 | return r 695 | 696 | 697 | def mergeSame(pdfs, retain_numbering, remove_duplicate_fonts, ranges): 698 | """The same as merge, except that it has an additional argument 699 | - a list of page ranges. This is used to select the pages to pick from 700 | each PDF. This avoids duplication of information when multiple discrete 701 | parts of a single source PDF are included.""" 702 | ranges = list(map(range_of_list, ranges)) 703 | raw_pdfs = map(lambda p: p.pdf, pdfs) 704 | c_pdfs = (c_int * len(pdfs))(*raw_pdfs) 705 | c_ranges = (c_int * len(ranges))(*ranges) 706 | r = Pdf(libc.pycpdf_mergeSame(c_pdfs, len(pdfs), 707 | retain_numbering, remove_duplicate_fonts, c_ranges)) 708 | for x in ranges: 709 | deleteRange(x) 710 | checkerror() 711 | return r 712 | 713 | 714 | def selectPages(pdf, r): 715 | """ Returns a new document which just those pages in the page range.""" 716 | rn = range_of_list(r) 717 | r = Pdf(libc.pycpdf_selectPages(pdf.pdf, rn)) 718 | deleteRange(rn) 719 | checkerror() 720 | return r 721 | 722 | # CHAPTER 3. Pages 723 | 724 | 725 | def scalePages(pdf, r, sx, sy): 726 | """Scale the page dimensions and content of the given range of pages by 727 | the given scale (sx, sy), about (0, 0). Other boxes (crop etc. are altered 728 | as appropriate).""" 729 | r = range_of_list(r) 730 | libc.pycpdf_scalePages(pdf.pdf, r, sx, sy) 731 | deleteRange(r) 732 | checkerror() 733 | 734 | 735 | def scaleToFit(pdf, r, w, h, scale_to_fit_scale): 736 | """Scales the pages in the range to fit new page dimensions (w and h) 737 | multiplied by scale_to_fit_scale (typically 1.0). Other boxes (crop etc.) 738 | are altered as appropriate.""" 739 | r = range_of_list(r) 740 | libc.pycpdf_scaleToFit(pdf.pdf, r, w, h, scale_to_fit_scale) 741 | deleteRange(r) 742 | checkerror() 743 | 744 | 745 | """Paper sizes.""" 746 | a0portrait = 0 747 | a1portrait = 1 748 | a2portrait = 2 749 | a3portrait = 3 750 | a4portrait = 4 751 | a5portrait = 5 752 | a0landscape = 6 753 | a1landscape = 7 754 | a2landscape = 8 755 | a3landscape = 9 756 | a4landscape = 10 757 | a5landscape = 11 758 | usletterportrait = 12 759 | usletterlandscape = 13 760 | uslegalportrait = 14 761 | uslegallandscape = 15 762 | 763 | 764 | def scaleToFitPaper(pdf, r, papersize, scale_to_fit_scale): 765 | """Scales the given pages to fit the given page size, possibly multiplied 766 | by scale_to_fit_scale (typically 1.0)""" 767 | r = range_of_list(r) 768 | libc.pycpdf_scaleToFitPaper(pdf.pdf, r, papersize, scale_to_fit_scale) 769 | deleteRange(r) 770 | checkerror() 771 | 772 | 773 | """Positions with two numbers in a tuple e.g (posLeft, 10.0, 20.0):""" 774 | posCentre = 0 775 | posLeft = 1 776 | posRight = 2 777 | """Positions with one number in a tuple e.g (top, 5.0):""" 778 | top = 3 779 | topLeft = 4 780 | topRight = 5 781 | left = 6 782 | bottomLeft = 7 783 | bottomRight = 8 784 | right = 9 785 | """Positions with no numbers e.g diagonal:""" 786 | diagonal = 10 787 | reverseDiagonal = 11 788 | 789 | 790 | def tripleOfPosition(p): 791 | if p == diagonal: 792 | return (p, 0.0, 0.0) 793 | if p == reverseDiagonal: 794 | return (p, 0.0, 0.0) 795 | if p[0] == top: 796 | return (p[0], p[1], 0.0) 797 | if p[0] == topLeft: 798 | return (p[0], p[1], 0.0) 799 | if p[0] == topRight: 800 | return (p[0], p[1], 0.0) 801 | if p[0] == left: 802 | return (p[0], p[1], 0.0) 803 | if p[0] == bottomLeft: 804 | return (p[0], p[1], 0.0) 805 | if p[0] == bottomRight: 806 | return (p[0], p[1], 0.0) 807 | if p[0] == right: 808 | return (p[0], p[1], 0.0) 809 | if p[0] == posCentre: 810 | return (p[0], p[1], p[2]) 811 | if p[0] == posLeft: 812 | return (p[0], p[1], p[2]) 813 | if p[0] == posRight: 814 | return (p[0], p[1], p[2]) 815 | 816 | 817 | def scaleContents(pdf, r, pos, scale): 818 | """Scales the contents of the pages in the range about the point given by 819 | the position, by the scale given.""" 820 | r = range_of_list(r) 821 | a, b, c = tripleOfPosition(pos) 822 | libc.pycpdf_scaleContents(pdf.pdf, r, a, b, c, scale) 823 | deleteRange(r) 824 | checkerror() 825 | 826 | 827 | def shiftContents(pdf, r, dx, dy): 828 | """Shift the content of the pages in the range by (dx, dy).""" 829 | r = range_of_list(r) 830 | libc.pycpdf_shiftContents(pdf.pdf, r, dx, dy) 831 | deleteRange(r) 832 | checkerror() 833 | 834 | 835 | def rotate(pdf, r, rotation): 836 | """Change the viewing rotation of the pages in the range to an 837 | absolute value. Appropriate rotations are 0, 90, 180, 270.""" 838 | r = range_of_list(r) 839 | libc.pycpdf_rotate(pdf.pdf, r, rotation) 840 | deleteRange(r) 841 | checkerror() 842 | 843 | 844 | def rotateBy(pdf, r, rotation): 845 | """Change the viewing rotation of the pages in the range by a 846 | given number of degrees. Appropriate values are 90, 180, 270.""" 847 | r = range_of_list(r) 848 | libc.pycpdf_rotateBy(pdf.pdf, r, rotation) 849 | deleteRange(r) 850 | checkerror() 851 | 852 | 853 | def rotateContents(pdf, r, rotation): 854 | """Rotate the content about the centre 855 | of the page by the given number of degrees, in a clockwise direction.""" 856 | r = range_of_list(r) 857 | libc.pycpdf_rotateContents(pdf.pdf, r, rotation) 858 | deleteRange(r) 859 | checkerror() 860 | 861 | 862 | def upright(pdf, r): 863 | """Change the viewing rotation of the pages in the range, counter-rotating 864 | the dimensions and content such that there is no visual change.""" 865 | r = range_of_list(r) 866 | libc.pycpdf_upright(pdf.pdf, r) 867 | deleteRange(r) 868 | checkerror() 869 | 870 | 871 | def hFlip(pdf, r): 872 | """Flip horizontally the pages in the range.""" 873 | r = range_of_list(r) 874 | libc.pycpdf_hFlip(pdf.pdf, r) 875 | deleteRange(r) 876 | checkerror() 877 | 878 | 879 | def vFlip(pdf, r): 880 | """Flip vertically the pages in the range.""" 881 | r = range_of_list(r) 882 | libc.pycpdf_vFlip(pdf.pdf, r) 883 | deleteRange(r) 884 | checkerror() 885 | 886 | 887 | def crop(pdf, r, x, y, w, h): 888 | """Crop a page to the box defined by (x, y, w, h), replacing any existing 889 | crop box.""" 890 | r = range_of_list(r) 891 | libc.pycpdf_crop(pdf.pdf, r, x, y, w, h) 892 | deleteRange(r) 893 | checkerror() 894 | 895 | 896 | def removeCrop(pdf, r): 897 | """Remove any crop box from pages in the range.""" 898 | r = range_of_list(r) 899 | libc.pycpdf_removeCrop(pdf.pdf, r) 900 | deleteRange(r) 901 | checkerror() 902 | 903 | 904 | def removeTrim(pdf, r): 905 | """Remove any trim box from pages in the range.""" 906 | r = range_of_list(r) 907 | libc.pycpdf_removeTrim(pdf.pdf, r) 908 | deleteRange(r) 909 | checkerror() 910 | 911 | 912 | def removeArt(pdf, r): 913 | """Remove any art box from pages in the range.""" 914 | r = range_of_list(r) 915 | libc.pycpdf_removeArt(pdf.pdf, r) 916 | deleteRange(r) 917 | checkerror() 918 | 919 | 920 | def removeBleed(pdf, r): 921 | """Remove any bleed box from pages in the range.""" 922 | r = range_of_list(r) 923 | libc.pycpdf_removeBleed(pdf.pdf, r) 924 | deleteRange(r) 925 | checkerror() 926 | 927 | 928 | def trimMarks(pdf, r): 929 | """Add trim marks to the given pages, if the trimbox exists.""" 930 | r = range_of_list(r) 931 | libc.pycpdf_trimMarks(pdf.pdf, r) 932 | deleteRange(r) 933 | checkerror() 934 | 935 | 936 | def showBoxes(pdf, r): 937 | """Show the boxes on the given pages, for debug.""" 938 | r = range_of_list(r) 939 | libc.pycpdf_showBoxes(pdf.pdf, r) 940 | deleteRange(r) 941 | checkerror() 942 | 943 | 944 | def hardBox(pdf, r, boxname): 945 | """Make a given box a 'hard box' i.e clip it explicitly. Boxname could be, 946 | for example "/TrimBox".""" 947 | r = range_of_list(r) 948 | libc.pycpdf_hardBox(pdf.pdf, r, str.encode(boxname)) 949 | deleteRange(r) 950 | checkerror() 951 | 952 | # CHAPTER 4. Encryption 953 | 954 | # Encryption covered under Chapter 1 in pycpdflib 955 | 956 | # CHAPTER 5. Compression 957 | 958 | 959 | def compress(pdf): 960 | """Compress any uncompressed streams in the given PDF using the Flate 961 | algorithm.""" 962 | libc.pycpdf_compress(pdf.pdf) 963 | checkerror() 964 | 965 | 966 | def decompress(pdf): 967 | """Decompress any streams in the given PDF, so long as the compression 968 | method is supported.""" 969 | libc.pycpdf_decompress(pdf.pdf) 970 | checkerror() 971 | 972 | 973 | def squeezeInMemory(pdf): 974 | """squeezeToMemory(pdf) squeezes a pdf in memory. Squeezing is a lossless 975 | compression method which works be rearrangement of a PDFs internal 976 | structure.""" 977 | libc.pycpdf_squeezeInMemory(pdf.pdf) 978 | checkerror() 979 | 980 | # CHAPTER 6. Bookmarks 981 | 982 | 983 | def getBookmarks(pdf): 984 | """Get the bookmarks for a PDF as a list of tuples of the form: 985 | (level : int, page : int, text : string, openstatus : bool)""" 986 | l = [] 987 | libc.pycpdf_startGetBookmarkInfo(pdf.pdf) 988 | n = libc.pycpdf_numberBookmarks() 989 | for x in range(n): 990 | level = libc.pycpdf_getBookmarkLevel(x) 991 | page = libc.pycpdf_getBookmarkPage(pdf.pdf, x) 992 | text = string_at(libc.pycpdf_getBookmarkText(x)).decode() 993 | openStatus = libc.pycpdf_getBookmarkOpenStatus(x) 994 | l.append((level, page, text, openStatus)) 995 | libc.pycpdf_endGetBookmarkInfo(pdf.pdf) 996 | checkerror() 997 | return l 998 | 999 | 1000 | def setBookmarks(pdf, marks): 1001 | """Set the bookmarks for a PDF as a list of tuples of the form: 1002 | (level : int, page : int, text : string, openstatus : bool)""" 1003 | libc.pycpdf_startSetBookmarkInfo(len(marks)) 1004 | for n, m in enumerate(marks): 1005 | level, page, text, openStatus = m 1006 | libc.pycpdf_setBookmarkLevel(n, level) 1007 | libc.pycpdf_setBookmarkPage(pdf.pdf, n, page) 1008 | libc.pycpdf_setBookmarkOpenStatus(n, openStatus) 1009 | libc.pycpdf_setBookmarkText(n, str.encode(text)) 1010 | libc.pycpdf_endSetBookmarkInfo(pdf.pdf) 1011 | checkerror() 1012 | 1013 | 1014 | def getBookmarksJSON(pdf): 1015 | """Get the bookmarks in JSON format.""" 1016 | length = c_int32() 1017 | data = libc.pycpdf_getBookmarksJSON(pdf.pdf, byref(length)) 1018 | out_data = create_string_buffer(length.value) 1019 | memmove(out_data, data, length.value) 1020 | libc.pycpdf_getBookmarksJSONFree() 1021 | checkerror() 1022 | return out_data.raw 1023 | 1024 | 1025 | def setBookmarksJSON(pdf, data): 1026 | """setBookmarksJSON(pdf, data) sets the bookmarks from JSON bookmark data.""" 1027 | libc.pycpdf_setBookmarksJSON(pdf.pdf, data, len(data)) 1028 | checkerror() 1029 | return 1030 | 1031 | 1032 | def tableOfContents(pdf, font, fontsize, title, bookmark): 1033 | """tableOfContents(pdf, font, fontsize, title, bookmark) typesets a table 1034 | of contents from existing bookmarks and prepends it to the document. If 1035 | bookmark is set, the table of contents gets its own bookmark.""" 1036 | pdf = libc.pycpdf_tableOfContents( 1037 | pdf.pdf, font, fontsize, str.encode(title), bookmark) 1038 | checkerror() 1039 | return pdf 1040 | 1041 | # CHAPTER 7. Presentations 1042 | 1043 | # Not included in the library version 1044 | 1045 | # CHAPTER 8. Logos, Watermarks and Stamps 1046 | 1047 | 1048 | def stampOn(pdf, pdf2, r): 1049 | """Stamps pdf on top of all the pages in pdf2 which are in the range. The 1050 | stamp is placed with its origin at the origin of the target document.""" 1051 | r = range_of_list(r) 1052 | libc.pycpdf_stampOn(pdf.pdf, pdf2.pdf, r) 1053 | deleteRange(r) 1054 | checkerror() 1055 | 1056 | 1057 | def stampUnder(pdf, pdf2, r): 1058 | """Stamps pdf under under all the pages in pdf2 which are in the range. The 1059 | stamp is placed with its origin at the origin of the target document.""" 1060 | r = range_of_list(r) 1061 | libc.pycpdf_stampUnder(pdf.pdf, pdf2.pdf, r) 1062 | deleteRange(r) 1063 | checkerror() 1064 | 1065 | 1066 | def stampExtended(pdf, pdf2, r, isover, scale_stamp_to_fit, pos, 1067 | relative_to_cropbox): 1068 | """A stamping function with extra features: 1069 | 1070 | - isover True, pdf goes over pdf2, isover False, pdf goes under pdf2 1071 | - scale_stamp_to_fit scales the stamp to fit the page 1072 | - pos gives the position to put the stamp 1073 | - relative_to_cropbox: if True, pos is relative to crop box not media box""" 1074 | r = range_of_list(r) 1075 | a, b, c = tripleOfPosition(pos) 1076 | libc.pycpdf_stampExtended(pdf.pdf, pdf2.pdf, r, isover, scale_stamp_to_fit, 1077 | a, b, c, relative_to_cropbox) 1078 | deleteRange(r) 1079 | checkerror() 1080 | 1081 | 1082 | def combinePages(pdf, pdf2): 1083 | """Combines the PDFs page-by-page, putting each page of pdf2 over each page 1084 | of pdf.""" 1085 | output = libc.pycpdf_combinePages(pdf.pdf, pdf2.pdf) 1086 | checkerror() 1087 | return Pdf(output) 1088 | 1089 | 1090 | """Fonts.""" 1091 | timesRoman = 0 1092 | timesBold = 1 1093 | timesItalic = 2 1094 | timesBoldItalic = 3 1095 | helvetica = 4 1096 | helveticaBold = 5 1097 | helveticaOblique = 6 1098 | helveticaBoldOblique = 7 1099 | courier = 8 1100 | courierBold = 9 1101 | courierOblique = 10 1102 | courierBoldOblique = 11 1103 | 1104 | 1105 | """Justifications.""" 1106 | leftJustify = 0 1107 | centreJustify = 1 1108 | rightJustify = 2 1109 | 1110 | 1111 | def addText(metrics, pdf, r, text, p, line_spacing, bates, font, size, red, 1112 | green, blue, underneath, relative_to_cropbox, outline, opacity, 1113 | justification, midline, topline, filename, line_width, 1114 | embed_fonts): 1115 | """Adding text. Adds text to a PDF, if the characters exist in the font. 1116 | 1117 | * metrics: If True, don't actually add text but collect metrics. 1118 | * pdf: Document 1119 | * r: Page Range 1120 | * text: The text to add 1121 | * p: Position to add text at 1122 | * line_spacing: Linespacing, 1.0 = normal 1123 | * bates: Starting Bates number 1124 | * font: Font 1125 | * size: Font size in points 1126 | * red: Red component of colour, 0.0 - 1.0 1127 | * green: Green component of colour, 0.0 - 1.0 1128 | * blue: Blue component of colour, 0.0 - 1.0 1129 | * underneath: If True, text is added underneath rather than on top 1130 | * relative_to_cropbox: If True, position is relative to crop box not 1131 | media box 1132 | * outline: If True, text is outline rather than filled 1133 | * opacity: Opacity, 1.0 = opaque, 0.0 = wholly transparent 1134 | * justification: Justification 1135 | * midline: If True, position is relative to midline of text, not 1136 | baseline 1137 | * topline: If True, position is relative to topline of text, not 1138 | baseline 1139 | * filename: filename that this document was read from (optional) 1140 | * line_width: line width 1141 | * embed_fonts: embed fonts 1142 | 1143 | Special codes 1144 | 1145 | * %Page Page number in arabic notation (1, 2, 3...) 1146 | * %roman Page number in lower-case roman notation (i, ii, iii...) 1147 | * %Roman Page number in upper-case roman notation (I, II, III...) 1148 | * %EndPage Last page of document in arabic notation 1149 | * %Label The page label of the page 1150 | * %EndLabel The page label of the last page 1151 | * %filename The full file name of the input document 1152 | * %a Abbreviated weekday name (Sun, Mon etc.) 1153 | * %A Full weekday name (Sunday, Monday etc.) 1154 | * %b Abbreviated month name (Jan, Feb etc.) 1155 | * %B Full month name (January, February etc.) 1156 | * %d Day of the month (01-31) 1157 | * %e Day of the month (1-31) 1158 | * %H Hour in 24-hour clock (00-23) 1159 | * %I Hour in 12-hour clock (01-12) 1160 | * %j Day of the year (001-366) 1161 | * %m Month of the year (01-12) 1162 | * %M Minute of the hour (00-59) 1163 | * %p "a.m" or "p.m" 1164 | * %S Second of the minute (00-61) 1165 | * %T Same as %H:%M:%S 1166 | * %u Weekday (1-7, 1 = Monday) 1167 | * %w Weekday (0-6, 0 = Monday) 1168 | * %Y Year (0000-9999) 1169 | * %% The % character""" 1170 | a, b, c = tripleOfPosition(p) 1171 | r = range_of_list(r) 1172 | libc.pycpdf_addText(metrics, pdf.pdf, r, str.encode(text), a, b, c, 1173 | line_spacing, bates, font, size, red, green, blue, 1174 | underneath, relative_to_cropbox, outline, opacity, 1175 | justification, midline, topline, str.encode(filename), 1176 | line_width, embed_fonts) 1177 | deleteRange(r) 1178 | checkerror() 1179 | 1180 | 1181 | def addTextSimple(pdf, r, text, p, font, size): 1182 | """like addText, but with most parameters default 1183 | 1184 | * pdf = the document 1185 | * r = the range 1186 | * text = the text 1187 | * p = the position 1188 | * font = the font 1189 | * size = the font size""" 1190 | a, b, c = tripleOfPosition(p) 1191 | r = range_of_list(r) 1192 | libc.pycpdf_addTextSimple( 1193 | pdf.pdf, r, str.encode(text), a, b, c, font, size) 1194 | deleteRange(r) 1195 | checkerror() 1196 | 1197 | 1198 | def removeText(pdf, r): 1199 | """Remove any text added by libcpdf from the given pages.""" 1200 | r = range_of_list(r) 1201 | libc.pycpdf_removeText(pdf.pdf, r) 1202 | deleteRange(r) 1203 | checkerror() 1204 | 1205 | 1206 | def textWidth(font, string): 1207 | """Return the width of a given string in the given font in thousandths of a 1208 | point.""" 1209 | r = libc.pycpdf_textWidth(font, str.encode(string)) 1210 | checkerror() 1211 | return r 1212 | 1213 | 1214 | def addContent(content, before, pdf, r): 1215 | """Add page content before (if True) or after (if False) the existing 1216 | content to pages in the given range in the given PDF. Warning: this a low 1217 | level function requiring understanding of the PDF format.""" 1218 | r = range_of_list(r) 1219 | libc.pycpdf_addContent(str.encode(content), before, pdf.pdf, r) 1220 | deleteRange(r) 1221 | checkerror() 1222 | 1223 | 1224 | def stampAsXObject(pdf, r, stamp_pdf): 1225 | """Stamps stamp_pdf onto the pages in the given range in pdf as a shared 1226 | Form XObject. The name of the newly-created XObject is returned, for use 1227 | with addContent. """ 1228 | r = range_of_list(r) 1229 | r2 = string_at(libc.pycpdf_stampAsXObject( 1230 | pdf.pdf, r, stamp_pdf.pdf)).decode() 1231 | deleteRange(r) 1232 | checkerror() 1233 | return r2 1234 | 1235 | 1236 | # CHAPTER 9. Multipage facilities 1237 | 1238 | def twoUp(pdf): 1239 | """Impose a document two up by retaining the existing page 1240 | size, scaling pages down.""" 1241 | libc.pycpdf_twoUp(pdf.pdf) 1242 | checkerror() 1243 | 1244 | 1245 | def twoUpStack(pdf): 1246 | """Impose a document two up by doubling the page size, 1247 | to fit two pages on one.""" 1248 | libc.pycpdf_twoUpStack(pdf.pdf) 1249 | checkerror() 1250 | 1251 | 1252 | def impose(pdf, x, y, fit, columns, rtl, btt, center, margin, spacing, linewidth): 1253 | """impose(pdf, x, y, fit, columns, rtl, btt, center, margin, spacing, 1254 | linewidth) imposes a PDF. There are two modes: imposing x * y, or imposing 1255 | to fit a page of size x * y. This is controlled by fit. Columns imposes by 1256 | columns rather than rows. rtl is right-to-left, btt bottom-to-top. Center 1257 | is unused for now. Margin is the margin around the output, spacing the 1258 | spacing between imposed inputs.""" 1259 | libc.pycpdf_impose(pdf.pdf, x, y, fit, columns, rtl, 1260 | btt, center, margin, spacing, linewidth) 1261 | checkerror() 1262 | 1263 | 1264 | def padBefore(pdf, r): 1265 | """Adds a blank page before each page in the given range.""" 1266 | r = range_of_list(r) 1267 | libc.pycpdf_padBefore(pdf.pdf, r) 1268 | deleteRange(r) 1269 | checkerror() 1270 | 1271 | 1272 | def padAfter(pdf, r): 1273 | """Adds a blank page after each page in the given range.""" 1274 | r = range_of_list(r) 1275 | libc.pycpdf_padAfter(pdf.pdf, r) 1276 | deleteRange(r) 1277 | checkerror() 1278 | 1279 | 1280 | def padEvery(pdf, n): 1281 | """Adds a blank page after every n pages.""" 1282 | libc.pycpdf_padEvery(pdf.pdf, n) 1283 | checkerror() 1284 | 1285 | 1286 | def padMultiple(pdf, n): 1287 | """Adds pages at the end to pad the file to a multiple of n pages in 1288 | length.""" 1289 | libc.pycpdf_padMultiple(pdf.pdf, n) 1290 | checkerror() 1291 | 1292 | 1293 | def padMultipleBefore(pdf, n): 1294 | """Adds pages at the beginning to pad the file to a 1295 | multiple of n pages in length.""" 1296 | libc.pycpdf_padMultipleBefore(pdf.pdf, n) 1297 | checkerror() 1298 | 1299 | # CHAPTER 10. Annotations 1300 | 1301 | 1302 | def annotationsJSON(pdf): 1303 | """Get the annotations in JSON format.""" 1304 | length = c_int32() 1305 | data = libc.pycpdf_annotationsJSON(pdf.pdf, byref(length)) 1306 | out_data = create_string_buffer(length.value) 1307 | memmove(out_data, data, length.value) 1308 | libc.pycpdf_annotationsJSONFree() 1309 | checkerror() 1310 | return out_data.raw 1311 | 1312 | 1313 | # CHAPTER 11. Document Information and Metadata 1314 | 1315 | 1316 | def isLinearized(filename): 1317 | """Finds out if a document is linearized as quickly 1318 | as possible without loading it.""" 1319 | r = libc.pycpdf_isLinearized(str.encode(filename)) 1320 | checkerror() 1321 | return r 1322 | 1323 | 1324 | def getVersion(pdf): 1325 | """Return the minor version number of a document.""" 1326 | r = libc.pycpdf_getVersion(pdf.pdf) 1327 | checkerror() 1328 | return r 1329 | 1330 | 1331 | def getMajorVersion(pdf): 1332 | """Return the minor version number of a document.""" 1333 | r = libc.pycpdf_getMajorVersion(pdf.pdf) 1334 | checkerror() 1335 | return r 1336 | 1337 | 1338 | def getTitle(pdf): 1339 | """Return the title of a document.""" 1340 | r = string_at(libc.pycpdf_getTitle(pdf.pdf)).decode() 1341 | checkerror() 1342 | return r 1343 | 1344 | 1345 | def getAuthor(pdf): 1346 | """Return the subject of a document.""" 1347 | r = string_at(libc.pycpdf_getAuthor(pdf.pdf)).decode() 1348 | checkerror() 1349 | return r 1350 | 1351 | 1352 | def getSubject(pdf): 1353 | """Return the subject of a document.""" 1354 | r = string_at(libc.pycpdf_getSubject(pdf.pdf)).decode() 1355 | checkerror() 1356 | return r 1357 | 1358 | 1359 | def getKeywords(pdf): 1360 | """Return the keywords of a document.""" 1361 | r = string_at(libc.pycpdf_getKeywords(pdf.pdf)).decode() 1362 | checkerror() 1363 | return r 1364 | 1365 | 1366 | def getCreator(pdf): 1367 | """Return the creator of a document.""" 1368 | r = string_at(libc.pycpdf_getCreator(pdf.pdf)).decode() 1369 | checkerror() 1370 | return r 1371 | 1372 | 1373 | def getProducer(pdf): 1374 | """Return the producer of a document.""" 1375 | r = string_at(libc.pycpdf_getProducer(pdf.pdf)).decode() 1376 | checkerror() 1377 | return r 1378 | 1379 | 1380 | def getCreationDate(pdf): 1381 | """Return the creation date of a document.""" 1382 | r = string_at(libc.pycpdf_getCreationDate(pdf.pdf)).decode() 1383 | checkerror() 1384 | return r 1385 | 1386 | 1387 | def getModificationDate(pdf): 1388 | """Return the modification date of a document.""" 1389 | r = string_at(libc.pycpdf_getModificationDate(pdf.pdf)).decode() 1390 | checkerror() 1391 | return r 1392 | 1393 | 1394 | def getTitleXMP(pdf): 1395 | """Return the XMP title of a document.""" 1396 | r = string_at(libc.pycpdf_getTitleXMP(pdf.pdf)).decode() 1397 | checkerror() 1398 | return r 1399 | 1400 | 1401 | def getAuthorXMP(pdf): 1402 | """Return the XMP author of a document.""" 1403 | r = string_at(libc.pycpdf_getAuthorXMP(pdf.pdf)).decode() 1404 | checkerror() 1405 | return r 1406 | 1407 | 1408 | def getSubjectXMP(pdf): 1409 | """Return the XMP subject of a document.""" 1410 | r = string_at(libc.pycpdf_getSubjectXMP(pdf.pdf)).decode() 1411 | checkerror() 1412 | return r 1413 | 1414 | 1415 | def getKeywordsXMP(pdf): 1416 | """Return the XMP keywords of a document.""" 1417 | r = string_at(libc.pycpdf_getKeywordsXMP(pdf.pdf)).decode() 1418 | checkerror() 1419 | return r 1420 | 1421 | 1422 | def getCreatorXMP(pdf): 1423 | """Return the XMP creator of a document.""" 1424 | r = string_at(libc.pycpdf_getCreatorXMP(pdf.pdf)).decode() 1425 | checkerror() 1426 | return r 1427 | 1428 | 1429 | def getProducerXMP(pdf): 1430 | """Return the XMP producer of a document.""" 1431 | r = string_at(libc.pycpdf_getProducerXMP(pdf.pdf)).decode() 1432 | checkerror() 1433 | return r 1434 | 1435 | 1436 | def getCreationDateXMP(pdf): 1437 | """Return the XMP creation date of a document.""" 1438 | r = string_at(libc.pycpdf_getCreationDateXMP(pdf.pdf)).decode() 1439 | checkerror() 1440 | return r 1441 | 1442 | 1443 | def getModificationDateXMP(pdf): 1444 | """Return the XMP modification date of a document.""" 1445 | r = string_at(libc.pycpdf_getModificationDateXMP(pdf.pdf)).decode() 1446 | checkerror() 1447 | return r 1448 | 1449 | 1450 | def setTitle(pdf, s): 1451 | """Set the title of a document.""" 1452 | libc.pycpdf_setTitle(pdf.pdf, str.encode(s)) 1453 | checkerror() 1454 | return 1455 | 1456 | 1457 | def setAuthor(pdf, s): 1458 | """Set the author of a document.""" 1459 | libc.pycpdf_setAuthor(pdf.pdf, str.encode(s)) 1460 | checkerror() 1461 | return 1462 | 1463 | 1464 | def setSubject(pdf, s): 1465 | """Set the subject of a document.""" 1466 | libc.pycpdf_setSubject(pdf.pdf, str.encode(s)) 1467 | checkerror() 1468 | return 1469 | 1470 | 1471 | def setKeywords(pdf, s): 1472 | """Set the keywords of a document.""" 1473 | libc.pycpdf_setKeywords(pdf.pdf, str.encode(s)) 1474 | checkerror() 1475 | return 1476 | 1477 | 1478 | def setCreator(pdf, s): 1479 | """Set the creator of a document.""" 1480 | libc.pycpdf_setCreator(pdf.pdf, str.encode(s)) 1481 | checkerror() 1482 | return 1483 | 1484 | 1485 | def setProducer(pdf, s): 1486 | """Set the producer of a document.""" 1487 | libc.pycpdf_setProducer(pdf.pdf, str.encode(s)) 1488 | checkerror() 1489 | return 1490 | 1491 | 1492 | def setCreationDate(pdf, s): 1493 | """Set the creation date of a document.""" 1494 | libc.pycpdf_setCreationDate(pdf.pdf, str.encode(s)) 1495 | checkerror() 1496 | return 1497 | 1498 | 1499 | def setModificationDate(pdf, s): 1500 | """Set the modifcation date of a document.""" 1501 | libc.pycpdf_setModificationDate(pdf.pdf, str.encode(s)) 1502 | checkerror() 1503 | return 1504 | 1505 | 1506 | def setTitleXMP(pdf, s): 1507 | """Set the XMP title of a document.""" 1508 | libc.pycpdf_setTitleXMP(pdf.pdf, str.encode(s)) 1509 | checkerror() 1510 | return 1511 | 1512 | 1513 | def setAuthorXMP(pdf, s): 1514 | """Set the XMP author of a document.""" 1515 | libc.pycpdf_setAuthorXMP(pdf.pdf, str.encode(s)) 1516 | checkerror() 1517 | return 1518 | 1519 | 1520 | def setSubjectXMP(pdf, s): 1521 | """Set the XMP subject of a document.""" 1522 | libc.pycpdf_setSubjectXMP(pdf.pdf, str.encode(s)) 1523 | checkerror() 1524 | return 1525 | 1526 | 1527 | def setKeywordsXMP(pdf, s): 1528 | """Set the XMP keywords of a document.""" 1529 | libc.pycpdf_setKeywordsXMP(pdf.pdf, str.encode(s)) 1530 | checkerror() 1531 | return 1532 | 1533 | 1534 | def setCreatorXMP(pdf, s): 1535 | """Set the XMP creator of a document.""" 1536 | libc.pycpdf_setCreatorXMP(pdf.pdf, str.encode(s)) 1537 | checkerror() 1538 | return 1539 | 1540 | 1541 | def setProducerXMP(pdf, s): 1542 | """Set the XMP producer of a document.""" 1543 | libc.pycpdf_setProducerXMP(pdf.pdf, str.encode(s)) 1544 | checkerror() 1545 | return 1546 | 1547 | 1548 | def setCreationDateXMP(pdf, s): 1549 | """Set the XMP creation date of a document.""" 1550 | libc.pycpdf_setCreationDateXMP(pdf.pdf, str.encode(s)) 1551 | checkerror() 1552 | return 1553 | 1554 | 1555 | def setModificationDateXMP(pdf, s): 1556 | """Set the XMP modification date of a document.""" 1557 | libc.pycpdf_setModificationDateXMP(pdf.pdf, str.encode(s)) 1558 | checkerror() 1559 | return 1560 | 1561 | 1562 | def getDateComponents(string): 1563 | """Return the components (year, month, day, hour, minute, second, 1564 | hour_offset, minute_offset) from a PDF date string. 1565 | 1566 | Month 1-31, day 1-31, hours (0-23), minutes (0-59), seconds 1567 | (0-59), hour_offset is the offset from UT in hours (-23 to 23); 1568 | minute_offset is the offset from UT in minutes (-59 to 59).""" 1569 | year = c_int(0) 1570 | month = c_int(0) 1571 | day = c_int(0) 1572 | hour = c_int(0) 1573 | minute = c_int(0) 1574 | second = c_int(0) 1575 | hour_offset = c_int(0) 1576 | minute_offset = c_int(0) 1577 | libc.pycpdf_getDateComponents(str.encode(string), byref(year), 1578 | byref(month), byref(day), byref(hour), 1579 | byref(minute), byref(second), 1580 | byref(hour_offset), byref(minute_offset)) 1581 | checkerror() 1582 | return (year.value, month.value, day.value, hour.value, minute.value, 1583 | second.value, hour_offset.value, minute_offset.value) 1584 | 1585 | 1586 | def dateStringOfComponents(cs): 1587 | """Build a PDF date string a (year, month, day, hour, minute, second, 1588 | hour_offset, minute_offset) tuple. 1589 | 1590 | Dates: Month 1-31, day 1-31, hours (0-23), minutes (0-59), seconds 1591 | (0-59), hour_offset is the offset from UT in hours (-23 to 23); 1592 | minute_offset is the offset from UT in minutes (-59 to 59).""" 1593 | year, month, day, hour, minute, second, hour_offset, minute_offset = cs 1594 | r = string_at(libc.pycpdf_dateStringOfComponents(year, month, day, hour, 1595 | minute, second, 1596 | hour_offset, 1597 | minute_offset)).decode() 1598 | checkerror() 1599 | return r 1600 | 1601 | 1602 | def getPageRotation(pdf, pagenumber): 1603 | """Get the viewing rotation for a given page.""" 1604 | r = libc.pycpdf_getPageRotation(pdf.pdf, pagenumber) 1605 | checkerror() 1606 | return r 1607 | 1608 | 1609 | def hasBox(pdf, pagenumber, boxname): 1610 | """Returns True, if the page has the given box. E.g "/CropBox" """ 1611 | r = libc.pycpdf_hasBox(pdf.pdf, pagenumber, str.encode(boxname)) 1612 | checkerror() 1613 | return r 1614 | 1615 | 1616 | def getMediaBox(pdf, pagenumber): 1617 | """Get a mediabox box given the document, page range, min x, max x, 1618 | min y, max y in points. Only suceeds if such a box exists, as checked by 1619 | hasBox""" 1620 | minx = c_double(0.0) 1621 | maxx = c_double(0.0) 1622 | miny = c_double(0.0) 1623 | maxy = c_double(0.0) 1624 | libc.pycpdf_getMediaBox(pdf.pdf, pagenumber, byref( 1625 | minx), byref(maxx), byref(miny), byref(maxy)) 1626 | checkerror() 1627 | return (minx.value, maxx.value, miny.value, maxy.value) 1628 | 1629 | 1630 | def getCropBox(pdf, pagenumber): 1631 | """Get a crop box given the document, page range, min x, max x, 1632 | min y, max y in points. Only suceeds if such a box exists, as checked by 1633 | hasBox""" 1634 | minx = c_double(0.0) 1635 | maxx = c_double(0.0) 1636 | miny = c_double(0.0) 1637 | maxy = c_double(0.0) 1638 | libc.pycpdf_getCropBox(pdf.pdf, pagenumber, byref( 1639 | minx), byref(maxx), byref(miny), byref(maxy)) 1640 | checkerror() 1641 | return (minx.value, maxx.value, miny.value, maxy.value) 1642 | 1643 | 1644 | def getTrimBox(pdf, pagenumber): 1645 | """Get a trim box given the document, page range, min x, max x, 1646 | min y, max y in points. Only suceeds if such a box exists, as checked by 1647 | hasBox""" 1648 | minx = c_double(0.0) 1649 | maxx = c_double(0.0) 1650 | miny = c_double(0.0) 1651 | maxy = c_double(0.0) 1652 | libc.pycpdf_getTrimBox(pdf.pdf, pagenumber, byref( 1653 | minx), byref(maxx), byref(miny), byref(maxy)) 1654 | checkerror() 1655 | return (minx.value, maxx.value, miny.value, maxy.value) 1656 | 1657 | 1658 | def getArtBox(pdf, pagenumber): 1659 | """Get an art box given the document, page range, min x, max x, 1660 | min y, max y in points. Only suceeds if such a box exists, as checked by 1661 | hasBox""" 1662 | minx = c_double(0.0) 1663 | maxx = c_double(0.0) 1664 | miny = c_double(0.0) 1665 | maxy = c_double(0.0) 1666 | libc.pycpdf_getArtBox(pdf.pdf, pagenumber, byref( 1667 | minx), byref(maxx), byref(miny), byref(maxy)) 1668 | checkerror() 1669 | return (minx.value, maxx.value, miny.value, maxy.value) 1670 | 1671 | 1672 | def getBleedBox(pdf, pagenumber): 1673 | """Get a bleed box given the document, page range, min x, max x, 1674 | min y, max y in points. Only suceeds if such a box exists, as checked by 1675 | hasBox""" 1676 | minx = c_double(0.0) 1677 | maxx = c_double(0.0) 1678 | miny = c_double(0.0) 1679 | maxy = c_double(0.0) 1680 | libc.pycpdf_getBleedBox(pdf.pdf, pagenumber, byref( 1681 | minx), byref(maxx), byref(miny), byref(maxy)) 1682 | checkerror() 1683 | return (minx.value, maxx.value, miny.value, maxy.value) 1684 | 1685 | 1686 | def setMediaBox(pdf, r, minx, maxx, miny, maxy): 1687 | """Set the media box given the document, page range, min x, max x, 1688 | min y, max y in points.""" 1689 | rn = range_of_list(r) 1690 | libc.pycpdf_setMediaBox(pdf.pdf, rn, minx, maxx, miny, maxy) 1691 | deleteRange(rn) 1692 | checkerror() 1693 | return 1694 | 1695 | 1696 | def setCropBox(pdf, r, minx, maxx, miny, maxy): 1697 | """Set the crop box given the document, page range, min x, max x, 1698 | min y, max y in points.""" 1699 | rn = range_of_list(r) 1700 | libc.pycpdf_setCropBox(pdf.pdf, rn, minx, maxx, miny, maxy) 1701 | deleteRange(rn) 1702 | checkerror() 1703 | return 1704 | 1705 | 1706 | def setTrimBox(pdf, r, minx, maxx, miny, maxy): 1707 | """Set the trim box given the document, page range, min x, max x, 1708 | min y, max y in points.""" 1709 | rn = range_of_list(r) 1710 | libc.pycpdf_setTrimBox(pdf.pdf, rn, minx, maxx, miny, maxy) 1711 | deleteRange(rn) 1712 | checkerror() 1713 | return 1714 | 1715 | 1716 | def setArtBox(pdf, r, minx, maxx, miny, maxy): 1717 | """Set the art box given the document, page range, min x, max x, 1718 | min y, max y in points.""" 1719 | rn = range_of_list(r) 1720 | libc.pycpdf_setArtBox(pdf.pdf, rn, minx, maxx, miny, maxy) 1721 | deleteRange(rn) 1722 | checkerror() 1723 | return 1724 | 1725 | 1726 | def setBleedBox(pdf, r, minx, maxx, miny, maxy): 1727 | """Set the bleed box given the document, page range, min x, max x, 1728 | min y, max y in points.""" 1729 | rn = range_of_list(r) 1730 | libc.pycpdf_setBleedBox(pdf.pdf, rn, minx, maxx, miny, maxy) 1731 | deleteRange(rn) 1732 | checkerror() 1733 | return 1734 | 1735 | 1736 | def markTrapped(pdf): 1737 | """Mark a document as trapped.""" 1738 | libc.pycpdf_markTrapped(pdf.pdf) 1739 | checkerror() 1740 | return 1741 | 1742 | 1743 | def markUntrapped(pdf): 1744 | """Mark a document as untrapped.""" 1745 | libc.pycpdf_markUntrapped(pdf.pdf) 1746 | checkerror() 1747 | return 1748 | 1749 | 1750 | def markTrappedXMP(pdf): 1751 | """Mark a document as trapped in XMP metadata.""" 1752 | libc.pycpdf_markTrappedXMP(pdf.pdf) 1753 | checkerror() 1754 | return 1755 | 1756 | 1757 | def markUntrappedXMP(pdf): 1758 | """Mark a document as untrapped in XMP metadata.""" 1759 | libc.pycpdf_markUntrappedXMP(pdf.pdf) 1760 | checkerror() 1761 | return 1762 | 1763 | 1764 | """Page layouts.""" 1765 | singlePage = 0 1766 | oneColumn = 1 1767 | twoColumnLeft = 2 1768 | twoColumnRight = 3 1769 | twoPageLeft = 4 1770 | twoPageRight = 5 1771 | 1772 | 1773 | def setPageLayout(pdf, layout): 1774 | """Set the page layout for a document.""" 1775 | libc.pycpdf_setPageLayout(pdf.pdf, layout) 1776 | checkerror() 1777 | return 1778 | 1779 | 1780 | """Page modes.""" 1781 | useNone = 0 1782 | useOutlines = 1 1783 | useThumbs = 2 1784 | useOC = 3 1785 | useAttachments = 4 1786 | 1787 | 1788 | def setPageMode(pdf, mode): 1789 | """Set the page mode for a document.""" 1790 | libc.pycpdf_setPageMode(pdf.pdf, mode) 1791 | checkerror() 1792 | return 1793 | 1794 | 1795 | def hideToolbar(pdf, flag): 1796 | """Sets the hide toolbar flag.""" 1797 | libc.pycpdf_hideToolbar(pdf.pdf, flag) 1798 | checkerror() 1799 | return 1800 | 1801 | 1802 | def hideMenubar(pdf, flag): 1803 | """Set the hide menu bar flag.""" 1804 | libc.pycpdf_hideMenubar(pdf.pdf, flag) 1805 | checkerror() 1806 | return 1807 | 1808 | 1809 | def hideWindowUi(pdf, flag): 1810 | """Set the hide window UI flag.""" 1811 | libc.pycpdf_hideWindowUi(pdf.pdf, flag) 1812 | checkerror() 1813 | return 1814 | 1815 | 1816 | def fitWindow(pdf, flag): 1817 | """Set the fit window flag.""" 1818 | libc.pycpdf_fitWindow(pdf.pdf, flag) 1819 | checkerror() 1820 | return 1821 | 1822 | 1823 | def centerWindow(pdf, flag): 1824 | """Set the center window flag.""" 1825 | libc.pycpdf_centerWindow(pdf.pdf, flag) 1826 | checkerror() 1827 | return 1828 | 1829 | 1830 | def displayDocTitle(pdf, flag): 1831 | """Set the display document title flag.""" 1832 | libc.pycpdf_displayDocTitle(pdf.pdf, flag) 1833 | checkerror() 1834 | return 1835 | 1836 | 1837 | def openAtPage(pdf, fitflag, pagenumber): 1838 | """Set the PDF to open, possibly with zoom-to-fit, at the given page number. 1839 | """ 1840 | libc.pycpdf_openAtPage(pdf.pdf, fitflag, pagenumber) 1841 | checkerror() 1842 | return 1843 | 1844 | 1845 | def setMetadataFromFile(pdf, filename): 1846 | """Set the XMP metadata of a document, given a file name.""" 1847 | libc.pycpdf_setMetadataFromFile(pdf.pdf, str.encode(filename)) 1848 | checkerror() 1849 | return 1850 | 1851 | 1852 | def setMetadataFromByteArray(pdf, data): 1853 | """Set the XMP metadata from an array of bytes.""" 1854 | libc.pycpdf_setMetadataFromByteArray(pdf.pdf, data, len(data)) 1855 | checkerror() 1856 | return 1857 | 1858 | 1859 | def getMetadata(pdf): 1860 | """Return the XMP metadata as a byte array of type bytes""" 1861 | length = c_int32() 1862 | data = libc.pycpdf_getMetadata(pdf.pdf, byref(length)) 1863 | out_data = create_string_buffer(length.value) 1864 | memmove(out_data, data, length.value) 1865 | libc.pycpdf_getMetadataFree() 1866 | checkerror() 1867 | return out_data.raw 1868 | 1869 | 1870 | def removeMetadata(pdf): 1871 | """Remove the XMP metadata from a document""" 1872 | libc.pycpdf_removeMetadata(pdf.pdf) 1873 | checkerror() 1874 | return 1875 | 1876 | 1877 | def createMetadata(pdf): 1878 | """Builds fresh XMP metadata as good as possible from existing 1879 | metadata in the document.""" 1880 | libc.pycpdf_createMetadata(pdf.pdf) 1881 | checkerror() 1882 | return 1883 | 1884 | 1885 | def setMetadataDate(pdf, date): 1886 | """Set the metadata date for a PDF. The date is given in PDF date format -- 1887 | cpdf will convert it to XMP format. The date 'now' means now.""" 1888 | libc.pycpdf_setMetadataDate(pdf.pdf, str.encode(date)) 1889 | checkerror() 1890 | return 1891 | 1892 | 1893 | """Label styles.""" 1894 | decimalArabic = 0 1895 | uppercaseRoman = 1 1896 | lowercaseRoman = 2 1897 | uppercaseLetters = 3 1898 | lowercaseLetters = 4 1899 | 1900 | 1901 | def getPageLabels(pdf): 1902 | """Get page labels as a list of tuples (style, prefix, offset, startvalue) 1903 | 1904 | For example, a document might have five pages of introduction with roman 1905 | numerals, followed by the rest of the pages in decimal arabic, numbered 1906 | from one. First label: 1907 | 1908 | * labelstyle = LowercaseRoman 1909 | * labelprefix = "" 1910 | * startpage = 1 1911 | * startvalue = 1 1912 | 1913 | Second label: 1914 | 1915 | * labelstyle = DecimalArabic 1916 | * labelprefix = "" 1917 | * startpage = 6 1918 | * startvalue = 1 """ 1919 | n = libc.pycpdf_startGetPageLabels(pdf.pdf) 1920 | l = [] 1921 | for x in range(n): 1922 | style = libc.pycpdf_getPageLabelStyle(x) 1923 | prefix = string_at(libc.pycpdf_getPageLabelPrefix(x)).decode() 1924 | offset = libc.pycpdf_getPageLabelOffset(x) 1925 | startvalue = libc.pycpdf_getPageLabelRange(x) 1926 | l.append((style, prefix, offset, startvalue)) 1927 | libc.pycpdf_endGetPageLabels() 1928 | checkerror() 1929 | return l 1930 | 1931 | 1932 | def addPageLabels(pdf, label, progress): 1933 | """Add one group of page labels from a tuple (style, prefix, offset, range). 1934 | 1935 | The prefix is prefix text for each label. The range is the page range the 1936 | labels apply to. Offset can be used to shift the numbering up or down.""" 1937 | style, prefix, offset, plrange = label 1938 | rn = range_of_list(plrange) 1939 | libc.pycpdf_addPageLabels(pdf.pdf, style, str.encode( 1940 | prefix), offset, rn, progress) 1941 | deleteRange(rn) 1942 | checkerror() 1943 | return 1944 | 1945 | 1946 | def removePageLabels(pdf): 1947 | """Removes all page labels from the document.""" 1948 | libc.pycpdf_removePageLabels(pdf.pdf) 1949 | checkerror() 1950 | return 1951 | 1952 | 1953 | def getPageLabelStringForPage(pdf, pagenumber): 1954 | """Calculate the full label string for a given page, and return it.""" 1955 | r = string_at(libc.pycpdf_getPageLabelStringForPage( 1956 | pdf.pdf, pagenumber)).decode() 1957 | checkerror() 1958 | return r 1959 | 1960 | # CHAPTER 12. File Attachments 1961 | 1962 | 1963 | def attachFile(filename, pdf): 1964 | """Attach a file to the pdf. It is attached at document level.""" 1965 | libc.pycpdf_attachFile(str.encode(filename), pdf.pdf) 1966 | checkerror() 1967 | 1968 | 1969 | def attachFileToPage(filename, pdf, pagenumber): 1970 | """Attach a file, given its file name, pdf, and the page number to which 1971 | it should be attached.""" 1972 | libc.pycpdf_attachFileToPage(str.encode(filename), pdf.pdf, pagenumber) 1973 | checkerror() 1974 | 1975 | 1976 | def attachFileFromMemory(data, filename, pdf): 1977 | """Attach a file from a byte array. It is attached at document level.""" 1978 | libc.pycpdf_attachFileFromMemory( 1979 | data, len(data), str.encode(filename), pdf.pdf) 1980 | checkerror() 1981 | 1982 | 1983 | def attachFileToPageFromMemory(data, filename, pdf, pagenumber): 1984 | """Attach a file to a given pag from a byte array. It is attached at 1985 | document level.""" 1986 | libc.pycpdf_attachFileToPageFromMemory( 1987 | data, len(data), str.encode(filename), pdf.pdf, pagenumber) 1988 | checkerror() 1989 | 1990 | 1991 | def removeAttachedFiles(pdf): 1992 | """Remove all page- and document-level attachments from a document.""" 1993 | libc.pycpdf_removeAttachedFiles(pdf.pdf) 1994 | checkerror() 1995 | 1996 | 1997 | def getAttachments(pdf): 1998 | """List information about attachements. Returns a list of tuples 1999 | (name, page number, byte array of data). Page 0 = document-level 2000 | attachment.""" 2001 | libc.pycpdf_startGetAttachments(pdf.pdf) 2002 | n = libc.pycpdf_numberGetAttachments() 2003 | l = [] 2004 | for i in range(n): 2005 | name = string_at(libc.pycpdf_getAttachmentName(i)).decode() 2006 | page = libc.pycpdf_getAttachmentPage(i) 2007 | length = c_int32() 2008 | data = libc.pycpdf_getAttachmentData(i, byref(length)) 2009 | out_data = create_string_buffer(length.value) 2010 | memmove(out_data, data, length.value) 2011 | libc.pycpdf_getAttachmentFree() 2012 | l.append((name, page, out_data.raw)) 2013 | libc.pycpdf_endGetAttachments() 2014 | checkerror() 2015 | return l 2016 | 2017 | # CHAPTER 13. Images 2018 | 2019 | 2020 | def getImageResolution(pdf, min_required_resolution): 2021 | """Return a list of all uses of images in the PDF which do not meet the 2022 | minimum required resolution in dpi as tuples of: 2023 | (pagenumber, name, x pixels, y pixels, x resolution, y resolution).""" 2024 | n = libc.pycpdf_startGetImageResolution(pdf.pdf, min_required_resolution) 2025 | l = [] 2026 | for x in range(n): 2027 | pagenumber = libc.pycpdf_getImageResolutionPageNumber(x) 2028 | imagename = string_at( 2029 | libc.pycpdf_getImageResolutionImageName(x)).decode() 2030 | xp = libc.pycpdf_getImageResolutionXPixels(x) 2031 | yp = libc.pycpdf_getImageResolutionYPixels(x) 2032 | xr = libc.pycpdf_getImageResolutionXRes(x) 2033 | yr = libc.pycpdf_getImageResolutionYRes(x) 2034 | l.append((pagenumber, imagename, xp, yp, xr, yr)) 2035 | libc.pycpdf_endGetImageResolution() 2036 | checkerror() 2037 | return l 2038 | 2039 | # CHAPTER 14. Fonts 2040 | 2041 | 2042 | def getFontInfo(pdf): 2043 | """Get a list of (pagenumber, fontname, fonttype, fontencoding) tuples, 2044 | showing each font used on each page.""" 2045 | libc.pycpdf_startGetFontInfo(pdf.pdf) 2046 | n = libc.pycpdf_numberFonts() 2047 | l = [] 2048 | for x in range(n): 2049 | pagenumber = libc.pycpdf_getFontPage(x) 2050 | fontname = string_at(libc.pycpdf_getFontName(x)).decode() 2051 | fonttype = string_at(libc.pycpdf_getFontType(x)).decode() 2052 | fontencoding = string_at(libc.pycpdf_getFontEncoding(x)).decode() 2053 | l.append((pagenumber, fontname, fonttype, fontencoding)) 2054 | libc.pycpdf_endGetFontInfo(pdf.pdf) 2055 | checkerror() 2056 | return l 2057 | 2058 | 2059 | def removeFonts(pdf): 2060 | """Remove all font data from a file.""" 2061 | libc.pycpdf_removeFonts(pdf.pdf) 2062 | checkerror() 2063 | 2064 | 2065 | def copyFont(pdf, pdf2, r, pagenumber, fontname): 2066 | """Copy the given font from the given page in the pdf PDF to every page in 2067 | the pdf2 PDF. The new font is stored under its font name.""" 2068 | r = range_of_list(r) 2069 | libc.pycpdf_copyFont(pdf.pdf, pdf2.pdf, r, 2070 | pagenumber, str.encode(fontname)) 2071 | deleteRange(r) 2072 | checkerror() 2073 | 2074 | # CHAPTER 15. PDF and JSON 2075 | 2076 | 2077 | def outputJSON(filename, parse_content, no_stream_data, decompress_streams, pdf): 2078 | """Output a PDF in JSON format to the given filename. If parse_content is 2079 | True, page content is parsed. If decompress_streams is True, streams are 2080 | decompressed. If no_stream_data is True, all stream data is suppressed 2081 | entirely.""" 2082 | libc.pycpdf_outputJSON(str.encode(filename), 2083 | parse_content, no_stream_data, decompress_streams, pdf.pdf) 2084 | checkerror() 2085 | 2086 | 2087 | def outputJSONMemory(pdf, parse_content, no_stream_data, decompress_streams): 2088 | """outputJSONMemory(pdf, parse_content, no_stream_data, decompress_stream) 2089 | is like outputJSON, but it write to a buffer in memory).""" 2090 | length = c_int32() 2091 | data = libc.pycpdf_outputJSONMemory( 2092 | pdf.pdf, parse_content, no_stream_data, decompress_streams, byref(length)) 2093 | out_data = create_string_buffer(length.value) 2094 | memmove(out_data, data, length.value) 2095 | libc.pycpdf_outputJSONMemoryFree() 2096 | checkerror() 2097 | return out_data.raw 2098 | 2099 | 2100 | def fromJSON(filename): 2101 | """Load a PDF from a JSON file given its filename.""" 2102 | pdf = Pdf(libc.pycpdf_fromJSON(str.encode(filename))) 2103 | checkerror() 2104 | return pdf 2105 | 2106 | 2107 | def fromJSONMemory(data): 2108 | """ Load a PDF from JSON data in memory.""" 2109 | pdf = Pdf(libc.pycpdf_fromJSONMemory(data, len(data))) 2110 | checkerror() 2111 | return pdf 2112 | 2113 | 2114 | # CHAPTER 16. Optional Content Groups 2115 | 2116 | 2117 | def getOCGList(pdf): 2118 | """Return a list of Optional Content Groups in the given pdf as strings.""" 2119 | l = [] 2120 | n = libc.pycpdf_startGetOCGList(pdf.pdf) 2121 | for x in range(n): 2122 | l.append(string_at(libc.pycpdf_OCGListEntry(x)).decode()) 2123 | libc.pycpdf_endGetOCGList() 2124 | checkerror() 2125 | return l 2126 | 2127 | 2128 | def OCGRename(pdf, n_from, n_to): 2129 | """Rename an optional content group.""" 2130 | libc.pycpdf_OCGRename(pdf.pdf, str.encode(n_from), str.encode(n_to)) 2131 | checkerror() 2132 | 2133 | 2134 | def OCGOrderAll(pdf): 2135 | """Ensure that every optional content group appears in the OCG order list. 2136 | """ 2137 | libc.pycpdf_OCGOrderAll(pdf.pdf) 2138 | checkerror() 2139 | 2140 | 2141 | def OCGCoalesce(pdf): 2142 | """Coalesce optional content groups. For example, if we merge or stamp two 2143 | files both with an OCG called "Layer 1", we will have two different 2144 | optional content groups. This function will merge the two into a single 2145 | optional content group.""" 2146 | libc.pycpdf_OCGCoalesce(pdf.pdf) 2147 | checkerror() 2148 | 2149 | # CHAPTER 17. Making New PDFs 2150 | 2151 | 2152 | def blankDocument(w, h, pages): 2153 | """ Create a blank document 2154 | with pages of the given width (in points), height (in points), and number 2155 | of pages.""" 2156 | pdf = Pdf(libc.pycpdf_blankDocument(w, h, pages)) 2157 | checkerror() 2158 | return pdf 2159 | 2160 | 2161 | def blankDocumentPaper(papersize, pages): 2162 | """Create a blank document with pages of the given paper size, and number 2163 | of pages. """ 2164 | r = Pdf(libc.pycpdf_blankDocumentPaper(papersize, pages)) 2165 | checkerror() 2166 | return r 2167 | 2168 | 2169 | def textToPDF(w, h, font, fontsize, filename): 2170 | """textToPDF(w, h, font, fontsize, filename) typesets a UTF8 text file 2171 | ragged right on a page of size w * h in points in the given font and font 2172 | size.""" 2173 | pdf = Pdf(libc.pycpdf_textToPDF( 2174 | w, h, font, fontsize, str.encode(filename))) 2175 | checkerror() 2176 | return pdf 2177 | 2178 | 2179 | def textToPDFPaper(papersize, font, fontsize, filename): 2180 | """textToPDF(papersize font, fontsize, filename) typesets a UTF8 text file 2181 | ragged right on a page of the given size in the given font and font 2182 | size.""" 2183 | pdf = Pdf(libc.pycpdf_textToPDFPaper( 2184 | papersize, font, fontsize, str.encode(filename))) 2185 | checkerror() 2186 | return pdf 2187 | 2188 | # CHAPTER 18. Miscellaneous 2189 | 2190 | 2191 | def draft(pdf, r, boxes): 2192 | """Remove images on the given pages, replacing 2193 | them with crossed boxes if 'boxes' is True.""" 2194 | r = range_of_list(r) 2195 | libc.pycpdf_draft(pdf.pdf, r, boxes) 2196 | deleteRange(r) 2197 | checkerror() 2198 | 2199 | 2200 | def removeAllText(pdf, r): 2201 | """Remove all text from the given pages in a document.""" 2202 | r = range_of_list(r) 2203 | libc.pycpdf_removeAllText(pdf.pdf, r) 2204 | deleteRange(r) 2205 | checkerror() 2206 | 2207 | 2208 | def blackText(pdf, r): 2209 | """Blacken all text on the given pages.""" 2210 | r = range_of_list(r) 2211 | libc.pycpdf_blackText(pdf.pdf, r) 2212 | deleteRange(r) 2213 | checkerror() 2214 | 2215 | 2216 | def blackLines(pdf, r): 2217 | """Blacken all lines on the given pages.""" 2218 | r = range_of_list(r) 2219 | libc.pycpdf_blackLines(pdf.pdf, r) 2220 | deleteRange(r) 2221 | checkerror() 2222 | 2223 | 2224 | def blackFills(pdf, r): 2225 | """Blacken all fills on the given pages.""" 2226 | r = range_of_list(r) 2227 | libc.pycpdf_blackFills(pdf.pdf, r) 2228 | deleteRange(r) 2229 | checkerror() 2230 | 2231 | 2232 | def thinLines(pdf, r, linewidth): 2233 | """Thicken every line less than 2234 | linewidth to linewidth. Thickness given in points.""" 2235 | r = range_of_list(r) 2236 | libc.pycpdf_thinLines(pdf.pdf, r, linewidth) 2237 | deleteRange(r) 2238 | checkerror() 2239 | 2240 | 2241 | def copyId(pdf, pdf2): 2242 | """Copy the /ID from one pdf to pdf2.""" 2243 | libc.pycpdf_copyId(pdf.pdf, pdf2.pdf) 2244 | checkerror() 2245 | 2246 | 2247 | def removeId(pdf): 2248 | """Remove a document's /ID""" 2249 | libc.pycpdf_removeId(pdf.pdf) 2250 | checkerror() 2251 | 2252 | 2253 | def setVersion(pdf, version): 2254 | """Set the minor version number of a document.""" 2255 | libc.pycpdf_setVersion(pdf.pdf, version) 2256 | checkerror() 2257 | 2258 | 2259 | def setFullVersion(pdf, major, minor): 2260 | """Set the major and minor version number of 2261 | a document.""" 2262 | libc.pycpdf_setFullVersion(pdf.pdf, major, minor) 2263 | checkerror() 2264 | 2265 | 2266 | def removeDictEntry(pdf, key): 2267 | """Remove any dictionary entry with the given 2268 | key anywhere in the document.""" 2269 | libc.pycpdf_removeDictEntry(pdf.pdf, str.encode(key)) 2270 | checkerror() 2271 | 2272 | 2273 | def removeDictEntrySearch(pdf, key, searchterm): 2274 | """Remove any dictionary entry with the given 2275 | key anywhere in the document, if its value matches the given search term.""" 2276 | libc.pycpdf_removeDictEntrySearch( 2277 | pdf.pdf, str.encode(key), str.encode(searchterm)) 2278 | checkerror() 2279 | 2280 | 2281 | def replaceDictEntry(pdf, key, newvalue): 2282 | """Replace any dictionary entry with the given 2283 | key anywhere in the document using the new value given.""" 2284 | libc.pycpdf_replaceDictEntry( 2285 | pdf.pdf, str.encode(key), str.encode(newvalue)) 2286 | checkerror() 2287 | 2288 | 2289 | def replaceDictEntrySearch(pdf, key, newvalue, searchterm): 2290 | """Replace any dictionary entry with the given key anywhere in the 2291 | document, if its value matches the given search term, with the new value 2292 | given.""" 2293 | libc.pycpdf_replaceDictEntrySearch( 2294 | pdf.pdf, str.encode(key), str.encode(newvalue), str.encode(searchterm)) 2295 | checkerror() 2296 | 2297 | 2298 | def getDictEntries(pdf, key): 2299 | """Return JSON of any dict entries with the given key.""" 2300 | length = c_int32() 2301 | data = libc.pycpdf_getDictEntries(pdf.pdf, str.encode(key), byref(length)) 2302 | out_data = create_string_buffer(length.value) 2303 | memmove(out_data, data, length.value) 2304 | libc.pycpdf_getDictEntriesFree() 2305 | checkerror() 2306 | return out_data.raw 2307 | 2308 | 2309 | def removeClipping(pdf, r): 2310 | """Remove all clipping from pages in the given range""" 2311 | r = range_of_list(r) 2312 | libc.pycpdf_removeClipping(pdf.pdf, r) 2313 | deleteRange(r) 2314 | checkerror() 2315 | 2316 | # CHAPTER X. Undocumented or Internal 2317 | 2318 | 2319 | def list_of_range(r): 2320 | """Internal.""" 2321 | l = [] 2322 | for x in range(libc.pycpdf_rangeLength(r)): 2323 | l.append(libc.pycpdf_rangeGet(r, x)) 2324 | checkerror() 2325 | return l 2326 | 2327 | 2328 | def range_of_list(l): 2329 | """Internal.""" 2330 | r = libc.pycpdf_blankRange() 2331 | for x in l: 2332 | rn = libc.pycpdf_rangeAdd(r, x) 2333 | deleteRange(r) 2334 | r = rn 2335 | checkerror() 2336 | return r 2337 | 2338 | 2339 | def deleteRange(r): 2340 | """Internal.""" 2341 | r = libc.pycpdf_deleteRange(r) 2342 | checkerror() 2343 | return r 2344 | -------------------------------------------------------------------------------- /pycpdflibmanual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/pycpdflibmanual.pdf -------------------------------------------------------------------------------- /windows32/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/windows32/.gitignore -------------------------------------------------------------------------------- /windows32/jcpdf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/windows32/jcpdf.dll -------------------------------------------------------------------------------- /windows32/libcpdf.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/windows32/libcpdf.a -------------------------------------------------------------------------------- /windows32/libcpdf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/windows32/libcpdf.dll -------------------------------------------------------------------------------- /windows32/libgcc_s_sjlj-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/windows32/libgcc_s_sjlj-1.dll -------------------------------------------------------------------------------- /windows32/libpycpdf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/windows32/libpycpdf.dll -------------------------------------------------------------------------------- /windows32/readme.txt: -------------------------------------------------------------------------------- 1 | COHERENT PDF C API 2 | 3 | There is one header file, cpdflibwrapper.h, and a static library and DLL(s). 4 | 5 | Sample linking on Linux with static libraries: 6 | 7 | cc program.c -o program -L. -lcpdf -lm -ldl 8 | 9 | Sample linking on Windows with DLL: 10 | 11 | cc program.c -o program.exe -Wl,-rpath,. -L. -l:libcpdf.dll 12 | 13 | Sample linking on OS X with static libraries: 14 | 15 | cc program.c -o program -L. -lcpdf 16 | 17 | 18 | COHERENT PDF Python API 19 | 20 | Use pycpdflib.py and import Pycpdflib with the DLLs libcpdf and libpycpdf. 21 | Further instruction in pycpdflibmanual.pdf. 22 | 23 | Also available directly with "pip install pycpdflib" (just installs 24 | pycpdflib.py). 25 | 26 | Online docs: https://python-libcpdf.readthedocs.io/en/latest/ 27 | 28 | 29 | COHERENT PDF .NET API 30 | 31 | Use the assembly provided in the dotnet folder, or the nuget package provided 32 | in the root folder. 33 | 34 | Full manual (required reading): dotnetcpdflibmanual.pdf in this folder. Follow 35 | the instructions at the end of Chapter 1 to write your first program. 36 | 37 | In addition, the assembly and nuget package provide Intellisense documentation 38 | with each function. 39 | 40 | Before using the library, you must make sure your project or build environment 41 | has access to the cpdf DLL, which is not part of the .NET assembly or nuget 42 | package. You can add it to a Visual Studio project as a file, set to 43 | copy-to-output-folder. Or, you can install it in a standard location such as 44 | the Windows system folder. 45 | 46 | ***IMPORTANT The DLL libcpdf.dll provided in this folder must be renamed 47 | cpdf.dll for .NET to be able to find it.*** 48 | 49 | 50 | COHERENT PDF JAVA API 51 | 52 | Use the .jar supplied in the java folder. 53 | 54 | Full manual (required reading): jcpdflibmanual.pdf in this folder. Follow 55 | the instructions at the end of Chapter 1 to write your first program. 56 | 57 | You will also require the jcpdf DLL from the platform folder, and the main cpdf 58 | DLL too. 59 | 60 | The java library invokes LoadLibrary on the jcpdf DLL, and so it must be placed 61 | in your java.library.path. The cpdf DLL itself will be searched for not by 62 | Java, but by your system, as a dependency of jcpdf. 63 | 64 | Files should be named jcpdf.dll and libcpdf.dll. Put jcpdf.dll in your 65 | java.library.path and then libcpdf.dll in the same folder, or in a standard 66 | location such as System32. 67 | -------------------------------------------------------------------------------- /windows64/jcpdf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/windows64/jcpdf.dll -------------------------------------------------------------------------------- /windows64/libcpdf.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/windows64/libcpdf.a -------------------------------------------------------------------------------- /windows64/libcpdf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/windows64/libcpdf.dll -------------------------------------------------------------------------------- /windows64/libpycpdf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coherentgraphics/cpdflib-binary/63e52872a7d38d81fde5b4aa97a27a7fe339b0ca/windows64/libpycpdf.dll -------------------------------------------------------------------------------- /windows64/readme.txt: -------------------------------------------------------------------------------- 1 | COHERENT PDF C API 2 | 3 | There is one header file, cpdflibwrapper.h, and a static library and DLL(s). 4 | 5 | Sample linking on Linux with static libraries: 6 | 7 | cc program.c -o program -L. -lcpdf -lm -ldl 8 | 9 | Sample linking on Windows with DLL: 10 | 11 | cc program.c -o program.exe -Wl,-rpath,. -L. -l:libcpdf.dll 12 | 13 | Sample linking on OS X with static libraries: 14 | 15 | cc program.c -o program -L. -lcpdf 16 | 17 | 18 | COHERENT PDF Python API 19 | 20 | Use pycpdflib.py and import Pycpdflib with the DLLs libcpdf and libpycpdf. 21 | Further instruction in pycpdflibmanual.pdf. 22 | 23 | Also available directly with "pip install pycpdflib" (just installs 24 | pycpdflib.py). 25 | 26 | Online docs: https://python-libcpdf.readthedocs.io/en/latest/ 27 | 28 | 29 | COHERENT PDF .NET API 30 | 31 | Use the assembly provided in the dotnet folder, or the nuget package provided 32 | in the root folder. 33 | 34 | Full manual (required reading): dotnetcpdflibmanual.pdf in this folder. Follow 35 | the instructions at the end of Chapter 1 to write your first program. 36 | 37 | In addition, the assembly and nuget package provide Intellisense documentation 38 | with each function. 39 | 40 | Before using the library, you must make sure your project or build environment 41 | has access to the cpdf DLL, which is not part of the .NET assembly or nuget 42 | package. You can add it to a Visual Studio project as a file, set to 43 | copy-to-output-folder. Or, you can install it in a standard location such as 44 | the Windows system folder. 45 | 46 | ***IMPORTANT The DLL libcpdf.dll provided in this folder must be renamed 47 | cpdf.dll for .NET to be able to find it.*** 48 | 49 | 50 | COHERENT PDF JAVA API 51 | 52 | Use the .jar supplied in the java folder. 53 | 54 | Full manual (required reading): jcpdflibmanual.pdf in this folder. Follow 55 | the instructions at the end of Chapter 1 to write your first program. 56 | 57 | You will also require the jcpdf DLL from the platform folder, and the main cpdf 58 | DLL too. 59 | 60 | The java library invokes LoadLibrary on the jcpdf DLL, and so it must be placed 61 | in your java.library.path. The cpdf DLL itself will be searched for not by 62 | Java, but by your system, as a dependency of jcpdf. 63 | 64 | Files should be named jcpdf.dll and libcpdf.dll. Put jcpdf.dll in your 65 | java.library.path and then libcpdf.dll in the same folder, or in a standard 66 | location such as System32. 67 | --------------------------------------------------------------------------------