PK!k3yj LICENSE.TXTnu[********************************************************************** * TCPDF LICENSE ********************************************************************** TCPDF is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 2002-2024 Nicola Asuni - Tecnick.com LTD ********************************************************************** ********************************************************************** GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. ********************************************************************** ********************************************************************** GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ********************************************************************** ********************************************************************** PK!iȯO9O9tcpdf_barcodes_2d.phpnu[. // // See LICENSE.TXT file for more information. // ------------------------------------------------------------------- // // Description : PHP class to creates array representations for // 2D barcodes to be used with TCPDF. // //============================================================+ /** * @file * PHP class to creates array representations for 2D barcodes to be used with TCPDF. * @package com.tecnick.tcpdf * @author Nicola Asuni * @version 1.0.015 */ /** * @class TCPDF2DBarcode * PHP class to creates array representations for 2D barcodes to be used with TCPDF (http://www.tcpdf.org). * @package com.tecnick.tcpdf * @version 1.0.015 * @author Nicola Asuni */ class TCPDF2DBarcode { /** * Array representation of barcode. * @protected */ protected $barcode_array = array(); /** * This is the class constructor. * Return an array representations for 2D barcodes:
    *
  • $arrcode['code'] code to be printed on text label
  • *
  • $arrcode['num_rows'] required number of rows
  • *
  • $arrcode['num_cols'] required number of columns
  • *
  • $arrcode['bcode'][$r][$c] value of the cell is $r row and $c column (0 = transparent, 1 = black)
* @param string $code code to print * @param string $type type of barcode:
  • DATAMATRIX : Datamatrix (ISO/IEC 16022)
  • PDF417 : PDF417 (ISO/IEC 15438:2006)
  • PDF417,a,e,t,s,f,o0,o1,o2,o3,o4,o5,o6 : PDF417 with parameters: a = aspect ratio (width/height); e = error correction level (0-8); t = total number of macro segments; s = macro segment index (0-99998); f = file ID; o0 = File Name (text); o1 = Segment Count (numeric); o2 = Time Stamp (numeric); o3 = Sender (text); o4 = Addressee (text); o5 = File Size (numeric); o6 = Checksum (numeric). NOTES: Parameters t, s and f are required for a Macro Control Block, all other parameters are optional. To use a comma character ',' on text options, replace it with the character 255: "\xff".
  • QRCODE : QRcode Low error correction
  • QRCODE,L : QRcode Low error correction
  • QRCODE,M : QRcode Medium error correction
  • QRCODE,Q : QRcode Better error correction
  • QRCODE,H : QR-CODE Best error correction
  • RAW: raw mode - comma-separad list of array rows
  • RAW2: raw mode - array rows are surrounded by square parenthesis.
  • TEST : Test matrix
*/ public function __construct($code, $type) { $this->setBarcode($code, $type); } /** * Return an array representations of barcode. * @return array */ public function getBarcodeArray() { return $this->barcode_array; } /** * Send barcode as SVG image object to the standard output. * @param int $w Width of a single rectangle element in user units. * @param int $h Height of a single rectangle element in user units. * @param string $color Foreground color (in SVG format) for bar elements (background is transparent). * @public */ public function getBarcodeSVG($w=3, $h=3, $color='black') { // send headers $code = $this->getBarcodeSVGcode($w, $h, $color); header('Content-Type: application/svg+xml'); header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 header('Pragma: public'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); header('Content-Disposition: inline; filename="'.md5($code).'.svg";'); //header('Content-Length: '.strlen($code)); echo $code; } /** * Return a SVG string representation of barcode. * @param int $w Width of a single rectangle element in user units. * @param int $h Height of a single rectangle element in user units. * @param string $color Foreground color (in SVG format) for bar elements (background is transparent). * @return string SVG code. * @public */ public function getBarcodeSVGcode($w=3, $h=3, $color='black') { // replace table for special characters $repstr = array("\0" => '', '&' => '&', '<' => '<', '>' => '>'); $svg = '<'.'?'.'xml version="1.0" standalone="no"'.'?'.'>'."\n"; $svg .= ''."\n"; $svg .= ''."\n"; $svg .= "\t".''.strtr($this->barcode_array['code'], $repstr).''."\n"; $svg .= "\t".''."\n"; // print barcode elements $y = 0; // for each row for ($r = 0; $r < $this->barcode_array['num_rows']; ++$r) { $x = 0; // for each column for ($c = 0; $c < $this->barcode_array['num_cols']; ++$c) { if ($this->barcode_array['bcode'][$r][$c] == 1) { // draw a single barcode cell $svg .= "\t\t".''."\n"; } $x += $w; } $y += $h; } $svg .= "\t".''."\n"; $svg .= ''."\n"; return $svg; } /** * Return an HTML representation of barcode. * @param int $w Width of a single rectangle element in pixels. * @param int $h Height of a single rectangle element in pixels. * @param string $color Foreground color for bar elements (background is transparent). * @return string HTML code. * @public */ public function getBarcodeHTML($w=10, $h=10, $color='black') { $html = '
'."\n"; // print barcode elements $y = 0; // for each row for ($r = 0; $r < $this->barcode_array['num_rows']; ++$r) { $x = 0; // for each column for ($c = 0; $c < $this->barcode_array['num_cols']; ++$c) { if ($this->barcode_array['bcode'][$r][$c] == 1) { // draw a single barcode cell $html .= '
 
'."\n"; } $x += $w; } $y += $h; } $html .= '
'."\n"; return $html; } /** * Send a PNG image representation of barcode (requires GD or Imagick library). * @param int $w Width of a single rectangle element in pixels. * @param int $h Height of a single rectangle element in pixels. * @param array $color RGB (0-255) foreground color for bar elements (background is transparent). * @public */ public function getBarcodePNG($w=3, $h=3, $color=array(0,0,0)) { $data = $this->getBarcodePngData($w, $h, $color); // send headers header('Content-Type: image/png'); header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 header('Pragma: public'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); //header('Content-Length: '.strlen($data)); echo $data; } /** * Return a PNG image representation of barcode (requires GD or Imagick library). * @param int $w Width of a single rectangle element in pixels. * @param int $h Height of a single rectangle element in pixels. * @param array $color RGB (0-255) foreground color for bar elements (background is transparent). * @return string|Imagick|false image or false in case of error. * @public */ public function getBarcodePngData($w=3, $h=3, $color=array(0,0,0)) { // calculate image size $width = ($this->barcode_array['num_cols'] * $w); $height = ($this->barcode_array['num_rows'] * $h); if (function_exists('imagecreate')) { // GD library $imagick = false; $png = imagecreate($width, $height); $bgcol = imagecolorallocate($png, 255, 255, 255); imagecolortransparent($png, $bgcol); $fgcol = imagecolorallocate($png, $color[0], $color[1], $color[2]); } elseif (extension_loaded('imagick')) { $imagick = true; $bgcol = new imagickpixel('rgb(255,255,255'); $fgcol = new imagickpixel('rgb('.$color[0].','.$color[1].','.$color[2].')'); $png = new Imagick(); $png->newImage($width, $height, 'none', 'png'); $bar = new imagickdraw(); $bar->setfillcolor($fgcol); } else { return false; } // print barcode elements $y = 0; // for each row for ($r = 0; $r < $this->barcode_array['num_rows']; ++$r) { $x = 0; // for each column for ($c = 0; $c < $this->barcode_array['num_cols']; ++$c) { if ($this->barcode_array['bcode'][$r][$c] == 1) { // draw a single barcode cell if ($imagick) { $bar->rectangle($x, $y, ($x + $w - 1), ($y + $h - 1)); } else { imagefilledrectangle($png, $x, $y, ($x + $w - 1), ($y + $h - 1), $fgcol); } } $x += $w; } $y += $h; } if ($imagick) { $png->drawimage($bar); return $png; } else { ob_start(); imagepng($png); $imagedata = ob_get_clean(); imagedestroy($png); return $imagedata; } } /** * Set the barcode. * @param string $code code to print * @param string $type type of barcode:
  • DATAMATRIX : Datamatrix (ISO/IEC 16022)
  • PDF417 : PDF417 (ISO/IEC 15438:2006)
  • PDF417,a,e,t,s,f,o0,o1,o2,o3,o4,o5,o6 : PDF417 with parameters: a = aspect ratio (width/height); e = error correction level (0-8); t = total number of macro segments; s = macro segment index (0-99998); f = file ID; o0 = File Name (text); o1 = Segment Count (numeric); o2 = Time Stamp (numeric); o3 = Sender (text); o4 = Addressee (text); o5 = File Size (numeric); o6 = Checksum (numeric). NOTES: Parameters t, s and f are required for a Macro Control Block, all other parameters are optional. To use a comma character ',' on text options, replace it with the character 255: "\xff".
  • QRCODE : QRcode Low error correction
  • QRCODE,L : QRcode Low error correction
  • QRCODE,M : QRcode Medium error correction
  • QRCODE,Q : QRcode Better error correction
  • QRCODE,H : QR-CODE Best error correction
  • RAW: raw mode - comma-separad list of array rows
  • RAW2: raw mode - array rows are surrounded by square parenthesis.
  • TEST : Test matrix
* @return void */ public function setBarcode($code, $type) { $mode = explode(',', $type); $qrtype = strtoupper($mode[0]); switch ($qrtype) { case 'DATAMATRIX': { // DATAMATRIX (ISO/IEC 16022) require_once(dirname(__FILE__).'/include/barcodes/datamatrix.php'); $qrcode = new Datamatrix($code); $this->barcode_array = $qrcode->getBarcodeArray(); $this->barcode_array['code'] = $code; break; } case 'PDF417': { // PDF417 (ISO/IEC 15438:2006) require_once(dirname(__FILE__).'/include/barcodes/pdf417.php'); if (!isset($mode[1]) OR ($mode[1] === '')) { $aspectratio = 2; // default aspect ratio (width / height) } else { $aspectratio = floatval($mode[1]); } if (!isset($mode[2]) OR ($mode[2] === '')) { $ecl = -1; // default error correction level (auto) } else { $ecl = intval($mode[2]); } // set macro block $macro = array(); if (isset($mode[3]) AND ($mode[3] !== '') AND isset($mode[4]) AND ($mode[4] !== '') AND isset($mode[5]) AND ($mode[5] !== '')) { $macro['segment_total'] = intval($mode[3]); $macro['segment_index'] = intval($mode[4]); $macro['file_id'] = strtr($mode[5], "\xff", ','); for ($i = 0; $i < 7; ++$i) { $o = $i + 6; if (isset($mode[$o]) AND ($mode[$o] !== '')) { // add option $macro['option_'.$i] = strtr($mode[$o], "\xff", ','); } } } $qrcode = new PDF417($code, $ecl, $aspectratio, $macro); $this->barcode_array = $qrcode->getBarcodeArray(); $this->barcode_array['code'] = $code; break; } case 'QRCODE': { // QR-CODE require_once(dirname(__FILE__).'/include/barcodes/qrcode.php'); if (!isset($mode[1]) OR (!in_array($mode[1],array('L','M','Q','H')))) { $mode[1] = 'L'; // Ddefault: Low error correction } $qrcode = new QRcode($code, strtoupper($mode[1])); $this->barcode_array = $qrcode->getBarcodeArray(); $this->barcode_array['code'] = $code; break; } case 'RAW': case 'RAW2': { // RAW MODE // remove spaces $code = preg_replace('/[\s]*/si', '', $code); if (strlen($code) < 3) { break; } if ($qrtype == 'RAW') { // comma-separated rows $rows = explode(',', $code); } else { // RAW2 // rows enclosed in square parentheses $code = substr($code, 1, -1); $rows = explode('][', $code); } $this->barcode_array['num_rows'] = count($rows); $this->barcode_array['num_cols'] = strlen($rows[0]); $this->barcode_array['bcode'] = array(); foreach ($rows as $r) { $this->barcode_array['bcode'][] = str_split($r, 1); } $this->barcode_array['code'] = $code; break; } case 'TEST': { // TEST MODE $this->barcode_array['num_rows'] = 5; $this->barcode_array['num_cols'] = 15; $this->barcode_array['bcode'] = array( array(1,1,1,0,1,1,1,0,1,1,1,0,1,1,1), array(0,1,0,0,1,0,0,0,1,0,0,0,0,1,0), array(0,1,0,0,1,1,0,0,1,1,1,0,0,1,0), array(0,1,0,0,1,0,0,0,0,0,1,0,0,1,0), array(0,1,0,0,1,1,1,0,1,1,1,0,0,1,0)); $this->barcode_array['code'] = $code; break; } default: { $this->barcode_array = array(); } } } } // end of class //============================================================+ // END OF FILE //============================================================+ PK!U README.mdnu[# TCPDF *PHP PDF Library* [![Donate via PayPal](https://img.shields.io/badge/donate-paypal-87ceeb.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations¤cy_code=GBP&business=paypal@tecnick.com&item_name=donation%20for%20TCPDF%20project) *Please consider supporting this project by making a donation via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_donations¤cy_code=GBP&business=paypal@tecnick.com&item_name=donation%20for%20TCPDF%20project)* * **category** Library * **author** Nicola Asuni * **copyright** 2002-2024 Nicola Asuni - Tecnick.com LTD * **license** http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) * **link** http://www.tcpdf.org * **source** https://github.com/tecnickcom/TCPDF ## NOTE A new version of this library is under development at https://github.com/tecnickcom/tc-lib-pdf and as a consequence this library is in support only mode. ## Description PHP library for generating PDF documents on-the-fly. ### Main Features: * no external libraries are required for the basic functions; * all standard page formats, custom page formats, custom margins and units of measure; * UTF-8 Unicode and Right-To-Left languages; * TrueTypeUnicode, OpenTypeUnicode v1, TrueType, OpenType v1, Type1 and CID-0 fonts; * font subsetting; * methods to publish some XHTML + CSS code, Javascript and Forms; * images, graphic (geometric figures) and transformation methods; * supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http://www.imagemagick.org/script/formats.php) * 1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extension, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417; * JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies; * automatic page header and footer management; * document encryption up to 256 bit and digital signature certifications; * transactions to UNDO commands; * PDF annotations, including links, text and file attachments; * text rendering modes (fill, stroke and clipping); * multiple columns mode; * no-write page regions; * bookmarks, named destinations and table of content; * text hyphenation; * text stretching and spacing (tracking); * automatic page break, line break and text alignments including justification; * automatic page numbering and page groups; * move and delete pages; * page compression (requires php-zlib extension); * XOBject Templates; * Layers and object visibility. * PDF/A-1b support. ### Third party fonts: This library may include third party font files released with different licenses. All the PHP files on the fonts directory are subject to the general TCPDF license (GNU-LGPLv3), they do not contain any binary data but just a description of the general properties of a particular font. These files can be also generated on the fly using the font utilities and TCPDF methods. All the original binary TTF font files have been renamed for compatibility with TCPDF and compressed using the gzcompress PHP function that uses the ZLIB data format (.z files). The binary files (.z) that begins with the prefix "free" have been extracted from the GNU FreeFont collection (GNU-GPLv3). The binary files (.z) that begins with the prefix "pdfa" have been derived from the GNU FreeFont, so they are subject to the same license. For the details of Copyright, License and other information, please check the files inside the directory fonts/freefont-20120503 Link : http://www.gnu.org/software/freefont/ The binary files (.z) that begins with the prefix "dejavu" have been extracted from the DejaVu fonts 2.33 (Bitstream) collection. For the details of Copyright, License and other information, please check the files inside the directory fonts/dejavu-fonts-ttf-2.33 Link : http://dejavu-fonts.org The binary files (.z) that begins with the prefix "ae" have been extracted from the Arabeyes.org collection (GNU-GPLv2). Link : http://projects.arabeyes.org/ ### ICC profile: TCPDF includes the sRGB.icc profile from the icc-profiles-free Debian package: https://packages.debian.org/source/stable/icc-profiles-free ## Developer(s) Contact * Nicola Asuni PK!Eyx[[tcpdf_barcodes_1d.phpnu[. // // See LICENSE.TXT file for more information. // ------------------------------------------------------------------- // // Description : PHP class to creates array representations for // common 1D barcodes to be used with TCPDF. // //============================================================+ /** * @file * PHP class to creates array representations for common 1D barcodes to be used with TCPDF. * @package com.tecnick.tcpdf * @author Nicola Asuni * @version 1.0.027 */ /** * @class TCPDFBarcode * PHP class to creates array representations for common 1D barcodes to be used with TCPDF (http://www.tcpdf.org).
* @package com.tecnick.tcpdf * @version 1.0.027 * @author Nicola Asuni */ class TCPDFBarcode { /** * Array representation of barcode. * @protected */ protected $barcode_array = array(); /** * This is the class constructor. * Return an array representations for common 1D barcodes:
    *
  • $arrcode['code'] code to be printed on text label
  • *
  • $arrcode['maxh'] max barcode height
  • *
  • $arrcode['maxw'] max barcode width
  • *
  • $arrcode['bcode'][$k] single bar or space in $k position
  • *
  • $arrcode['bcode'][$k]['t'] bar type: true = bar, false = space.
  • *
  • $arrcode['bcode'][$k]['w'] bar width in units.
  • *
  • $arrcode['bcode'][$k]['h'] bar height in units.
  • *
  • $arrcode['bcode'][$k]['p'] bar top position (0 = top, 1 = middle)
* @param string $code code to print * @param string $type type of barcode:
  • C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
  • C39+ : CODE 39 with checksum
  • C39E : CODE 39 EXTENDED
  • C39E+ : CODE 39 EXTENDED + CHECKSUM
  • C93 : CODE 93 - USS-93
  • S25 : Standard 2 of 5
  • S25+ : Standard 2 of 5 + CHECKSUM
  • I25 : Interleaved 2 of 5
  • I25+ : Interleaved 2 of 5 + CHECKSUM
  • C128 : CODE 128
  • C128A : CODE 128 A
  • C128B : CODE 128 B
  • C128C : CODE 128 C
  • EAN2 : 2-Digits UPC-Based Extension
  • EAN5 : 5-Digits UPC-Based Extension
  • EAN8 : EAN 8
  • EAN13 : EAN 13
  • UPCA : UPC-A
  • UPCE : UPC-E
  • MSI : MSI (Variation of Plessey code)
  • MSI+ : MSI + CHECKSUM (modulo 11)
  • POSTNET : POSTNET
  • PLANET : PLANET
  • RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
  • KIX : KIX (Klant index - Customer index)
  • IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200
  • CODABAR : CODABAR
  • CODE11 : CODE 11
  • PHARMA : PHARMACODE
  • PHARMA2T : PHARMACODE TWO-TRACKS
* @public */ public function __construct($code, $type) { $this->setBarcode($code, $type); } /** * Return an array representations of barcode. * @return array * @public */ public function getBarcodeArray() { return $this->barcode_array; } /** * Send barcode as SVG image object to the standard output. * @param int $w Minimum width of a single bar in user units. * @param int $h Height of barcode in user units. * @param string $color Foreground color (in SVG format) for bar elements (background is transparent). * @public */ public function getBarcodeSVG($w=2, $h=30, $color='black') { // send headers $code = $this->getBarcodeSVGcode($w, $h, $color); header('Content-Type: application/svg+xml'); header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 header('Pragma: public'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); header('Content-Disposition: inline; filename="'.md5($code).'.svg";'); //header('Content-Length: '.strlen($code)); echo $code; } /** * Return a SVG string representation of barcode. * @param int $w Minimum width of a single bar in user units. * @param int $h Height of barcode in user units. * @param string $color Foreground color (in SVG format) for bar elements (background is transparent). * @return string SVG code. * @public */ public function getBarcodeSVGcode($w=2, $h=30, $color='black') { // replace table for special characters $repstr = array("\0" => '', '&' => '&', '<' => '<', '>' => '>'); $svg = '<'.'?'.'xml version="1.0" standalone="no"'.'?'.'>'."\n"; $svg .= ''."\n"; $svg .= ''."\n"; $svg .= "\t".''.strtr($this->barcode_array['code'], $repstr).''."\n"; $svg .= "\t".''."\n"; // print bars $x = 0; foreach ($this->barcode_array['bcode'] as $k => $v) { $bw = round(($v['w'] * $w), 3); $bh = round(($v['h'] * $h / $this->barcode_array['maxh']), 3); if ($v['t']) { $y = round(($v['p'] * $h / $this->barcode_array['maxh']), 3); // draw a vertical bar $svg .= "\t\t".''."\n"; } $x += $bw; } $svg .= "\t".''."\n"; $svg .= ''."\n"; return $svg; } /** * Return an HTML representation of barcode. * @param int $w Width of a single bar element in pixels. * @param int $h Height of a single bar element in pixels. * @param string $color Foreground color for bar elements (background is transparent). * @return string HTML code. * @public */ public function getBarcodeHTML($w=2, $h=30, $color='black') { $html = '
'."\n"; // print bars $x = 0; foreach ($this->barcode_array['bcode'] as $k => $v) { $bw = round(($v['w'] * $w), 3); $bh = round(($v['h'] * $h / $this->barcode_array['maxh']), 3); if ($v['t']) { $y = round(($v['p'] * $h / $this->barcode_array['maxh']), 3); // draw a vertical bar $html .= '
 
'."\n"; } $x += $bw; } $html .= '
'."\n"; return $html; } /** * Send a PNG image representation of barcode (requires GD or Imagick library). * @param int $w Width of a single bar element in pixels. * @param int $h Height of a single bar element in pixels. * @param array $color RGB (0-255) foreground color for bar elements (background is transparent). * @public */ public function getBarcodePNG($w=2, $h=30, $color=array(0,0,0)) { $data = $this->getBarcodePngData($w, $h, $color); // send headers header('Content-Type: image/png'); header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 header('Pragma: public'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); //header('Content-Length: '.strlen($data)); echo $data; } /** * Return a PNG image representation of barcode (requires GD or Imagick library). * @param int $w Width of a single bar element in pixels. * @param int $h Height of a single bar element in pixels. * @param array $color RGB (0-255) foreground color for bar elements (background is transparent). * @return string|Imagick|false image or false in case of error. * @public */ public function getBarcodePngData($w=2, $h=30, $color=array(0,0,0)) { // calculate image size $width = ($this->barcode_array['maxw'] * $w); $height = $h; if (function_exists('imagecreate')) { // GD library $imagick = false; $png = imagecreate($width, $height); $bgcol = imagecolorallocate($png, 255, 255, 255); imagecolortransparent($png, $bgcol); $fgcol = imagecolorallocate($png, $color[0], $color[1], $color[2]); } elseif (extension_loaded('imagick')) { $imagick = true; $bgcol = new imagickpixel('rgb(255,255,255'); $fgcol = new imagickpixel('rgb('.$color[0].','.$color[1].','.$color[2].')'); $png = new Imagick(); $png->newImage($width, $height, 'none', 'png'); $bar = new imagickdraw(); $bar->setfillcolor($fgcol); } else { return false; } // print bars $x = 0; foreach ($this->barcode_array['bcode'] as $k => $v) { $bw = round(($v['w'] * $w), 3); $bh = round(($v['h'] * $h / $this->barcode_array['maxh']), 3); if ($v['t']) { $y = round(($v['p'] * $h / $this->barcode_array['maxh']), 3); // draw a vertical bar if ($imagick) { $bar->rectangle($x, $y, ($x + $bw - 1), ($y + $bh - 1)); } else { imagefilledrectangle($png, $x, $y, ($x + $bw - 1), ($y + $bh - 1), $fgcol); } } $x += $bw; } if ($imagick) { $png->drawimage($bar); return $png; } else { ob_start(); imagepng($png); $imagedata = ob_get_clean(); imagedestroy($png); return $imagedata; } } /** * Set the barcode. * @param string $code code to print * @param string $type type of barcode:
  • C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
  • C39+ : CODE 39 with checksum
  • C39E : CODE 39 EXTENDED
  • C39E+ : CODE 39 EXTENDED + CHECKSUM
  • C93 : CODE 93 - USS-93
  • S25 : Standard 2 of 5
  • S25+ : Standard 2 of 5 + CHECKSUM
  • I25 : Interleaved 2 of 5
  • I25+ : Interleaved 2 of 5 + CHECKSUM
  • C128 : CODE 128
  • C128A : CODE 128 A
  • C128B : CODE 128 B
  • C128C : CODE 128 C
  • EAN2 : 2-Digits UPC-Based Extension
  • EAN5 : 5-Digits UPC-Based Extension
  • EAN8 : EAN 8
  • EAN13 : EAN 13
  • UPCA : UPC-A
  • UPCE : UPC-E
  • MSI : MSI (Variation of Plessey code)
  • MSI+ : MSI + CHECKSUM (modulo 11)
  • POSTNET : POSTNET
  • PLANET : PLANET
  • RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
  • KIX : KIX (Klant index - Customer index)
  • IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200
  • IMBPRE: Pre-processed Intelligent Mail Barcode - Onecode - USPS-B-3200, using only F,A,D,T letters
  • CODABAR : CODABAR
  • CODE11 : CODE 11
  • PHARMA : PHARMACODE
  • PHARMA2T : PHARMACODE TWO-TRACKS
* @return void * @public */ public function setBarcode($code, $type) { switch (strtoupper($type)) { case 'C39': { // CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9. $arrcode = $this->barcode_code39($code, false, false); break; } case 'C39+': { // CODE 39 with checksum $arrcode = $this->barcode_code39($code, false, true); break; } case 'C39E': { // CODE 39 EXTENDED $arrcode = $this->barcode_code39($code, true, false); break; } case 'C39E+': { // CODE 39 EXTENDED + CHECKSUM $arrcode = $this->barcode_code39($code, true, true); break; } case 'C93': { // CODE 93 - USS-93 $arrcode = $this->barcode_code93($code); break; } case 'S25': { // Standard 2 of 5 $arrcode = $this->barcode_s25($code, false); break; } case 'S25+': { // Standard 2 of 5 + CHECKSUM $arrcode = $this->barcode_s25($code, true); break; } case 'I25': { // Interleaved 2 of 5 $arrcode = $this->barcode_i25($code, false); break; } case 'I25+': { // Interleaved 2 of 5 + CHECKSUM $arrcode = $this->barcode_i25($code, true); break; } case 'C128': { // CODE 128 $arrcode = $this->barcode_c128($code, ''); break; } case 'C128A': { // CODE 128 A $arrcode = $this->barcode_c128($code, 'A'); break; } case 'C128B': { // CODE 128 B $arrcode = $this->barcode_c128($code, 'B'); break; } case 'C128C': { // CODE 128 C $arrcode = $this->barcode_c128($code, 'C'); break; } case 'EAN2': { // 2-Digits UPC-Based Extension $arrcode = $this->barcode_eanext($code, 2); break; } case 'EAN5': { // 5-Digits UPC-Based Extension $arrcode = $this->barcode_eanext($code, 5); break; } case 'EAN8': { // EAN 8 $arrcode = $this->barcode_eanupc($code, 8); break; } case 'EAN13': { // EAN 13 $arrcode = $this->barcode_eanupc($code, 13); break; } case 'UPCA': { // UPC-A $arrcode = $this->barcode_eanupc($code, 12); break; } case 'UPCE': { // UPC-E $arrcode = $this->barcode_eanupc($code, 6); break; } case 'MSI': { // MSI (Variation of Plessey code) $arrcode = $this->barcode_msi($code, false); break; } case 'MSI+': { // MSI + CHECKSUM (modulo 11) $arrcode = $this->barcode_msi($code, true); break; } case 'POSTNET': { // POSTNET $arrcode = $this->barcode_postnet($code, false); break; } case 'PLANET': { // PLANET $arrcode = $this->barcode_postnet($code, true); break; } case 'RMS4CC': { // RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code) $arrcode = $this->barcode_rms4cc($code, false); break; } case 'KIX': { // KIX (Klant index - Customer index) $arrcode = $this->barcode_rms4cc($code, true); break; } case 'IMB': { // IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200 $arrcode = $this->barcode_imb($code); break; } case 'IMBPRE': { // IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200- pre-processed $arrcode = $this->barcode_imb_pre($code); break; } case 'CODABAR': { // CODABAR $arrcode = $this->barcode_codabar($code); break; } case 'CODE11': { // CODE 11 $arrcode = $this->barcode_code11($code); break; } case 'PHARMA': { // PHARMACODE $arrcode = $this->barcode_pharmacode($code); break; } case 'PHARMA2T': { // PHARMACODE TWO-TRACKS $arrcode = $this->barcode_pharmacode2t($code); break; } default: { $this->barcode_array = array(); $arrcode = false; break; } } $this->barcode_array = $arrcode; } /** * CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9. * General-purpose code in very wide use world-wide * @param string $code code to represent. * @param boolean $extended if true uses the extended mode. * @param boolean $checksum if true add a checksum to the code. * @return array barcode representation. * @protected */ protected function barcode_code39($code, $extended=false, $checksum=false) { $chr['0'] = '111331311'; $chr['1'] = '311311113'; $chr['2'] = '113311113'; $chr['3'] = '313311111'; $chr['4'] = '111331113'; $chr['5'] = '311331111'; $chr['6'] = '113331111'; $chr['7'] = '111311313'; $chr['8'] = '311311311'; $chr['9'] = '113311311'; $chr['A'] = '311113113'; $chr['B'] = '113113113'; $chr['C'] = '313113111'; $chr['D'] = '111133113'; $chr['E'] = '311133111'; $chr['F'] = '113133111'; $chr['G'] = '111113313'; $chr['H'] = '311113311'; $chr['I'] = '113113311'; $chr['J'] = '111133311'; $chr['K'] = '311111133'; $chr['L'] = '113111133'; $chr['M'] = '313111131'; $chr['N'] = '111131133'; $chr['O'] = '311131131'; $chr['P'] = '113131131'; $chr['Q'] = '111111333'; $chr['R'] = '311111331'; $chr['S'] = '113111331'; $chr['T'] = '111131331'; $chr['U'] = '331111113'; $chr['V'] = '133111113'; $chr['W'] = '333111111'; $chr['X'] = '131131113'; $chr['Y'] = '331131111'; $chr['Z'] = '133131111'; $chr['-'] = '131111313'; $chr['.'] = '331111311'; $chr[' '] = '133111311'; $chr['$'] = '131313111'; $chr['/'] = '131311131'; $chr['+'] = '131113131'; $chr['%'] = '111313131'; $chr['*'] = '131131311'; $code = strtoupper($code); if ($extended) { // extended mode $code = $this->encode_code39_ext($code); } if ($code === false) { return false; } if ($checksum) { // checksum $code .= $this->checksum_code39($code); } // add start and stop codes $code = '*'.$code.'*'; $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); $k = 0; $clen = strlen($code); for ($i = 0; $i < $clen; ++$i) { $char = $code[$i]; if(!isset($chr[$char])) { // invalid character return false; } for ($j = 0; $j < 9; ++$j) { if (($j % 2) == 0) { $t = true; // bar } else { $t = false; // space } $w = $chr[$char][$j]; $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); $bararray['maxw'] += $w; ++$k; } // intercharacter gap $bararray['bcode'][$k] = array('t' => false, 'w' => 1, 'h' => 1, 'p' => 0); $bararray['maxw'] += 1; ++$k; } return $bararray; } /** * Encode a string to be used for CODE 39 Extended mode. * @param string $code code to represent. * @return string encoded string. * @protected */ protected function encode_code39_ext($code) { $encode = array( chr(0) => '%U', chr(1) => '$A', chr(2) => '$B', chr(3) => '$C', chr(4) => '$D', chr(5) => '$E', chr(6) => '$F', chr(7) => '$G', chr(8) => '$H', chr(9) => '$I', chr(10) => '$J', chr(11) => '£K', chr(12) => '$L', chr(13) => '$M', chr(14) => '$N', chr(15) => '$O', chr(16) => '$P', chr(17) => '$Q', chr(18) => '$R', chr(19) => '$S', chr(20) => '$T', chr(21) => '$U', chr(22) => '$V', chr(23) => '$W', chr(24) => '$X', chr(25) => '$Y', chr(26) => '$Z', chr(27) => '%A', chr(28) => '%B', chr(29) => '%C', chr(30) => '%D', chr(31) => '%E', chr(32) => ' ', chr(33) => '/A', chr(34) => '/B', chr(35) => '/C', chr(36) => '/D', chr(37) => '/E', chr(38) => '/F', chr(39) => '/G', chr(40) => '/H', chr(41) => '/I', chr(42) => '/J', chr(43) => '/K', chr(44) => '/L', chr(45) => '-', chr(46) => '.', chr(47) => '/O', chr(48) => '0', chr(49) => '1', chr(50) => '2', chr(51) => '3', chr(52) => '4', chr(53) => '5', chr(54) => '6', chr(55) => '7', chr(56) => '8', chr(57) => '9', chr(58) => '/Z', chr(59) => '%F', chr(60) => '%G', chr(61) => '%H', chr(62) => '%I', chr(63) => '%J', chr(64) => '%V', chr(65) => 'A', chr(66) => 'B', chr(67) => 'C', chr(68) => 'D', chr(69) => 'E', chr(70) => 'F', chr(71) => 'G', chr(72) => 'H', chr(73) => 'I', chr(74) => 'J', chr(75) => 'K', chr(76) => 'L', chr(77) => 'M', chr(78) => 'N', chr(79) => 'O', chr(80) => 'P', chr(81) => 'Q', chr(82) => 'R', chr(83) => 'S', chr(84) => 'T', chr(85) => 'U', chr(86) => 'V', chr(87) => 'W', chr(88) => 'X', chr(89) => 'Y', chr(90) => 'Z', chr(91) => '%K', chr(92) => '%L', chr(93) => '%M', chr(94) => '%N', chr(95) => '%O', chr(96) => '%W', chr(97) => '+A', chr(98) => '+B', chr(99) => '+C', chr(100) => '+D', chr(101) => '+E', chr(102) => '+F', chr(103) => '+G', chr(104) => '+H', chr(105) => '+I', chr(106) => '+J', chr(107) => '+K', chr(108) => '+L', chr(109) => '+M', chr(110) => '+N', chr(111) => '+O', chr(112) => '+P', chr(113) => '+Q', chr(114) => '+R', chr(115) => '+S', chr(116) => '+T', chr(117) => '+U', chr(118) => '+V', chr(119) => '+W', chr(120) => '+X', chr(121) => '+Y', chr(122) => '+Z', chr(123) => '%P', chr(124) => '%Q', chr(125) => '%R', chr(126) => '%S', chr(127) => '%T'); $code_ext = ''; $clen = strlen($code); for ($i = 0 ; $i < $clen; ++$i) { if (ord($code[$i]) > 127) { return false; } $code_ext .= $encode[$code[$i]]; } return $code_ext; } /** * Calculate CODE 39 checksum (modulo 43). * @param string $code code to represent. * @return string char checksum. * @protected */ protected function checksum_code39($code) { $chars = array( '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%'); $sum = 0; $clen = strlen($code); for ($i = 0 ; $i < $clen; ++$i) { $k = array_keys($chars, $code[$i]); $sum += $k[0]; } $j = ($sum % 43); return $chars[$j]; } /** * CODE 93 - USS-93 * Compact code similar to Code 39 * @param string $code code to represent. * @return array barcode representation. * @protected */ protected function barcode_code93($code) { $chr[48] = '131112'; // 0 $chr[49] = '111213'; // 1 $chr[50] = '111312'; // 2 $chr[51] = '111411'; // 3 $chr[52] = '121113'; // 4 $chr[53] = '121212'; // 5 $chr[54] = '121311'; // 6 $chr[55] = '111114'; // 7 $chr[56] = '131211'; // 8 $chr[57] = '141111'; // 9 $chr[65] = '211113'; // A $chr[66] = '211212'; // B $chr[67] = '211311'; // C $chr[68] = '221112'; // D $chr[69] = '221211'; // E $chr[70] = '231111'; // F $chr[71] = '112113'; // G $chr[72] = '112212'; // H $chr[73] = '112311'; // I $chr[74] = '122112'; // J $chr[75] = '132111'; // K $chr[76] = '111123'; // L $chr[77] = '111222'; // M $chr[78] = '111321'; // N $chr[79] = '121122'; // O $chr[80] = '131121'; // P $chr[81] = '212112'; // Q $chr[82] = '212211'; // R $chr[83] = '211122'; // S $chr[84] = '211221'; // T $chr[85] = '221121'; // U $chr[86] = '222111'; // V $chr[87] = '112122'; // W $chr[88] = '112221'; // X $chr[89] = '122121'; // Y $chr[90] = '123111'; // Z $chr[45] = '121131'; // - $chr[46] = '311112'; // . $chr[32] = '311211'; // $chr[36] = '321111'; // $ $chr[47] = '112131'; // / $chr[43] = '113121'; // + $chr[37] = '211131'; // % $chr[128] = '121221'; // ($) $chr[129] = '311121'; // (/) $chr[130] = '122211'; // (+) $chr[131] = '312111'; // (%) $chr[42] = '111141'; // start-stop $code = strtoupper($code); $encode = array( chr(0) => chr(131).'U', chr(1) => chr(128).'A', chr(2) => chr(128).'B', chr(3) => chr(128).'C', chr(4) => chr(128).'D', chr(5) => chr(128).'E', chr(6) => chr(128).'F', chr(7) => chr(128).'G', chr(8) => chr(128).'H', chr(9) => chr(128).'I', chr(10) => chr(128).'J', chr(11) => '£K', chr(12) => chr(128).'L', chr(13) => chr(128).'M', chr(14) => chr(128).'N', chr(15) => chr(128).'O', chr(16) => chr(128).'P', chr(17) => chr(128).'Q', chr(18) => chr(128).'R', chr(19) => chr(128).'S', chr(20) => chr(128).'T', chr(21) => chr(128).'U', chr(22) => chr(128).'V', chr(23) => chr(128).'W', chr(24) => chr(128).'X', chr(25) => chr(128).'Y', chr(26) => chr(128).'Z', chr(27) => chr(131).'A', chr(28) => chr(131).'B', chr(29) => chr(131).'C', chr(30) => chr(131).'D', chr(31) => chr(131).'E', chr(32) => ' ', chr(33) => chr(129).'A', chr(34) => chr(129).'B', chr(35) => chr(129).'C', chr(36) => chr(129).'D', chr(37) => chr(129).'E', chr(38) => chr(129).'F', chr(39) => chr(129).'G', chr(40) => chr(129).'H', chr(41) => chr(129).'I', chr(42) => chr(129).'J', chr(43) => chr(129).'K', chr(44) => chr(129).'L', chr(45) => '-', chr(46) => '.', chr(47) => chr(129).'O', chr(48) => '0', chr(49) => '1', chr(50) => '2', chr(51) => '3', chr(52) => '4', chr(53) => '5', chr(54) => '6', chr(55) => '7', chr(56) => '8', chr(57) => '9', chr(58) => chr(129).'Z', chr(59) => chr(131).'F', chr(60) => chr(131).'G', chr(61) => chr(131).'H', chr(62) => chr(131).'I', chr(63) => chr(131).'J', chr(64) => chr(131).'V', chr(65) => 'A', chr(66) => 'B', chr(67) => 'C', chr(68) => 'D', chr(69) => 'E', chr(70) => 'F', chr(71) => 'G', chr(72) => 'H', chr(73) => 'I', chr(74) => 'J', chr(75) => 'K', chr(76) => 'L', chr(77) => 'M', chr(78) => 'N', chr(79) => 'O', chr(80) => 'P', chr(81) => 'Q', chr(82) => 'R', chr(83) => 'S', chr(84) => 'T', chr(85) => 'U', chr(86) => 'V', chr(87) => 'W', chr(88) => 'X', chr(89) => 'Y', chr(90) => 'Z', chr(91) => chr(131).'K', chr(92) => chr(131).'L', chr(93) => chr(131).'M', chr(94) => chr(131).'N', chr(95) => chr(131).'O', chr(96) => chr(131).'W', chr(97) => chr(130).'A', chr(98) => chr(130).'B', chr(99) => chr(130).'C', chr(100) => chr(130).'D', chr(101) => chr(130).'E', chr(102) => chr(130).'F', chr(103) => chr(130).'G', chr(104) => chr(130).'H', chr(105) => chr(130).'I', chr(106) => chr(130).'J', chr(107) => chr(130).'K', chr(108) => chr(130).'L', chr(109) => chr(130).'M', chr(110) => chr(130).'N', chr(111) => chr(130).'O', chr(112) => chr(130).'P', chr(113) => chr(130).'Q', chr(114) => chr(130).'R', chr(115) => chr(130).'S', chr(116) => chr(130).'T', chr(117) => chr(130).'U', chr(118) => chr(130).'V', chr(119) => chr(130).'W', chr(120) => chr(130).'X', chr(121) => chr(130).'Y', chr(122) => chr(130).'Z', chr(123) => chr(131).'P', chr(124) => chr(131).'Q', chr(125) => chr(131).'R', chr(126) => chr(131).'S', chr(127) => chr(131).'T'); $code_ext = ''; $clen = strlen($code); for ($i = 0 ; $i < $clen; ++$i) { if (ord($code[$i]) > 127) { return false; } $code_ext .= $encode[$code[$i]]; } // checksum $code_ext .= $this->checksum_code93($code_ext); // add start and stop codes $code = '*'.$code_ext.'*'; $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); $k = 0; $clen = strlen($code); for ($i = 0; $i < $clen; ++$i) { $char = ord($code[$i]); if(!isset($chr[$char])) { // invalid character return false; } for ($j = 0; $j < 6; ++$j) { if (($j % 2) == 0) { $t = true; // bar } else { $t = false; // space } $w = $chr[$char][$j]; $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); $bararray['maxw'] += $w; ++$k; } } $bararray['bcode'][$k] = array('t' => true, 'w' => 1, 'h' => 1, 'p' => 0); $bararray['maxw'] += 1; ++$k; return $bararray; } /** * Calculate CODE 93 checksum (modulo 47). * @param string $code code to represent. * @return string checksum code. * @protected */ protected function checksum_code93($code) { $chars = array( '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%', '<', '=', '>', '?'); // translate special characters $code = strtr($code, chr(128).chr(131).chr(129).chr(130), '<=>?'); $len = strlen($code); // calculate check digit C $p = 1; $check = 0; for ($i = ($len - 1); $i >= 0; --$i) { $k = array_keys($chars, $code[$i]); $check += ($k[0] * $p); ++$p; if ($p > 20) { $p = 1; } } $check %= 47; $c = $chars[$check]; $code .= $c; // calculate check digit K $p = 1; $check = 0; for ($i = $len; $i >= 0; --$i) { $k = array_keys($chars, $code[$i]); $check += ($k[0] * $p); ++$p; if ($p > 15) { $p = 1; } } $check %= 47; $k = $chars[$check]; $checksum = $c.$k; // resto respecial characters $checksum = strtr($checksum, '<=>?', chr(128).chr(131).chr(129).chr(130)); return $checksum; } /** * Checksum for standard 2 of 5 barcodes. * @param string $code code to process. * @return int checksum. * @protected */ protected function checksum_s25($code) { $len = strlen($code); $sum = 0; for ($i = 0; $i < $len; $i+=2) { $sum += $code[$i]; } $sum *= 3; for ($i = 1; $i < $len; $i+=2) { $sum += ($code[$i]); } $r = $sum % 10; if($r > 0) { $r = (10 - $r); } return $r; } /** * MSI. * Variation of Plessey code, with similar applications * Contains digits (0 to 9) and encodes the data only in the width of bars. * @param string $code code to represent. * @param boolean $checksum if true add a checksum to the code (modulo 11) * @return array barcode representation. * @protected */ protected function barcode_msi($code, $checksum=false) { $chr['0'] = '100100100100'; $chr['1'] = '100100100110'; $chr['2'] = '100100110100'; $chr['3'] = '100100110110'; $chr['4'] = '100110100100'; $chr['5'] = '100110100110'; $chr['6'] = '100110110100'; $chr['7'] = '100110110110'; $chr['8'] = '110100100100'; $chr['9'] = '110100100110'; $chr['A'] = '110100110100'; $chr['B'] = '110100110110'; $chr['C'] = '110110100100'; $chr['D'] = '110110100110'; $chr['E'] = '110110110100'; $chr['F'] = '110110110110'; if ($checksum) { // add checksum $clen = strlen($code); $p = 2; $check = 0; for ($i = ($clen - 1); $i >= 0; --$i) { $check += (hexdec($code[$i]) * $p); ++$p; if ($p > 7) { $p = 2; } } $check %= 11; if ($check > 0) { $check = 11 - $check; } $code .= $check; } $seq = '110'; // left guard $clen = strlen($code); for ($i = 0; $i < $clen; ++$i) { $digit = $code[$i]; if (!isset($chr[$digit])) { // invalid character return false; } $seq .= $chr[$digit]; } $seq .= '1001'; // right guard $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); return $this->binseq_to_array($seq, $bararray); } /** * Standard 2 of 5 barcodes. * Used in airline ticket marking, photofinishing * Contains digits (0 to 9) and encodes the data only in the width of bars. * @param string $code code to represent. * @param boolean $checksum if true add a checksum to the code * @return array barcode representation. * @protected */ protected function barcode_s25($code, $checksum=false) { $chr['0'] = '10101110111010'; $chr['1'] = '11101010101110'; $chr['2'] = '10111010101110'; $chr['3'] = '11101110101010'; $chr['4'] = '10101110101110'; $chr['5'] = '11101011101010'; $chr['6'] = '10111011101010'; $chr['7'] = '10101011101110'; $chr['8'] = '11101010111010'; $chr['9'] = '10111010111010'; if ($checksum) { // add checksum $code .= $this->checksum_s25($code); } if((strlen($code) % 2) != 0) { // add leading zero if code-length is odd $code = '0'.$code; } $seq = '1110111010'; $clen = strlen($code); for ($i = 0; $i < $clen; ++$i) { $digit = $code[$i]; if (!isset($chr[$digit])) { // invalid character return false; } $seq .= $chr[$digit]; } $seq .= '111010111'; $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); return $this->binseq_to_array($seq, $bararray); } /** * Convert binary barcode sequence to WarnockPDF barcode array. * @param string $seq barcode as binary sequence. * @param array $bararray barcode array to fill up * @return array barcode representation. * @protected */ protected function binseq_to_array($seq, $bararray) { $len = strlen($seq); $w = 0; $k = 0; for ($i = 0; $i < $len; ++$i) { $w += 1; if (($i == ($len - 1)) OR (($i < ($len - 1)) AND ($seq[$i] != $seq[($i+1)]))) { if ($seq[$i] == '1') { $t = true; // bar } else { $t = false; // space } $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); $bararray['maxw'] += $w; ++$k; $w = 0; } } return $bararray; } /** * Interleaved 2 of 5 barcodes. * Compact numeric code, widely used in industry, air cargo * Contains digits (0 to 9) and encodes the data in the width of both bars and spaces. * @param string $code code to represent. * @param boolean $checksum if true add a checksum to the code * @return array barcode representation. * @protected */ protected function barcode_i25($code, $checksum=false) { $chr['0'] = '11221'; $chr['1'] = '21112'; $chr['2'] = '12112'; $chr['3'] = '22111'; $chr['4'] = '11212'; $chr['5'] = '21211'; $chr['6'] = '12211'; $chr['7'] = '11122'; $chr['8'] = '21121'; $chr['9'] = '12121'; $chr['A'] = '11'; $chr['Z'] = '21'; if ($checksum) { // add checksum $code .= $this->checksum_s25($code); } if((strlen($code) % 2) != 0) { // add leading zero if code-length is odd $code = '0'.$code; } // add start and stop codes $code = 'AA'.strtolower($code).'ZA'; $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); $k = 0; $clen = strlen($code); for ($i = 0; $i < $clen; $i = ($i + 2)) { $char_bar = $code[$i]; $char_space = $code[$i+1]; if((!isset($chr[$char_bar])) OR (!isset($chr[$char_space]))) { // invalid character return false; } // create a bar-space sequence $seq = ''; $chrlen = strlen($chr[$char_bar]); for ($s = 0; $s < $chrlen; $s++){ $seq .= $chr[$char_bar][$s] . $chr[$char_space][$s]; } $seqlen = strlen($seq); for ($j = 0; $j < $seqlen; ++$j) { if (($j % 2) == 0) { $t = true; // bar } else { $t = false; // space } $w = (float)$seq[$j]; $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); $bararray['maxw'] += $w; ++$k; } } return $bararray; } /** * C128 barcodes. * Very capable code, excellent density, high reliability; in very wide use world-wide * @param string $code code to represent. * @param string $type barcode type: A, B, C or empty for automatic switch (AUTO mode) * @return array barcode representation. * @protected */ protected function barcode_c128($code, $type='') { $chr = array( '212222', /* 00 */ '222122', /* 01 */ '222221', /* 02 */ '121223', /* 03 */ '121322', /* 04 */ '131222', /* 05 */ '122213', /* 06 */ '122312', /* 07 */ '132212', /* 08 */ '221213', /* 09 */ '221312', /* 10 */ '231212', /* 11 */ '112232', /* 12 */ '122132', /* 13 */ '122231', /* 14 */ '113222', /* 15 */ '123122', /* 16 */ '123221', /* 17 */ '223211', /* 18 */ '221132', /* 19 */ '221231', /* 20 */ '213212', /* 21 */ '223112', /* 22 */ '312131', /* 23 */ '311222', /* 24 */ '321122', /* 25 */ '321221', /* 26 */ '312212', /* 27 */ '322112', /* 28 */ '322211', /* 29 */ '212123', /* 30 */ '212321', /* 31 */ '232121', /* 32 */ '111323', /* 33 */ '131123', /* 34 */ '131321', /* 35 */ '112313', /* 36 */ '132113', /* 37 */ '132311', /* 38 */ '211313', /* 39 */ '231113', /* 40 */ '231311', /* 41 */ '112133', /* 42 */ '112331', /* 43 */ '132131', /* 44 */ '113123', /* 45 */ '113321', /* 46 */ '133121', /* 47 */ '313121', /* 48 */ '211331', /* 49 */ '231131', /* 50 */ '213113', /* 51 */ '213311', /* 52 */ '213131', /* 53 */ '311123', /* 54 */ '311321', /* 55 */ '331121', /* 56 */ '312113', /* 57 */ '312311', /* 58 */ '332111', /* 59 */ '314111', /* 60 */ '221411', /* 61 */ '431111', /* 62 */ '111224', /* 63 */ '111422', /* 64 */ '121124', /* 65 */ '121421', /* 66 */ '141122', /* 67 */ '141221', /* 68 */ '112214', /* 69 */ '112412', /* 70 */ '122114', /* 71 */ '122411', /* 72 */ '142112', /* 73 */ '142211', /* 74 */ '241211', /* 75 */ '221114', /* 76 */ '413111', /* 77 */ '241112', /* 78 */ '134111', /* 79 */ '111242', /* 80 */ '121142', /* 81 */ '121241', /* 82 */ '114212', /* 83 */ '124112', /* 84 */ '124211', /* 85 */ '411212', /* 86 */ '421112', /* 87 */ '421211', /* 88 */ '212141', /* 89 */ '214121', /* 90 */ '412121', /* 91 */ '111143', /* 92 */ '111341', /* 93 */ '131141', /* 94 */ '114113', /* 95 */ '114311', /* 96 */ '411113', /* 97 */ '411311', /* 98 */ '113141', /* 99 */ '114131', /* 100 */ '311141', /* 101 */ '411131', /* 102 */ '211412', /* 103 START A */ '211214', /* 104 START B */ '211232', /* 105 START C */ '233111', /* STOP */ '200000' /* END */ ); // ASCII characters for code A (ASCII 00 - 95) $keys_a = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'; $keys_a .= chr(0).chr(1).chr(2).chr(3).chr(4).chr(5).chr(6).chr(7).chr(8).chr(9); $keys_a .= chr(10).chr(11).chr(12).chr(13).chr(14).chr(15).chr(16).chr(17).chr(18).chr(19); $keys_a .= chr(20).chr(21).chr(22).chr(23).chr(24).chr(25).chr(26).chr(27).chr(28).chr(29); $keys_a .= chr(30).chr(31); // ASCII characters for code B (ASCII 32 - 127) $keys_b = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'.chr(127); // special codes $fnc_a = array(241 => 102, 242 => 97, 243 => 96, 244 => 101); $fnc_b = array(241 => 102, 242 => 97, 243 => 96, 244 => 100); // array of symbols $code_data = array(); // length of the code $len = strlen($code); switch(strtoupper($type)) { case 'A': { // MODE A $startid = 103; for ($i = 0; $i < $len; ++$i) { $char = $code[$i]; $char_id = ord($char); if (($char_id >= 241) AND ($char_id <= 244)) { $code_data[] = $fnc_a[$char_id]; } elseif (($char_id >= 0) AND ($char_id <= 95)) { $code_data[] = strpos($keys_a, $char); } else { return false; } } break; } case 'B': { // MODE B $startid = 104; for ($i = 0; $i < $len; ++$i) { $char = $code[$i]; $char_id = ord($char); if (($char_id >= 241) AND ($char_id <= 244)) { $code_data[] = $fnc_b[$char_id]; } elseif (($char_id >= 32) AND ($char_id <= 127)) { $code_data[] = strpos($keys_b, $char); } else { return false; } } break; } case 'C': { // MODE C $startid = 105; if (ord($code[0]) == 241) { $code_data[] = 102; $code = substr($code, 1); --$len; } if (($len % 2) != 0) { // the length must be even return false; } for ($i = 0; $i < $len; $i+=2) { $chrnum = $code[$i].$code[$i+1]; if (preg_match('/([0-9]{2})/', $chrnum) > 0) { $code_data[] = intval($chrnum); } else { return false; } } break; } default: { // MODE AUTO // split code into sequences $sequence = array(); // get numeric sequences (if any) $numseq = array(); preg_match_all('/([0-9]{4,})/', $code, $numseq, PREG_OFFSET_CAPTURE); if (isset($numseq[1]) AND !empty($numseq[1])) { $end_offset = 0; foreach ($numseq[1] as $val) { $offset = $val[1]; if ($offset > $end_offset) { // non numeric sequence $sequence = array_merge($sequence, $this->get128ABsequence(substr($code, $end_offset, ($offset - $end_offset)))); } // numeric sequence $slen = strlen($val[0]); if (($slen % 2) != 0) { // the length must be even --$slen; } $sequence[] = array('C', substr($code, $offset, $slen), $slen); $end_offset = $offset + $slen; } if ($end_offset < $len) { $sequence = array_merge($sequence, $this->get128ABsequence(substr($code, $end_offset))); } } else { // text code (non C mode) $sequence = array_merge($sequence, $this->get128ABsequence($code)); } // process the sequence foreach ($sequence as $key => $seq) { switch($seq[0]) { case 'A': { if ($key == 0) { $startid = 103; } elseif ($sequence[($key - 1)][0] != 'A') { if (($seq[2] == 1) AND ($key > 0) AND ($sequence[($key - 1)][0] == 'B') AND (!isset($sequence[($key - 1)][3]))) { // single character shift $code_data[] = 98; // mark shift $sequence[$key][3] = true; } elseif (!isset($sequence[($key - 1)][3])) { $code_data[] = 101; } } for ($i = 0; $i < $seq[2]; ++$i) { $char = $seq[1][$i]; $char_id = ord($char); if (($char_id >= 241) AND ($char_id <= 244)) { $code_data[] = $fnc_a[$char_id]; } else { $code_data[] = strpos($keys_a, $char); } } break; } case 'B': { if ($key == 0) { $tmpchr = ord($seq[1][0]); if (($seq[2] == 1) AND ($tmpchr >= 241) AND ($tmpchr <= 244) AND isset($sequence[($key + 1)]) AND ($sequence[($key + 1)][0] != 'B')) { switch ($sequence[($key + 1)][0]) { case 'A': { $startid = 103; $sequence[$key][0] = 'A'; $code_data[] = $fnc_a[$tmpchr]; break; } case 'C': { $startid = 105; $sequence[$key][0] = 'C'; $code_data[] = $fnc_a[$tmpchr]; break; } } break; } else { $startid = 104; } } elseif ($sequence[($key - 1)][0] != 'B') { if (($seq[2] == 1) AND ($key > 0) AND ($sequence[($key - 1)][0] == 'A') AND (!isset($sequence[($key - 1)][3]))) { // single character shift $code_data[] = 98; // mark shift $sequence[$key][3] = true; } elseif (!isset($sequence[($key - 1)][3])) { $code_data[] = 100; } } for ($i = 0; $i < $seq[2]; ++$i) { $char = $seq[1][$i]; $char_id = ord($char); if (($char_id >= 241) AND ($char_id <= 244)) { $code_data[] = $fnc_b[$char_id]; } else { $code_data[] = strpos($keys_b, $char); } } break; } case 'C': { if ($key == 0) { $startid = 105; } elseif ($sequence[($key - 1)][0] != 'C') { $code_data[] = 99; } for ($i = 0; $i < $seq[2]; $i+=2) { $chrnum = $seq[1][$i].$seq[1][$i+1]; $code_data[] = intval($chrnum); } break; } } } } } // calculate check character $sum = $startid; foreach ($code_data as $key => $val) { $sum += ($val * ($key + 1)); } // add check character $code_data[] = ($sum % 103); // add stop sequence $code_data[] = 106; $code_data[] = 107; // add start code at the beginning array_unshift($code_data, $startid); // build barcode array $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); foreach ($code_data as $val) { $seq = $chr[$val]; for ($j = 0; $j < 6; ++$j) { if (($j % 2) == 0) { $t = true; // bar } else { $t = false; // space } $w = (float)$seq[$j]; $bararray['bcode'][] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); $bararray['maxw'] += $w; } } return $bararray; } /** * Split text code in A/B sequence for 128 code * @param string $code code to split. * @return array sequence * @protected */ protected function get128ABsequence($code) { $len = strlen($code); $sequence = array(); // get A sequences (if any) $numseq = array(); preg_match_all('/([\0-\31])/', $code, $numseq, PREG_OFFSET_CAPTURE); if (isset($numseq[1]) AND !empty($numseq[1])) { $end_offset = 0; foreach ($numseq[1] as $val) { $offset = $val[1]; if ($offset > $end_offset) { // B sequence $sequence[] = array('B', substr($code, $end_offset, ($offset - $end_offset)), ($offset - $end_offset)); } // A sequence $slen = strlen($val[0]); $sequence[] = array('A', substr($code, $offset, $slen), $slen); $end_offset = $offset + $slen; } if ($end_offset < $len) { $sequence[] = array('B', substr($code, $end_offset), ($len - $end_offset)); } } else { // only B sequence $sequence[] = array('B', $code, $len); } return $sequence; } /** * EAN13 and UPC-A barcodes. * EAN13: European Article Numbering international retail product code * UPC-A: Universal product code seen on almost all retail products in the USA and Canada * UPC-E: Short version of UPC symbol * @param string $code code to represent. * @param string $len barcode type: 6 = UPC-E, 8 = EAN8, 13 = EAN13, 12 = UPC-A * @return array barcode representation. * @protected */ protected function barcode_eanupc($code, $len=13) { $upce = false; if ($len == 6) { $len = 12; // UPC-A $upce = true; // UPC-E mode } $data_len = $len - 1; //Padding $code = str_pad($code, $data_len, '0', STR_PAD_LEFT); $code_len = strlen($code); // calculate check digit $sum_a = 0; for ($i = 1; $i < $data_len; $i+=2) { $sum_a += $code[$i]; } if ($len > 12) { $sum_a *= 3; } $sum_b = 0; for ($i = 0; $i < $data_len; $i+=2) { $sum_b += ($code[$i]); } if ($len < 13) { $sum_b *= 3; } $r = ($sum_a + $sum_b) % 10; if($r > 0) { $r = (10 - $r); } if ($code_len == $data_len) { // add check digit $code .= $r; } elseif ($r !== intval($code[$data_len])) { // wrong checkdigit return false; } if ($len == 12) { // UPC-A $code = '0'.$code; ++$len; } if ($upce) { // convert UPC-A to UPC-E $tmp = substr($code, 4, 3); if (($tmp == '000') OR ($tmp == '100') OR ($tmp == '200')) { // manufacturer code ends in 000, 100, or 200 $upce_code = substr($code, 2, 2).substr($code, 9, 3).substr($code, 4, 1); } else { $tmp = substr($code, 5, 2); if ($tmp == '00') { // manufacturer code ends in 00 $upce_code = substr($code, 2, 3).substr($code, 10, 2).'3'; } else { $tmp = substr($code, 6, 1); if ($tmp == '0') { // manufacturer code ends in 0 $upce_code = substr($code, 2, 4).substr($code, 11, 1).'4'; } else { // manufacturer code does not end in zero $upce_code = substr($code, 2, 5).substr($code, 11, 1); } } } } //Convert digits to bars $codes = array( 'A'=>array( // left odd parity '0'=>'0001101', '1'=>'0011001', '2'=>'0010011', '3'=>'0111101', '4'=>'0100011', '5'=>'0110001', '6'=>'0101111', '7'=>'0111011', '8'=>'0110111', '9'=>'0001011'), 'B'=>array( // left even parity '0'=>'0100111', '1'=>'0110011', '2'=>'0011011', '3'=>'0100001', '4'=>'0011101', '5'=>'0111001', '6'=>'0000101', '7'=>'0010001', '8'=>'0001001', '9'=>'0010111'), 'C'=>array( // right '0'=>'1110010', '1'=>'1100110', '2'=>'1101100', '3'=>'1000010', '4'=>'1011100', '5'=>'1001110', '6'=>'1010000', '7'=>'1000100', '8'=>'1001000', '9'=>'1110100') ); $parities = array( '0'=>array('A','A','A','A','A','A'), '1'=>array('A','A','B','A','B','B'), '2'=>array('A','A','B','B','A','B'), '3'=>array('A','A','B','B','B','A'), '4'=>array('A','B','A','A','B','B'), '5'=>array('A','B','B','A','A','B'), '6'=>array('A','B','B','B','A','A'), '7'=>array('A','B','A','B','A','B'), '8'=>array('A','B','A','B','B','A'), '9'=>array('A','B','B','A','B','A') ); $upce_parities = array(); $upce_parities[0] = array( '0'=>array('B','B','B','A','A','A'), '1'=>array('B','B','A','B','A','A'), '2'=>array('B','B','A','A','B','A'), '3'=>array('B','B','A','A','A','B'), '4'=>array('B','A','B','B','A','A'), '5'=>array('B','A','A','B','B','A'), '6'=>array('B','A','A','A','B','B'), '7'=>array('B','A','B','A','B','A'), '8'=>array('B','A','B','A','A','B'), '9'=>array('B','A','A','B','A','B') ); $upce_parities[1] = array( '0'=>array('A','A','A','B','B','B'), '1'=>array('A','A','B','A','B','B'), '2'=>array('A','A','B','B','A','B'), '3'=>array('A','A','B','B','B','A'), '4'=>array('A','B','A','A','B','B'), '5'=>array('A','B','B','A','A','B'), '6'=>array('A','B','B','B','A','A'), '7'=>array('A','B','A','B','A','B'), '8'=>array('A','B','A','B','B','A'), '9'=>array('A','B','B','A','B','A') ); $k = 0; $seq = '101'; // left guard bar if ($upce) { $bararray = array('code' => $upce_code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); $p = $upce_parities[$code[1]][$r]; for ($i = 0; $i < 6; ++$i) { $seq .= $codes[$p[$i]][$upce_code[$i]]; } $seq .= '010101'; // right guard bar } else { $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); $half_len = intval(ceil($len / 2)); if ($len == 8) { for ($i = 0; $i < $half_len; ++$i) { $seq .= $codes['A'][$code[$i]]; } } else { $p = $parities[$code[0]]; for ($i = 1; $i < $half_len; ++$i) { $seq .= $codes[$p[$i-1]][$code[$i]]; } } $seq .= '01010'; // center guard bar for ($i = $half_len; $i < $len; ++$i) { $seq .= $codes['C'][$code[$i]]; } $seq .= '101'; // right guard bar } $clen = strlen($seq); $w = 0; for ($i = 0; $i < $clen; ++$i) { $w += 1; if (($i == ($clen - 1)) OR (($i < ($clen - 1)) AND ($seq[$i] != $seq[$i+1]))) { if ($seq[$i] == '1') { $t = true; // bar } else { $t = false; // space } $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); $bararray['maxw'] += $w; ++$k; $w = 0; } } return $bararray; } /** * UPC-Based Extensions * 2-Digit Ext.: Used to indicate magazines and newspaper issue numbers * 5-Digit Ext.: Used to mark suggested retail price of books * @param string $code code to represent. * @param string $len barcode type: 2 = 2-Digit, 5 = 5-Digit * @return array barcode representation. * @protected */ protected function barcode_eanext($code, $len=5) { //Padding $code = str_pad($code, $len, '0', STR_PAD_LEFT); // calculate check digit if ($len == 2) { $r = $code % 4; } elseif ($len == 5) { $r = (3 * ($code[0] + $code[2] + $code[4])) + (9 * ($code[1] + $code[3])); $r %= 10; } else { return false; } //Convert digits to bars $codes = array( 'A'=>array( // left odd parity '0'=>'0001101', '1'=>'0011001', '2'=>'0010011', '3'=>'0111101', '4'=>'0100011', '5'=>'0110001', '6'=>'0101111', '7'=>'0111011', '8'=>'0110111', '9'=>'0001011'), 'B'=>array( // left even parity '0'=>'0100111', '1'=>'0110011', '2'=>'0011011', '3'=>'0100001', '4'=>'0011101', '5'=>'0111001', '6'=>'0000101', '7'=>'0010001', '8'=>'0001001', '9'=>'0010111') ); $parities = array(); $parities[2] = array( '0'=>array('A','A'), '1'=>array('A','B'), '2'=>array('B','A'), '3'=>array('B','B') ); $parities[5] = array( '0'=>array('B','B','A','A','A'), '1'=>array('B','A','B','A','A'), '2'=>array('B','A','A','B','A'), '3'=>array('B','A','A','A','B'), '4'=>array('A','B','B','A','A'), '5'=>array('A','A','B','B','A'), '6'=>array('A','A','A','B','B'), '7'=>array('A','B','A','B','A'), '8'=>array('A','B','A','A','B'), '9'=>array('A','A','B','A','B') ); $p = $parities[$len][$r]; $seq = '1011'; // left guard bar $seq .= $codes[$p[0]][$code[0]]; for ($i = 1; $i < $len; ++$i) { $seq .= '01'; // separator $seq .= $codes[$p[$i]][$code[$i]]; } $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); return $this->binseq_to_array($seq, $bararray); } /** * POSTNET and PLANET barcodes. * Used by U.S. Postal Service for automated mail sorting * @param string $code zip code to represent. Must be a string containing a zip code of the form DDDDD or DDDDD-DDDD. * @param boolean $planet if true print the PLANET barcode, otherwise print POSTNET * @return array barcode representation. * @protected */ protected function barcode_postnet($code, $planet=false) { // bar length if ($planet) { $barlen = Array( 0 => Array(1,1,2,2,2), 1 => Array(2,2,2,1,1), 2 => Array(2,2,1,2,1), 3 => Array(2,2,1,1,2), 4 => Array(2,1,2,2,1), 5 => Array(2,1,2,1,2), 6 => Array(2,1,1,2,2), 7 => Array(1,2,2,2,1), 8 => Array(1,2,2,1,2), 9 => Array(1,2,1,2,2) ); } else { $barlen = Array( 0 => Array(2,2,1,1,1), 1 => Array(1,1,1,2,2), 2 => Array(1,1,2,1,2), 3 => Array(1,1,2,2,1), 4 => Array(1,2,1,1,2), 5 => Array(1,2,1,2,1), 6 => Array(1,2,2,1,1), 7 => Array(2,1,1,1,2), 8 => Array(2,1,1,2,1), 9 => Array(2,1,2,1,1) ); } $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 2, 'bcode' => array()); $k = 0; $code = str_replace('-', '', $code); $code = str_replace(' ', '', $code); $len = strlen($code); // calculate checksum $sum = 0; for ($i = 0; $i < $len; ++$i) { $sum += intval($code[$i]); } $chkd = ($sum % 10); if($chkd > 0) { $chkd = (10 - $chkd); } $code .= $chkd; $len = strlen($code); // start bar $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 2, 'p' => 0); $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0); $bararray['maxw'] += 2; for ($i = 0; $i < $len; ++$i) { for ($j = 0; $j < 5; ++$j) { $h = $barlen[$code[$i]][$j]; $p = floor(1 / $h); $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p); $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0); $bararray['maxw'] += 2; } } // end bar $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 2, 'p' => 0); $bararray['maxw'] += 1; return $bararray; } /** * RMS4CC - CBC - KIX * RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code) - KIX (Klant index - Customer index) * RM4SCC is the name of the barcode symbology used by the Royal Mail for its Cleanmail service. * @param string $code code to print * @param boolean $kix if true prints the KIX variation (doesn't use the start and end symbols, and the checksum) - in this case the house number must be sufficed with an X and placed at the end of the code. * @return array barcode representation. * @protected */ protected function barcode_rms4cc($code, $kix=false) { $notkix = !$kix; // bar mode // 1 = pos 1, length 2 // 2 = pos 1, length 3 // 3 = pos 2, length 1 // 4 = pos 2, length 2 $barmode = array( '0' => array(3,3,2,2), '1' => array(3,4,1,2), '2' => array(3,4,2,1), '3' => array(4,3,1,2), '4' => array(4,3,2,1), '5' => array(4,4,1,1), '6' => array(3,1,4,2), '7' => array(3,2,3,2), '8' => array(3,2,4,1), '9' => array(4,1,3,2), 'A' => array(4,1,4,1), 'B' => array(4,2,3,1), 'C' => array(3,1,2,4), 'D' => array(3,2,1,4), 'E' => array(3,2,2,3), 'F' => array(4,1,1,4), 'G' => array(4,1,2,3), 'H' => array(4,2,1,3), 'I' => array(1,3,4,2), 'J' => array(1,4,3,2), 'K' => array(1,4,4,1), 'L' => array(2,3,3,2), 'M' => array(2,3,4,1), 'N' => array(2,4,3,1), 'O' => array(1,3,2,4), 'P' => array(1,4,1,4), 'Q' => array(1,4,2,3), 'R' => array(2,3,1,4), 'S' => array(2,3,2,3), 'T' => array(2,4,1,3), 'U' => array(1,1,4,4), 'V' => array(1,2,3,4), 'W' => array(1,2,4,3), 'X' => array(2,1,3,4), 'Y' => array(2,1,4,3), 'Z' => array(2,2,3,3) ); $code = strtoupper($code); $len = strlen($code); $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 3, 'bcode' => array()); if ($notkix) { // table for checksum calculation (row,col) $checktable = array( '0' => array(1,1), '1' => array(1,2), '2' => array(1,3), '3' => array(1,4), '4' => array(1,5), '5' => array(1,0), '6' => array(2,1), '7' => array(2,2), '8' => array(2,3), '9' => array(2,4), 'A' => array(2,5), 'B' => array(2,0), 'C' => array(3,1), 'D' => array(3,2), 'E' => array(3,3), 'F' => array(3,4), 'G' => array(3,5), 'H' => array(3,0), 'I' => array(4,1), 'J' => array(4,2), 'K' => array(4,3), 'L' => array(4,4), 'M' => array(4,5), 'N' => array(4,0), 'O' => array(5,1), 'P' => array(5,2), 'Q' => array(5,3), 'R' => array(5,4), 'S' => array(5,5), 'T' => array(5,0), 'U' => array(0,1), 'V' => array(0,2), 'W' => array(0,3), 'X' => array(0,4), 'Y' => array(0,5), 'Z' => array(0,0) ); $row = 0; $col = 0; for ($i = 0; $i < $len; ++$i) { $row += $checktable[$code[$i]][0]; $col += $checktable[$code[$i]][1]; } $row %= 6; $col %= 6; $chk = array_keys($checktable, array($row,$col)); $code .= $chk[0]; ++$len; } $k = 0; if ($notkix) { // start bar $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 2, 'p' => 0); $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0); $bararray['maxw'] += 2; } for ($i = 0; $i < $len; ++$i) { for ($j = 0; $j < 4; ++$j) { switch ($barmode[$code[$i]][$j]) { case 1: { $p = 0; $h = 2; break; } case 2: { $p = 0; $h = 3; break; } case 3: { $p = 1; $h = 1; break; } case 4: { $p = 1; $h = 2; break; } } $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p); $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0); $bararray['maxw'] += 2; } } if ($notkix) { // stop bar $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 3, 'p' => 0); $bararray['maxw'] += 1; } return $bararray; } /** * CODABAR barcodes. * Older code often used in library systems, sometimes in blood banks * @param string $code code to represent. * @return array barcode representation. * @protected */ protected function barcode_codabar($code) { $chr = array( '0' => '11111221', '1' => '11112211', '2' => '11121121', '3' => '22111111', '4' => '11211211', '5' => '21111211', '6' => '12111121', '7' => '12112111', '8' => '12211111', '9' => '21121111', '-' => '11122111', '$' => '11221111', ':' => '21112121', '/' => '21211121', '.' => '21212111', '+' => '11222221', 'A' => '11221211', 'B' => '12121121', 'C' => '11121221', 'D' => '11122211' ); $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); $k = 0; $w = 0; $seq = ''; $code = 'A'.strtoupper($code).'A'; $len = strlen($code); for ($i = 0; $i < $len; ++$i) { if (!isset($chr[$code[$i]])) { return false; } $seq = $chr[$code[$i]]; for ($j = 0; $j < 8; ++$j) { if (($j % 2) == 0) { $t = true; // bar } else { $t = false; // space } $w = (float)$seq[$j]; $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); $bararray['maxw'] += $w; ++$k; } } return $bararray; } /** * CODE11 barcodes. * Used primarily for labeling telecommunications equipment * @param string $code code to represent. * @return array barcode representation. * @protected */ protected function barcode_code11($code) { $chr = array( '0' => '111121', '1' => '211121', '2' => '121121', '3' => '221111', '4' => '112121', '5' => '212111', '6' => '122111', '7' => '111221', '8' => '211211', '9' => '211111', '-' => '112111', 'S' => '112211' ); $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); $k = 0; $w = 0; $seq = ''; $len = strlen($code); // calculate check digit C $p = 1; $check = 0; for ($i = ($len - 1); $i >= 0; --$i) { $digit = $code[$i]; if ($digit == '-') { $dval = 10; } else { $dval = intval($digit); } $check += ($dval * $p); ++$p; if ($p > 10) { $p = 1; } } $check %= 11; if ($check == 10) { $check = '-'; } $code .= $check; if ($len > 10) { // calculate check digit K $p = 1; $check = 0; for ($i = $len; $i >= 0; --$i) { $digit = $code[$i]; if ($digit == '-') { $dval = 10; } else { $dval = intval($digit); } $check += ($dval * $p); ++$p; if ($p > 9) { $p = 1; } } $check %= 11; $code .= $check; ++$len; } $code = 'S'.$code.'S'; $len += 3; for ($i = 0; $i < $len; ++$i) { if (!isset($chr[$code[$i]])) { return false; } $seq = $chr[$code[$i]]; for ($j = 0; $j < 6; ++$j) { if (($j % 2) == 0) { $t = true; // bar } else { $t = false; // space } $w = (float)$seq[$j]; $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0); $bararray['maxw'] += $w; ++$k; } } return $bararray; } /** * Pharmacode * Contains digits (0 to 9) * @param string $code code to represent. * @return array barcode representation. * @protected */ protected function barcode_pharmacode($code) { $seq = ''; $code = intval($code); while ($code > 0) { if (($code % 2) == 0) { $seq .= '11100'; $code -= 2; } else { $seq .= '100'; $code -= 1; } $code /= 2; } $seq = substr($seq, 0, -2); $seq = strrev($seq); $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array()); return $this->binseq_to_array($seq, $bararray); } /** * Pharmacode two-track * Contains digits (0 to 9) * @param string $code code to represent. * @return array barcode representation. * @protected */ protected function barcode_pharmacode2t($code) { $seq = ''; $code = intval($code); do { switch ($code % 3) { case 0: { $seq .= '3'; $code = ($code - 3) / 3; break; } case 1: { $seq .= '1'; $code = ($code - 1) / 3; break; } case 2: { $seq .= '2'; $code = ($code - 2) / 3; break; } } } while($code != 0); $seq = strrev($seq); $k = 0; $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 2, 'bcode' => array()); $len = strlen($seq); for ($i = 0; $i < $len; ++$i) { switch ($seq[$i]) { case '1': { $p = 1; $h = 1; break; } case '2': { $p = 0; $h = 1; break; } case '3': { $p = 0; $h = 2; break; } } $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p); $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0); $bararray['maxw'] += 2; } unset($bararray['bcode'][($k - 1)]); --$bararray['maxw']; return $bararray; } /** * IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200 * (requires PHP bcmath extension) * Intelligent Mail barcode is a 65-bar code for use on mail in the United States. * The fields are described as follows:
  • The Barcode Identifier shall be assigned by USPS to encode the presort identification that is currently printed in human readable form on the optional endorsement line (OEL) as well as for future USPS use. This shall be two digits, with the second digit in the range of 0–4. The allowable encoding ranges shall be 00–04, 10–14, 20–24, 30–34, 40–44, 50–54, 60–64, 70–74, 80–84, and 90–94.
  • The Service Type Identifier shall be assigned by USPS for any combination of services requested on the mailpiece. The allowable encoding range shall be 000http://it2.php.net/manual/en/function.dechex.php–999. Each 3-digit value shall correspond to a particular mail class with a particular combination of service(s). Each service program, such as OneCode Confirm and OneCode ACS, shall provide the list of Service Type Identifier values.
  • The Mailer or Customer Identifier shall be assigned by USPS as a unique, 6 or 9 digit number that identifies a business entity. The allowable encoding range for the 6 digit Mailer ID shall be 000000- 899999, while the allowable encoding range for the 9 digit Mailer ID shall be 900000000-999999999.
  • The Serial or Sequence Number shall be assigned by the mailer for uniquely identifying and tracking mailpieces. The allowable encoding range shall be 000000000–999999999 when used with a 6 digit Mailer ID and 000000-999999 when used with a 9 digit Mailer ID. e. The Delivery Point ZIP Code shall be assigned by the mailer for routing the mailpiece. This shall replace POSTNET for routing the mailpiece to its final delivery point. The length may be 0, 5, 9, or 11 digits. The allowable encoding ranges shall be no ZIP Code, 00000–99999, 000000000–999999999, and 00000000000–99999999999.
* @param string $code code to print, separate the ZIP (routing code) from the rest using a minus char '-' (BarcodeID_ServiceTypeID_MailerID_SerialNumber-RoutingCode) * @return array barcode representation. * @protected */ protected function barcode_imb($code) { $asc_chr = array(4,0,2,6,3,5,1,9,8,7,1,2,0,6,4,8,2,9,5,3,0,1,3,7,4,6,8,9,2,0,5,1,9,4,3,8,6,7,1,2,4,3,9,5,7,8,3,0,2,1,4,0,9,1,7,0,2,4,6,3,7,1,9,5,8); $dsc_chr = array(7,1,9,5,8,0,2,4,6,3,5,8,9,7,3,0,6,1,7,4,6,8,9,2,5,1,7,5,4,3,8,7,6,0,2,5,4,9,3,0,1,6,8,2,0,4,5,9,6,7,5,2,6,3,8,5,1,9,8,7,4,0,2,6,3); $asc_pos = array(3,0,8,11,1,12,8,11,10,6,4,12,2,7,9,6,7,9,2,8,4,0,12,7,10,9,0,7,10,5,7,9,6,8,2,12,1,4,2,0,1,5,4,6,12,1,0,9,4,7,5,10,2,6,9,11,2,12,6,7,5,11,0,3,2); $dsc_pos = array(2,10,12,5,9,1,5,4,3,9,11,5,10,1,6,3,4,1,10,0,2,11,8,6,1,12,3,8,6,4,4,11,0,6,1,9,11,5,3,7,3,10,7,11,8,2,10,3,5,8,0,3,12,11,8,4,5,1,3,0,7,12,9,8,10); $code_arr = explode('-', $code); $tracking_number = $code_arr[0]; if (isset($code_arr[1])) { $routing_code = $code_arr[1]; } else { $routing_code = ''; } // Conversion of Routing Code switch (strlen($routing_code)) { case 0: { $binary_code = 0; break; } case 5: { $binary_code = bcadd($routing_code, '1'); break; } case 9: { $binary_code = bcadd($routing_code, '100001'); break; } case 11: { $binary_code = bcadd($routing_code, '1000100001'); break; } default: { return false; break; } } $binary_code = bcmul($binary_code, 10); $binary_code = bcadd($binary_code, $tracking_number[0]); $binary_code = bcmul($binary_code, 5); $binary_code = bcadd($binary_code, $tracking_number[1]); $binary_code .= substr($tracking_number, 2, 18); // convert to hexadecimal $binary_code = $this->dec_to_hex($binary_code); // pad to get 13 bytes $binary_code = str_pad($binary_code, 26, '0', STR_PAD_LEFT); // convert string to array of bytes $binary_code_arr = chunk_split($binary_code, 2, "\r"); $binary_code_arr = substr($binary_code_arr, 0, -1); $binary_code_arr = explode("\r", $binary_code_arr); // calculate frame check sequence $fcs = $this->imb_crc11fcs($binary_code_arr); // exclude first 2 bits from first byte $first_byte = sprintf('%2s', dechex((hexdec($binary_code_arr[0]) << 2) >> 2)); $binary_code_102bit = $first_byte.substr($binary_code, 2); // convert binary data to codewords $codewords = array(); $data = $this->hex_to_dec($binary_code_102bit); $codewords[0] = bcmod($data, 636) * 2; $data = bcdiv($data, 636); for ($i = 1; $i < 9; ++$i) { $codewords[$i] = bcmod($data, 1365); $data = bcdiv($data, 1365); } $codewords[9] = $data; if (($fcs >> 10) == 1) { $codewords[9] += 659; } // generate lookup tables $table2of13 = $this->imb_tables(2, 78); $table5of13 = $this->imb_tables(5, 1287); // convert codewords to characters $characters = array(); $bitmask = 512; foreach($codewords as $k => $val) { if ($val <= 1286) { $chrcode = $table5of13[$val]; } else { $chrcode = $table2of13[($val - 1287)]; } if (($fcs & $bitmask) > 0) { // bitwise invert $chrcode = ((~$chrcode) & 8191); } $characters[] = $chrcode; $bitmask /= 2; } $characters = array_reverse($characters); // build bars $k = 0; $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 3, 'bcode' => array()); for ($i = 0; $i < 65; ++$i) { $asc = (($characters[$asc_chr[$i]] & pow(2, $asc_pos[$i])) > 0); $dsc = (($characters[$dsc_chr[$i]] & pow(2, $dsc_pos[$i])) > 0); if ($asc AND $dsc) { // full bar (F) $p = 0; $h = 3; } elseif ($asc) { // ascender (A) $p = 0; $h = 2; } elseif ($dsc) { // descender (D) $p = 1; $h = 2; } else { // tracker (T) $p = 1; $h = 1; } $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p); $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0); $bararray['maxw'] += 2; } unset($bararray['bcode'][($k - 1)]); --$bararray['maxw']; return $bararray; } /** * IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200 * * @param string $code pre-formatted IMB barcode (65 chars "FADT") * @return array barcode representation. * @protected */ protected function barcode_imb_pre($code) { if (!preg_match('/^[fadtFADT]{65}$/', $code) == 1) { return false; } $characters = str_split(strtolower($code), 1); // build bars $k = 0; $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 3, 'bcode' => array()); for ($i = 0; $i < 65; ++$i) { switch($characters[$i]) { case 'f': { // full bar $p = 0; $h = 3; break; } case 'a': { // ascender $p = 0; $h = 2; break; } case 'd': { // descender $p = 1; $h = 2; break; } case 't': { // tracker (short) $p = 1; $h = 1; break; } } $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p); $bararray['bcode'][$k++] = array('t' => 0, 'w' => 1, 'h' => 2, 'p' => 0); $bararray['maxw'] += 2; } unset($bararray['bcode'][($k - 1)]); --$bararray['maxw']; return $bararray; } /** * Convert large integer number to hexadecimal representation. * (requires PHP bcmath extension) * @param string $number number to convert specified as a string * @return string hexadecimal representation */ public function dec_to_hex($number) { $i = 0; $hex = array(); if($number == 0) { return '00'; } while($number > 0) { if($number == 0) { array_push($hex, '0'); } else { array_push($hex, strtoupper(dechex(bcmod($number, '16')))); $number = bcdiv($number, '16', 0); } } $hex = array_reverse($hex); return implode($hex); } /** * Convert large hexadecimal number to decimal representation (string). * (requires PHP bcmath extension) * @param string $hex hexadecimal number to convert specified as a string * @return string hexadecimal representation */ public function hex_to_dec($hex) { $dec = 0; $bitval = 1; $len = strlen($hex); for($pos = ($len - 1); $pos >= 0; --$pos) { $dec = bcadd($dec, bcmul(hexdec($hex[$pos]), $bitval)); $bitval = bcmul($bitval, 16); } return $dec; } /** * Intelligent Mail Barcode calculation of Frame Check Sequence * @param string $code_arr array of hexadecimal values (13 bytes holding 102 bits right justified). * @return int 11 bit Frame Check Sequence as integer (decimal base) * @protected */ protected function imb_crc11fcs($code_arr) { $genpoly = 0x0F35; // generator polynomial $fcs = 0x07FF; // Frame Check Sequence // do most significant byte skipping the 2 most significant bits $data = hexdec($code_arr[0]) << 5; for ($bit = 2; $bit < 8; ++$bit) { if (($fcs ^ $data) & 0x400) { $fcs = ($fcs << 1) ^ $genpoly; } else { $fcs = ($fcs << 1); } $fcs &= 0x7FF; $data <<= 1; } // do rest of bytes for ($byte = 1; $byte < 13; ++$byte) { $data = hexdec($code_arr[$byte]) << 3; for ($bit = 0; $bit < 8; ++$bit) { if (($fcs ^ $data) & 0x400) { $fcs = ($fcs << 1) ^ $genpoly; } else { $fcs = ($fcs << 1); } $fcs &= 0x7FF; $data <<= 1; } } return $fcs; } /** * Reverse unsigned short value * @param int $num value to reversr * @return int reversed value * @protected */ protected function imb_reverse_us($num) { $rev = 0; for ($i = 0; $i < 16; ++$i) { $rev <<= 1; $rev |= ($num & 1); $num >>= 1; } return $rev; } /** * generate Nof13 tables used for Intelligent Mail Barcode * @param int $n is the type of table: 2 for 2of13 table, 5 for 5of13table * @param int $size size of table (78 for n=2 and 1287 for n=5) * @return array requested table * @protected */ protected function imb_tables($n, $size) { $table = array(); $lli = 0; // LUT lower index $lui = $size - 1; // LUT upper index for ($count = 0; $count < 8192; ++$count) { $bit_count = 0; for ($bit_index = 0; $bit_index < 13; ++$bit_index) { $bit_count += intval(($count & (1 << $bit_index)) != 0); } // if we don't have the right number of bits on, go on to the next value if ($bit_count == $n) { $reverse = ($this->imb_reverse_us($count) >> 3); // if the reverse is less than count, we have already visited this pair before if ($reverse >= $count) { // If count is symmetric, place it at the first free slot from the end of the list. // Otherwise, place it at the first free slot from the beginning of the list AND place $reverse ath the next free slot from the beginning of the list if ($reverse == $count) { $table[$lui] = $count; --$lui; } else { $table[$lli] = $count; ++$lli; $table[$lli] = $reverse; ++$lli; } } } } return $table; } } // end of class //============================================================+ // END OF FILE //============================================================+ PK!WΊinclude/tcpdf_static.phpnu[. // // See LICENSE.TXT file for more information. // ------------------------------------------------------------------- // // Description : // Static methods used by the TCPDF class. // //============================================================+ /** * @file * This is a PHP class that contains static methods for the TCPDF class.
* @package com.tecnick.tcpdf * @author Nicola Asuni * @version 1.1.5 */ /** * @class TCPDF_STATIC * Static methods used by the TCPDF class. * @package com.tecnick.tcpdf * @brief PHP class for generating PDF documents without requiring external extensions. * @version 1.1.5 * @author Nicola Asuni - info@tecnick.com */ class TCPDF_STATIC { /** * Current TCPDF version. * @private static */ private static $tcpdf_version = '6.8.0'; /** * String alias for total number of pages. * @public static */ public static $alias_tot_pages = '{:ptp:}'; /** * String alias for page number. * @public static */ public static $alias_num_page = '{:pnp:}'; /** * String alias for total number of pages in a single group. * @public static */ public static $alias_group_tot_pages = '{:ptg:}'; /** * String alias for group page number. * @public static */ public static $alias_group_num_page = '{:png:}'; /** * String alias for right shift compensation used to correctly align page numbers on the right. * @public static */ public static $alias_right_shift = '{rsc:'; /** * Encryption padding string. * @public static */ public static $enc_padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A"; /** * ByteRange placemark used during digital signature process. * @since 4.6.028 (2009-08-25) * @public static */ public static $byterange_string = '/ByteRange[0 ********** ********** **********]'; /** * Array page boxes names * @public static */ public static $pageboxes = array('MediaBox', 'CropBox', 'BleedBox', 'TrimBox', 'ArtBox'); /** * Array of default cURL options for curl_setopt_array. * * @var array cURL options. */ protected const CURLOPT_DEFAULT = [ CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_MAXREDIRS => 5, CURLOPT_PROTOCOLS => CURLPROTO_HTTPS | CURLPROTO_HTTP | CURLPROTO_FTP | CURLPROTO_FTPS, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_TIMEOUT => 30, CURLOPT_USERAGENT => 'tcpdf', ]; /** * Array of fixed cURL options for curl_setopt_array. * * @var array cURL options. */ protected const CURLOPT_FIXED = [ CURLOPT_FAILONERROR => true, CURLOPT_RETURNTRANSFER => true, ]; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** * Return the current TCPDF version. * @return string TCPDF version string * @since 5.9.012 (2010-11-10) * @public static */ public static function getTCPDFVersion() { return self::$tcpdf_version; } /** * Return the current TCPDF producer. * @return string TCPDF producer string * @since 6.0.000 (2013-03-16) * @public static */ public static function getTCPDFProducer() { return "\x54\x43\x50\x44\x46\x20".self::getTCPDFVersion()."\x20\x28\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29"; } /** * Check if the URL exist. * @param string $url URL to check. * @return boolean true if the URl exist, false otherwise. * @since 5.9.204 (2013-01-28) * @public static */ public static function isValidURL($url) { $headers = @get_headers($url); if ($headers === false) { return false; } return (strpos($headers[0], '200') !== false); } /** * Removes SHY characters from text. * Unicode Data:
    *
  • Name : SOFT HYPHEN, commonly abbreviated as SHY
  • *
  • HTML Entity (decimal): "&#173;"
  • *
  • HTML Entity (hex): "&#xad;"
  • *
  • HTML Entity (named): "&shy;"
  • *
  • How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]
  • *
  • UTF-8 (hex): 0xC2 0xAD (c2ad)
  • *
  • UTF-8 character: chr(194).chr(173)
  • *
* @param string $txt input string * @param boolean $unicode True if we are in unicode mode, false otherwise. * @return string without SHY characters. * @since (4.5.019) 2009-02-28 * @public static */ public static function removeSHY($txt='', $unicode=true) { $txt = preg_replace('/([\\xc2]{1}[\\xad]{1})/', '', $txt); if (!$unicode) { $txt = preg_replace('/([\\xad]{1})/', '', $txt); } return $txt; } /** * Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages) * @param string|array|int $brd Indicates if borders must be drawn around the cell block. The value can be a number:
  • 0: no border (default)
  • 1: frame
or a string containing some or all of the following characters (in any order):
  • L: left
  • T: top
  • R: right
  • B: bottom
or an array of line styles for each border group: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))) * @param string $position multicell position: 'start', 'middle', 'end' * @param boolean $opencell True when the cell is left open at the page bottom, false otherwise. * @return array border mode array * @since 4.4.002 (2008-12-09) * @public static */ public static function getBorderMode($brd, $position='start', $opencell=true) { if ((!$opencell) OR empty($brd)) { return $brd; } if ($brd == 1) { $brd = 'LTRB'; } if (is_string($brd)) { // convert string to array $slen = strlen($brd); $newbrd = array(); for ($i = 0; $i < $slen; ++$i) { $newbrd[$brd[$i]] = array('cap' => 'square', 'join' => 'miter'); } $brd = $newbrd; } foreach ($brd as $border => $style) { switch ($position) { case 'start': { if (strpos($border, 'B') !== false) { // remove bottom line $newkey = str_replace('B', '', $border); if (strlen($newkey) > 0) { $brd[$newkey] = $style; } unset($brd[$border]); } break; } case 'middle': { if (strpos($border, 'B') !== false) { // remove bottom line $newkey = str_replace('B', '', $border); if (strlen($newkey) > 0) { $brd[$newkey] = $style; } unset($brd[$border]); $border = $newkey; } if (strpos($border, 'T') !== false) { // remove bottom line $newkey = str_replace('T', '', $border); if (strlen($newkey) > 0) { $brd[$newkey] = $style; } unset($brd[$border]); } break; } case 'end': { if (strpos($border, 'T') !== false) { // remove bottom line $newkey = str_replace('T', '', $border); if (strlen($newkey) > 0) { $brd[$newkey] = $style; } unset($brd[$border]); } break; } } } return $brd; } /** * Determine whether a string is empty. * @param string $str string to be checked * @return bool true if string is empty * @since 4.5.044 (2009-04-16) * @public static */ public static function empty_string($str) { return (is_null($str) OR (is_string($str) AND (strlen($str) == 0))); } /** * Returns a temporary filename for caching object on filesystem. * @param string $type Type of file (name of the subdir on the tcpdf cache folder). * @param string $file_id TCPDF file_id. * @return string filename. * @since 4.5.000 (2008-12-31) * @public static */ public static function getObjFilename($type='tmp', $file_id='') { return tempnam(K_PATH_CACHE, '__tcpdf_'.$file_id.'_'.$type.'_'.md5(TCPDF_STATIC::getRandomSeed()).'_'); } /** * Add "\" before "\", "(" and ")" * @param string $s string to escape. * @return string escaped string. * @public static */ public static function _escape($s) { // the chr(13) substitution fixes the Bugs item #1421290. return strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\', chr(13) => '\r')); } /** * Escape some special characters (< > &) for XML output. * @param string $str Input string to convert. * @return string converted string * @since 5.9.121 (2011-09-28) * @public static */ public static function _escapeXML($str) { $replaceTable = array("\0" => '', '&' => '&', '<' => '<', '>' => '>'); $str = strtr($str === null ? '' : $str, $replaceTable); return $str; } /** * Creates a copy of a class object * @param object $object class object to be cloned * @return object cloned object * @since 4.5.029 (2009-03-19) * @public static */ public static function objclone($object) { if (($object instanceof Imagick) AND (version_compare(phpversion('imagick'), '3.0.1') !== 1)) { // on the versions after 3.0.1 the clone() method was deprecated in favour of clone keyword return @$object->clone(); } return @clone($object); } /** * Output input data and compress it if possible. * @param string $data Data to output. * @param int $length Data length in bytes. * @since 5.9.086 * @public static */ public static function sendOutputData($data, $length) { if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) OR empty($_SERVER['HTTP_ACCEPT_ENCODING'])) { // the content length may vary if the server is using compression header('Content-Length: '.$length); } echo $data; } /** * Replace page number aliases with number. * @param string $page Page content. * @param array $replace Array of replacements (array keys are replacement strings, values are alias arrays). * @param int $diff If passed, this will be set to the total char number difference between alias and replacements. * @return array replaced page content and updated $diff parameter as array. * @public static */ public static function replacePageNumAliases($page, $replace, $diff=0) { foreach ($replace as $rep) { foreach ($rep[3] as $a) { if (strpos($page, $a) !== false) { $page = str_replace($a, $rep[0], $page); $diff += ($rep[2] - $rep[1]); } } } return array($page, $diff); } /** * Returns timestamp in seconds from formatted date-time. * @param string $date Formatted date-time. * @return int seconds. * @since 5.9.152 (2012-03-23) * @public static */ public static function getTimestamp($date) { if (($date[0] == 'D') AND ($date[1] == ':')) { // remove date prefix if present $date = substr($date, 2); } return strtotime($date); } /** * Returns a formatted date-time. * @param int $time Time in seconds. * @return string escaped date string. * @since 5.9.152 (2012-03-23) * @public static */ public static function getFormattedDate($time) { return substr_replace(date('YmdHisO', intval($time)), '\'', (0 - 2), 0).'\''; } /** * Returns a string containing random data to be used as a seed for encryption methods. * @param string $seed starting seed value * @return string containing random data * @author Nicola Asuni * @since 5.9.006 (2010-10-19) * @public static */ public static function getRandomSeed($seed='') { $rnd = uniqid(rand().microtime(true), true); if (function_exists('posix_getpid')) { $rnd .= posix_getpid(); } if (function_exists('random_bytes')) { $rnd .= random_bytes(512); } elseif (function_exists('openssl_random_pseudo_bytes') AND (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) { // this is not used on windows systems because it is very slow for a know bug $rnd .= openssl_random_pseudo_bytes(512); } else { for ($i = 0; $i < 23; ++$i) { $rnd .= uniqid('', true); } } return $rnd.$seed.__FILE__.microtime(true); } /** * Encrypts a string using MD5 and returns it's value as a binary string. * @param string $str input string * @return string MD5 encrypted binary string * @since 2.0.000 (2008-01-02) * @public static */ public static function _md5_16($str) { return pack('H*', md5($str)); } /** * Returns the input text encrypted using AES algorithm and the specified key. * This method requires openssl or mcrypt. Text is padded to 16bytes blocks * @param string $key encryption key * @param string $text input text to be encrypted * @return string encrypted text * @author Nicola Asuni * @since 5.0.005 (2010-05-11) * @public static */ public static function _AES($key, $text) { // padding (RFC 2898, PKCS #5: Password-Based Cryptography Specification Version 2.0) $padding = 16 - (strlen($text) % 16); $text .= str_repeat(chr($padding), $padding); if (extension_loaded('openssl')) { $algo = 'aes-256-cbc'; if (strlen($key) == 16) { $algo = 'aes-128-cbc'; } $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($algo)); $text = openssl_encrypt($text, $algo, $key, OPENSSL_RAW_DATA, $iv); return $iv.substr($text, 0, -16); } $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND); $text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv); $text = $iv.$text; return $text; } /** * Returns the input text encrypted using AES algorithm and the specified key. * This method requires openssl or mcrypt. Text is not padded * @param string $key encryption key * @param string $text input text to be encrypted * @return string encrypted text * @author Nicola Asuni * @since TODO * @public static */ public static function _AESnopad($key, $text) { if (extension_loaded('openssl')) { $algo = 'aes-256-cbc'; if (strlen($key) == 16) { $algo = 'aes-128-cbc'; } $iv = str_repeat("\x00", openssl_cipher_iv_length($algo)); $text = openssl_encrypt($text, $algo, $key, OPENSSL_RAW_DATA, $iv); return substr($text, 0, -16); } $iv = str_repeat("\x00", mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)); $text = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv); return $text; } /** * Returns the input text encrypted using RC4 algorithm and the specified key. * RC4 is the standard encryption algorithm used in PDF format * @param string $key Encryption key. * @param string $text Input text to be encrypted. * @param string $last_enc_key Reference to last RC4 key encrypted. * @param string $last_enc_key_c Reference to last RC4 computed key. * @return string encrypted text * @since 2.0.000 (2008-01-02) * @author Klemen Vodopivec, Nicola Asuni * @public static */ public static function _RC4($key, $text, &$last_enc_key, &$last_enc_key_c) { if (function_exists('mcrypt_encrypt') AND ($out = @mcrypt_encrypt(MCRYPT_ARCFOUR, $key, $text, MCRYPT_MODE_STREAM, ''))) { // try to use mcrypt function if exist return $out; } if ($last_enc_key != $key) { $k = str_repeat($key, (int) ((256 / strlen($key)) + 1)); $rc4 = range(0, 255); $j = 0; for ($i = 0; $i < 256; ++$i) { $t = $rc4[$i]; $j = ($j + $t + ord($k[$i])) % 256; $rc4[$i] = $rc4[$j]; $rc4[$j] = $t; } $last_enc_key = $key; $last_enc_key_c = $rc4; } else { $rc4 = $last_enc_key_c; } $len = strlen($text); $a = 0; $b = 0; $out = ''; for ($i = 0; $i < $len; ++$i) { $a = ($a + 1) % 256; $t = $rc4[$a]; $b = ($b + $t) % 256; $rc4[$a] = $rc4[$b]; $rc4[$b] = $t; $k = $rc4[($rc4[$a] + $rc4[$b]) % 256]; $out .= chr(ord($text[$i]) ^ $k); } return $out; } /** * Return the permission code used on encryption (P value). * @param array $permissions the set of permissions (specify the ones you want to block). * @param int $mode encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit. * @since 5.0.005 (2010-05-12) * @author Nicola Asuni * @public static */ public static function getUserPermissionCode($permissions, $mode=0) { $options = array( 'owner' => 2, // bit 2 -- inverted logic: cleared by default 'print' => 4, // bit 3 'modify' => 8, // bit 4 'copy' => 16, // bit 5 'annot-forms' => 32, // bit 6 'fill-forms' => 256, // bit 9 'extract' => 512, // bit 10 'assemble' => 1024,// bit 11 'print-high' => 2048 // bit 12 ); $protection = 2147422012; // 32 bit: (01111111 11111111 00001111 00111100) foreach ($permissions as $permission) { if (isset($options[$permission])) { if (($mode > 0) OR ($options[$permission] <= 32)) { // set only valid permissions if ($options[$permission] == 2) { // the logic for bit 2 is inverted (cleared by default) $protection += $options[$permission]; } else { $protection -= $options[$permission]; } } } } return $protection; } /** * Convert hexadecimal string to string * @param string $bs byte-string to convert * @return string * @since 5.0.005 (2010-05-12) * @author Nicola Asuni * @public static */ public static function convertHexStringToString($bs) { $string = ''; // string to be returned $bslength = strlen($bs); if (($bslength % 2) != 0) { // padding $bs .= '0'; ++$bslength; } for ($i = 0; $i < $bslength; $i += 2) { $string .= chr(hexdec($bs[$i].$bs[($i + 1)])); } return $string; } /** * Convert string to hexadecimal string (byte string) * @param string $s string to convert * @return string byte string * @since 5.0.010 (2010-05-17) * @author Nicola Asuni * @public static */ public static function convertStringToHexString($s) { $bs = ''; $chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY); foreach ($chars as $c) { $bs .= sprintf('%02s', dechex(ord($c))); } return $bs; } /** * Convert encryption P value to a string of bytes, low-order byte first. * @param string $protection 32bit encryption permission value (P value) * @return string * @since 5.0.005 (2010-05-12) * @author Nicola Asuni * @public static */ public static function getEncPermissionsString($protection) { $binprot = sprintf('%032b', $protection); $str = chr(bindec(substr($binprot, 24, 8))); $str .= chr(bindec(substr($binprot, 16, 8))); $str .= chr(bindec(substr($binprot, 8, 8))); $str .= chr(bindec(substr($binprot, 0, 8))); return $str; } /** * Encode a name object. * @param string $name Name object to encode. * @return string Encoded name object. * @author Nicola Asuni * @since 5.9.097 (2011-06-23) * @public static */ public static function encodeNameObject($name) { $escname = ''; $length = strlen($name); for ($i = 0; $i < $length; ++$i) { $chr = $name[$i]; if (preg_match('/[0-9a-zA-Z#_=-]/', $chr) == 1) { $escname .= $chr; } else { $escname .= sprintf('#%02X', ord($chr)); } } return $escname; } /** * Convert JavaScript form fields properties array to Annotation Properties array. * @param array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference. * @param array $spot_colors Reference to spot colors array. * @param boolean $rtl True if in Right-To-Left text direction mode, false otherwise. * @return array of annotation properties * @author Nicola Asuni * @since 4.8.000 (2009-09-06) * @public static */ public static function getAnnotOptFromJSProp($prop, &$spot_colors, $rtl=false) { if (isset($prop['aopt']) AND is_array($prop['aopt'])) { // the annotation options are already defined return $prop['aopt']; } $opt = array(); // value to be returned // alignment: Controls how the text is laid out within the text field. if (isset($prop['alignment'])) { switch ($prop['alignment']) { case 'left': { $opt['q'] = 0; break; } case 'center': { $opt['q'] = 1; break; } case 'right': { $opt['q'] = 2; break; } default: { $opt['q'] = ($rtl)?2:0; break; } } } // lineWidth: Specifies the thickness of the border when stroking the perimeter of a field's rectangle. if (isset($prop['lineWidth'])) { $linewidth = intval($prop['lineWidth']); } else { $linewidth = 1; } // borderStyle: The border style for a field. if (isset($prop['borderStyle'])) { switch ($prop['borderStyle']) { case 'border.d': case 'dashed': { $opt['border'] = array(0, 0, $linewidth, array(3, 2)); $opt['bs'] = array('w'=>$linewidth, 's'=>'D', 'd'=>array(3, 2)); break; } case 'border.b': case 'beveled': { $opt['border'] = array(0, 0, $linewidth); $opt['bs'] = array('w'=>$linewidth, 's'=>'B'); break; } case 'border.i': case 'inset': { $opt['border'] = array(0, 0, $linewidth); $opt['bs'] = array('w'=>$linewidth, 's'=>'I'); break; } case 'border.u': case 'underline': { $opt['border'] = array(0, 0, $linewidth); $opt['bs'] = array('w'=>$linewidth, 's'=>'U'); break; } case 'border.s': case 'solid': { $opt['border'] = array(0, 0, $linewidth); $opt['bs'] = array('w'=>$linewidth, 's'=>'S'); break; } default: { break; } } } if (isset($prop['border']) AND is_array($prop['border'])) { $opt['border'] = $prop['border']; } if (!isset($opt['mk'])) { $opt['mk'] = array(); } if (!isset($opt['mk']['if'])) { $opt['mk']['if'] = array(); } $opt['mk']['if']['a'] = array(0.5, 0.5); // buttonAlignX: Controls how space is distributed from the left of the button face with respect to the icon. if (isset($prop['buttonAlignX'])) { $opt['mk']['if']['a'][0] = $prop['buttonAlignX']; } // buttonAlignY: Controls how unused space is distributed from the bottom of the button face with respect to the icon. if (isset($prop['buttonAlignY'])) { $opt['mk']['if']['a'][1] = $prop['buttonAlignY']; } // buttonFitBounds: If true, the extent to which the icon may be scaled is set to the bounds of the button field. if (isset($prop['buttonFitBounds']) AND ($prop['buttonFitBounds'] == 'true')) { $opt['mk']['if']['fb'] = true; } // buttonScaleHow: Controls how the icon is scaled (if necessary) to fit inside the button face. if (isset($prop['buttonScaleHow'])) { switch ($prop['buttonScaleHow']) { case 'scaleHow.proportional': { $opt['mk']['if']['s'] = 'P'; break; } case 'scaleHow.anamorphic': { $opt['mk']['if']['s'] = 'A'; break; } } } // buttonScaleWhen: Controls when an icon is scaled to fit inside the button face. if (isset($prop['buttonScaleWhen'])) { switch ($prop['buttonScaleWhen']) { case 'scaleWhen.always': { $opt['mk']['if']['sw'] = 'A'; break; } case 'scaleWhen.never': { $opt['mk']['if']['sw'] = 'N'; break; } case 'scaleWhen.tooBig': { $opt['mk']['if']['sw'] = 'B'; break; } case 'scaleWhen.tooSmall': { $opt['mk']['if']['sw'] = 'S'; break; } } } // buttonPosition: Controls how the text and the icon of the button are positioned with respect to each other within the button face. if (isset($prop['buttonPosition'])) { switch ($prop['buttonPosition']) { case 0: case 'position.textOnly': { $opt['mk']['tp'] = 0; break; } case 1: case 'position.iconOnly': { $opt['mk']['tp'] = 1; break; } case 2: case 'position.iconTextV': { $opt['mk']['tp'] = 2; break; } case 3: case 'position.textIconV': { $opt['mk']['tp'] = 3; break; } case 4: case 'position.iconTextH': { $opt['mk']['tp'] = 4; break; } case 5: case 'position.textIconH': { $opt['mk']['tp'] = 5; break; } case 6: case 'position.overlay': { $opt['mk']['tp'] = 6; break; } } } // fillColor: Specifies the background color for a field. if (isset($prop['fillColor'])) { if (is_array($prop['fillColor'])) { $opt['mk']['bg'] = $prop['fillColor']; } else { $opt['mk']['bg'] = TCPDF_COLORS::convertHTMLColorToDec($prop['fillColor'], $spot_colors); } } // strokeColor: Specifies the stroke color for a field that is used to stroke the rectangle of the field with a line as large as the line width. if (isset($prop['strokeColor'])) { if (is_array($prop['strokeColor'])) { $opt['mk']['bc'] = $prop['strokeColor']; } else { $opt['mk']['bc'] = TCPDF_COLORS::convertHTMLColorToDec($prop['strokeColor'], $spot_colors); } } // rotation: The rotation of a widget in counterclockwise increments. if (isset($prop['rotation'])) { $opt['mk']['r'] = $prop['rotation']; } // charLimit: Limits the number of characters that a user can type into a text field. if (isset($prop['charLimit'])) { $opt['maxlen'] = intval($prop['charLimit']); } $ff = 0; // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it. if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) { $ff += 1 << 0; } // required: Specifies whether a field requires a value. if (isset($prop['required']) AND ($prop['required'] == 'true')) { $ff += 1 << 1; } // multiline: Controls how text is wrapped within the field. if (isset($prop['multiline']) AND ($prop['multiline'] == 'true')) { $ff += 1 << 12; } // password: Specifies whether the field should display asterisks when data is entered in the field. if (isset($prop['password']) AND ($prop['password'] == 'true')) { $ff += 1 << 13; } // NoToggleToOff: If set, exactly one radio button shall be selected at all times; selecting the currently selected button has no effect. if (isset($prop['NoToggleToOff']) AND ($prop['NoToggleToOff'] == 'true')) { $ff += 1 << 14; } // Radio: If set, the field is a set of radio buttons. if (isset($prop['Radio']) AND ($prop['Radio'] == 'true')) { $ff += 1 << 15; } // Pushbutton: If set, the field is a pushbutton that does not retain a permanent value. if (isset($prop['Pushbutton']) AND ($prop['Pushbutton'] == 'true')) { $ff += 1 << 16; } // Combo: If set, the field is a combo box; if clear, the field is a list box. if (isset($prop['Combo']) AND ($prop['Combo'] == 'true')) { $ff += 1 << 17; } // editable: Controls whether a combo box is editable. if (isset($prop['editable']) AND ($prop['editable'] == 'true')) { $ff += 1 << 18; } // Sort: If set, the field's option items shall be sorted alphabetically. if (isset($prop['Sort']) AND ($prop['Sort'] == 'true')) { $ff += 1 << 19; } // fileSelect: If true, sets the file-select flag in the Options tab of the text field (Field is Used for File Selection). if (isset($prop['fileSelect']) AND ($prop['fileSelect'] == 'true')) { $ff += 1 << 20; } // multipleSelection: If true, indicates that a list box allows a multiple selection of items. if (isset($prop['multipleSelection']) AND ($prop['multipleSelection'] == 'true')) { $ff += 1 << 21; } // doNotSpellCheck: If true, spell checking is not performed on this editable text field. if (isset($prop['doNotSpellCheck']) AND ($prop['doNotSpellCheck'] == 'true')) { $ff += 1 << 22; } // doNotScroll: If true, the text field does not scroll and the user, therefore, is limited by the rectangular region designed for the field. if (isset($prop['doNotScroll']) AND ($prop['doNotScroll'] == 'true')) { $ff += 1 << 23; } // comb: If set to true, the field background is drawn as series of boxes (one for each character in the value of the field) and each character of the content is drawn within those boxes. The number of boxes drawn is determined from the charLimit property. It applies only to text fields. The setter will also raise if any of the following field properties are also set multiline, password, and fileSelect. A side-effect of setting this property is that the doNotScroll property is also set. if (isset($prop['comb']) AND ($prop['comb'] == 'true')) { $ff += 1 << 24; } // radiosInUnison: If false, even if a group of radio buttons have the same name and export value, they behave in a mutually exclusive fashion, like HTML radio buttons. if (isset($prop['radiosInUnison']) AND ($prop['radiosInUnison'] == 'true')) { $ff += 1 << 25; } // richText: If true, the field allows rich text formatting. if (isset($prop['richText']) AND ($prop['richText'] == 'true')) { $ff += 1 << 25; } // commitOnSelChange: Controls whether a field value is committed after a selection change. if (isset($prop['commitOnSelChange']) AND ($prop['commitOnSelChange'] == 'true')) { $ff += 1 << 26; } $opt['ff'] = $ff; // defaultValue: The default value of a field - that is, the value that the field is set to when the form is reset. if (isset($prop['defaultValue'])) { $opt['dv'] = $prop['defaultValue']; } $f = 4; // default value for annotation flags // readonly: The read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it. if (isset($prop['readonly']) AND ($prop['readonly'] == 'true')) { $f += 1 << 6; } // display: Controls whether the field is hidden or visible on screen and in print. if (isset($prop['display'])) { if ($prop['display'] == 'display.visible') { // } elseif ($prop['display'] == 'display.hidden') { $f += 1 << 1; } elseif ($prop['display'] == 'display.noPrint') { $f -= 1 << 2; } elseif ($prop['display'] == 'display.noView') { $f += 1 << 5; } } $opt['f'] = $f; // currentValueIndices: Reads and writes single or multiple values of a list box or combo box. if (isset($prop['currentValueIndices']) AND is_array($prop['currentValueIndices'])) { $opt['i'] = $prop['currentValueIndices']; } // value: The value of the field data that the user has entered. if (isset($prop['value'])) { if (is_array($prop['value'])) { $opt['opt'] = array(); foreach ($prop['value'] AS $key => $optval) { // exportValues: An array of strings representing the export values for the field. if (isset($prop['exportValues'][$key])) { $opt['opt'][$key] = array($prop['exportValues'][$key], $prop['value'][$key]); } else { $opt['opt'][$key] = $prop['value'][$key]; } } } else { $opt['v'] = $prop['value']; } } // richValue: This property specifies the text contents and formatting of a rich text field. if (isset($prop['richValue'])) { $opt['rv'] = $prop['richValue']; } // submitName: If nonempty, used during form submission instead of name. Only applicable if submitting in HTML format (that is, URL-encoded). if (isset($prop['submitName'])) { $opt['tm'] = $prop['submitName']; } // name: Fully qualified field name. if (isset($prop['name'])) { $opt['t'] = $prop['name']; } // userName: The user name (short description string) of the field. if (isset($prop['userName'])) { $opt['tu'] = $prop['userName']; } // highlight: Defines how a button reacts when a user clicks it. if (isset($prop['highlight'])) { switch ($prop['highlight']) { case 'none': case 'highlight.n': { $opt['h'] = 'N'; break; } case 'invert': case 'highlight.i': { $opt['h'] = 'i'; break; } case 'push': case 'highlight.p': { $opt['h'] = 'P'; break; } case 'outline': case 'highlight.o': { $opt['h'] = 'O'; break; } } } // Unsupported options: // - calcOrderIndex: Changes the calculation order of fields in the document. // - delay: Delays the redrawing of a field's appearance. // - defaultStyle: This property defines the default style attributes for the form field. // - style: Allows the user to set the glyph style of a check box or radio button. // - textColor, textFont, textSize return $opt; } /** * Format the page numbers. * This method can be overridden for custom formats. * @param int $num page number * @return string * @since 4.2.005 (2008-11-06) * @public static */ public static function formatPageNumber($num) { return number_format((float)$num, 0, '', '.'); } /** * Format the page numbers on the Table Of Content. * This method can be overridden for custom formats. * @param int $num page number * @return string * @since 4.5.001 (2009-01-04) * @see addTOC(), addHTMLTOC() * @public static */ public static function formatTOCPageNumber($num) { return number_format((float)$num, 0, '', '.'); } /** * Extracts the CSS properties from a CSS string. * @param string $cssdata string containing CSS definitions. * @return array An array where the keys are the CSS selectors and the values are the CSS properties. * @author Nicola Asuni * @since 5.1.000 (2010-05-25) * @public static */ public static function extractCSSproperties($cssdata) { if (empty($cssdata)) { return array(); } // remove comments $cssdata = preg_replace('/\/\*[^\*]*\*\//', '', $cssdata); // remove newlines and multiple spaces $cssdata = preg_replace('/[\s]+/', ' ', $cssdata); // remove some spaces $cssdata = preg_replace('/[\s]*([;:\{\}]{1})[\s]*/', '\\1', $cssdata); // remove empty blocks $cssdata = preg_replace('/([^\}\{]+)\{\}/', '', $cssdata); // replace media type parenthesis $cssdata = preg_replace('/@media[\s]+([^\{]*)\{/i', '@media \\1§', $cssdata); $cssdata = preg_replace('/\}\}/si', '}§', $cssdata); // trim string $cssdata = trim($cssdata); // find media blocks (all, braille, embossed, handheld, print, projection, screen, speech, tty, tv) $cssblocks = array(); $matches = array(); if (preg_match_all('/@media[\s]+([^\§]*)§([^§]*)§/i', $cssdata, $matches) > 0) { foreach ($matches[1] as $key => $type) { $cssblocks[$type] = $matches[2][$key]; } // remove media blocks $cssdata = preg_replace('/@media[\s]+([^\§]*)§([^§]*)§/i', '', $cssdata); } // keep 'all' and 'print' media, other media types are discarded if (isset($cssblocks['all']) AND !empty($cssblocks['all'])) { $cssdata .= $cssblocks['all']; } if (isset($cssblocks['print']) AND !empty($cssblocks['print'])) { $cssdata .= $cssblocks['print']; } // reset css blocks array $cssblocks = array(); $matches = array(); // explode css data string into array if (substr($cssdata, -1) == '}') { // remove last parethesis $cssdata = substr($cssdata, 0, -1); } $matches = explode('}', $cssdata); foreach ($matches as $key => $block) { // index 0 contains the CSS selector, index 1 contains CSS properties $cssblocks[$key] = explode('{', $block); if (!isset($cssblocks[$key][1])) { // remove empty definitions unset($cssblocks[$key]); } } // split groups of selectors (comma-separated list of selectors) foreach ($cssblocks as $key => $block) { if (strpos($block[0], ',') > 0) { $selectors = explode(',', $block[0]); foreach ($selectors as $sel) { $cssblocks[] = array(0 => trim($sel), 1 => $block[1]); } unset($cssblocks[$key]); } } // covert array to selector => properties $cssdata = array(); foreach ($cssblocks as $block) { $selector = $block[0]; // calculate selector's specificity $matches = array(); $a = 0; // the declaration is not from is a 'style' attribute $b = intval(preg_match_all('/[\#]/', $selector, $matches)); // number of ID attributes $c = intval(preg_match_all('/[\[\.]/', $selector, $matches)); // number of other attributes $c += intval(preg_match_all('/[\:]link|visited|hover|active|focus|target|lang|enabled|disabled|checked|indeterminate|root|nth|first|last|only|empty|contains|not/i', $selector, $matches)); // number of pseudo-classes $d = intval(preg_match_all('/[\>\+\~\s]{1}[a-zA-Z0-9]+/', ' '.$selector, $matches)); // number of element names $d += intval(preg_match_all('/[\:][\:]/', $selector, $matches)); // number of pseudo-elements $specificity = $a.$b.$c.$d; // add specificity to the beginning of the selector $cssdata[$specificity.' '.$selector] = $block[1]; } // sort selectors alphabetically to account for specificity ksort($cssdata, SORT_STRING); // return array return $cssdata; } /** * Cleanup HTML code (requires HTML Tidy library). * @param string $html htmlcode to fix * @param string $default_css CSS commands to add * @param array|null $tagvs parameters for setHtmlVSpace method * @param array|null $tidy_options options for tidy_parse_string function * @param array $tagvspaces Array of vertical spaces for tags. * @return string XHTML code cleaned up * @author Nicola Asuni * @since 5.9.017 (2010-11-16) * @see setHtmlVSpace() * @public static */ public static function fixHTMLCode($html, $default_css, $tagvs, $tidy_options, &$tagvspaces) { // configure parameters for HTML Tidy if (TCPDF_STATIC::empty_string($tidy_options)) { $tidy_options = array ( 'clean' => 1, 'drop-empty-paras' => 0, 'drop-proprietary-attributes' => 1, 'fix-backslash' => 1, 'hide-comments' => 1, 'join-styles' => 1, 'lower-literals' => 1, 'merge-divs' => 1, 'merge-spans' => 1, 'output-xhtml' => 1, 'word-2000' => 1, 'wrap' => 0, 'output-bom' => 0, //'char-encoding' => 'utf8', //'input-encoding' => 'utf8', //'output-encoding' => 'utf8' ); } // clean up the HTML code $tidy = tidy_parse_string($html, $tidy_options); // fix the HTML $tidy->cleanRepair(); // get the CSS part $tidy_head = tidy_get_head($tidy); $css = $tidy_head->value; $css = preg_replace('/]+)>/ims', ''; // get the body part $tidy_body = tidy_get_body($tidy); $html = $tidy_body->value; // fix some self-closing tags $html = str_replace('
', '
', $html); // remove some empty tag blocks $html = preg_replace('/]*)><\/div>/', '', $html); $html = preg_replace('/]*)><\/p>/', '', $html); if (!TCPDF_STATIC::empty_string($tagvs)) { // set vertical space for some XHTML tags $tagvspaces = $tagvs; } // return the cleaned XHTML code + CSS return $css.$html; } /** * Returns true if the CSS selector is valid for the selected HTML tag * @param array $dom array of HTML tags and properties * @param int $key key of the current HTML tag * @param string $selector CSS selector string * @return true if the selector is valid, false otherwise * @since 5.1.000 (2010-05-25) * @public static */ public static function isValidCSSSelectorForTag($dom, $key, $selector) { $valid = false; // value to be returned $tag = $dom[$key]['value']; $class = array(); if (isset($dom[$key]['attribute']['class']) AND !empty($dom[$key]['attribute']['class'])) { $class = explode(' ', strtolower($dom[$key]['attribute']['class'])); } $id = ''; if (isset($dom[$key]['attribute']['id']) AND !empty($dom[$key]['attribute']['id'])) { $id = strtolower($dom[$key]['attribute']['id']); } $selector = preg_replace('/([\>\+\~\s]{1})([\.]{1})([^\>\+\~\s]*)/si', '\\1*.\\3', $selector); $matches = array(); if (preg_match_all('/([\>\+\~\s]{1})([a-zA-Z0-9\*]+)([^\>\+\~\s]*)/si', $selector, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE) > 0) { $parentop = array_pop($matches[1]); $operator = $parentop[0]; $offset = $parentop[1]; $lasttag = array_pop($matches[2]); $lasttag = strtolower(trim($lasttag[0])); if (($lasttag == '*') OR ($lasttag == $tag)) { // the last element on selector is our tag or 'any tag' $attrib = array_pop($matches[3]); $attrib = strtolower(trim($attrib[0])); if (!empty($attrib)) { // check if matches class, id, attribute, pseudo-class or pseudo-element switch ($attrib[0]) { case '.': { // class if (in_array(substr($attrib, 1), $class)) { $valid = true; } break; } case '#': { // ID if (substr($attrib, 1) == $id) { $valid = true; } break; } case '[': { // attribute $attrmatch = array(); if (preg_match('/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i', $attrib, $attrmatch) > 0) { $att = strtolower($attrmatch[1]); $val = $attrmatch[3]; if (isset($dom[$key]['attribute'][$att])) { switch ($attrmatch[2]) { case '=': { if ($dom[$key]['attribute'][$att] == $val) { $valid = true; } break; } case '~=': { if (in_array($val, explode(' ', $dom[$key]['attribute'][$att]))) { $valid = true; } break; } case '^=': { if ($val == substr($dom[$key]['attribute'][$att], 0, strlen($val))) { $valid = true; } break; } case '$=': { if ($val == substr($dom[$key]['attribute'][$att], -strlen($val))) { $valid = true; } break; } case '*=': { if (strpos($dom[$key]['attribute'][$att], $val) !== false) { $valid = true; } break; } case '|=': { if ($dom[$key]['attribute'][$att] == $val) { $valid = true; } elseif (preg_match('/'.$val.'[\-]{1}/i', $dom[$key]['attribute'][$att]) > 0) { $valid = true; } break; } default: { $valid = true; } } } } break; } case ':': { // pseudo-class or pseudo-element if ($attrib[1] == ':') { // pseudo-element // pseudo-elements are not supported! // (::first-line, ::first-letter, ::before, ::after) } else { // pseudo-class // pseudo-classes are not supported! // (:root, :nth-child(n), :nth-last-child(n), :nth-of-type(n), :nth-last-of-type(n), :first-child, :last-child, :first-of-type, :last-of-type, :only-child, :only-of-type, :empty, :link, :visited, :active, :hover, :focus, :target, :lang(fr), :enabled, :disabled, :checked) } break; } } // end of switch } else { $valid = true; } if ($valid AND ($offset > 0)) { $valid = false; // check remaining selector part $selector = substr($selector, 0, $offset); switch ($operator) { case ' ': { // descendant of an element while ($dom[$key]['parent'] > 0) { if (self::isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector)) { $valid = true; break; } else { $key = $dom[$key]['parent']; } } break; } case '>': { // child of an element $valid = self::isValidCSSSelectorForTag($dom, $dom[$key]['parent'], $selector); break; } case '+': { // immediately preceded by an element for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) { if ($dom[$i]['tag'] AND $dom[$i]['opening']) { $valid = self::isValidCSSSelectorForTag($dom, $i, $selector); break; } } break; } case '~': { // preceded by an element for ($i = ($key - 1); $i > $dom[$key]['parent']; --$i) { if ($dom[$i]['tag'] AND $dom[$i]['opening']) { if (self::isValidCSSSelectorForTag($dom, $i, $selector)) { break; } } } break; } } } } } return $valid; } /** * Returns the styles array that apply for the selected HTML tag. * @param array $dom array of HTML tags and properties * @param int $key key of the current HTML tag * @param array $css array of CSS properties * @return array containing CSS properties * @since 5.1.000 (2010-05-25) * @public static */ public static function getCSSdataArray($dom, $key, $css) { $cssarray = array(); // style to be returned // get parent CSS selectors $selectors = array(); if (isset($dom[($dom[$key]['parent'])]['csssel'])) { $selectors = $dom[($dom[$key]['parent'])]['csssel']; } // get all styles that apply foreach($css as $selector => $style) { $pos = strpos($selector, ' '); // get specificity $specificity = substr($selector, 0, $pos); // remove specificity $selector = substr($selector, $pos); // check if this selector apply to current tag if (self::isValidCSSSelectorForTag($dom, $key, $selector)) { if (!in_array($selector, $selectors)) { // add style if not already added on parent selector $cssarray[] = array('k' => $selector, 's' => $specificity, 'c' => $style); $selectors[] = $selector; } } } if (isset($dom[$key]['attribute']['style'])) { // attach inline style (latest properties have high priority) $cssarray[] = array('k' => '', 's' => '1000', 'c' => $dom[$key]['attribute']['style']); } // order the css array to account for specificity $cssordered = array(); foreach ($cssarray as $key => $val) { $skey = sprintf('%04d', $key); $cssordered[$val['s'].'_'.$skey] = $val; } // sort selectors alphabetically to account for specificity ksort($cssordered, SORT_STRING); return array($selectors, $cssordered); } /** * Compact CSS data array into single string. * @param array $css array of CSS properties * @return string containing merged CSS properties * @since 5.9.070 (2011-04-19) * @public static */ public static function getTagStyleFromCSSarray($css) { $tagstyle = ''; // value to be returned foreach ($css as $style) { // split single css commands $csscmds = explode(';', $style['c']); foreach ($csscmds as $cmd) { if (!empty($cmd)) { $pos = strpos($cmd, ':'); if ($pos !== false) { $cmd = substr($cmd, 0, ($pos + 1)); if (strpos($tagstyle, $cmd) !== false) { // remove duplicate commands (last commands have high priority) $tagstyle = preg_replace('/'.$cmd.'[^;]+/i', '', $tagstyle); } } } } $tagstyle .= ';'.$style['c']; } // remove multiple semicolons $tagstyle = preg_replace('/[;]+/', ';', $tagstyle); return $tagstyle; } /** * Returns the Roman representation of an integer number * @param int $number number to convert * @return string roman representation of the specified number * @since 4.4.004 (2008-12-10) * @public static */ public static function intToRoman($number) { $roman = ''; if ($number >= 4000) { // do not represent numbers above 4000 in Roman numerals return strval($number); } while ($number >= 1000) { $roman .= 'M'; $number -= 1000; } while ($number >= 900) { $roman .= 'CM'; $number -= 900; } while ($number >= 500) { $roman .= 'D'; $number -= 500; } while ($number >= 400) { $roman .= 'CD'; $number -= 400; } while ($number >= 100) { $roman .= 'C'; $number -= 100; } while ($number >= 90) { $roman .= 'XC'; $number -= 90; } while ($number >= 50) { $roman .= 'L'; $number -= 50; } while ($number >= 40) { $roman .= 'XL'; $number -= 40; } while ($number >= 10) { $roman .= 'X'; $number -= 10; } while ($number >= 9) { $roman .= 'IX'; $number -= 9; } while ($number >= 5) { $roman .= 'V'; $number -= 5; } while ($number >= 4) { $roman .= 'IV'; $number -= 4; } while ($number >= 1) { $roman .= 'I'; --$number; } return $roman; } /** * Find position of last occurrence of a substring in a string * @param string $haystack The string to search in. * @param string $needle substring to search. * @param int $offset May be specified to begin searching an arbitrary number of characters into the string. * @return int|false Returns the position where the needle exists. Returns FALSE if the needle was not found. * @since 4.8.038 (2010-03-13) * @public static */ public static function revstrpos($haystack, $needle, $offset = 0) { $length = strlen($haystack); $offset = ($offset > 0)?($length - $offset):abs($offset); $pos = strpos(strrev($haystack), strrev($needle), $offset); return ($pos === false)?false:($length - $pos - strlen($needle)); } /** * Returns an array of hyphenation patterns. * @param string $file TEX file containing hypenation patterns. TEX patterns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/ * @return array of hyphenation patterns * @author Nicola Asuni * @since 4.9.012 (2010-04-12) * @public static */ public static function getHyphenPatternsFromTEX($file) { // TEX patterns are available at: // http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/ $data = file_get_contents($file); $patterns = array(); // remove comments $data = preg_replace('/\%[^\n]*/', '', $data); // extract the patterns part preg_match('/\\\\patterns\{([^\}]*)\}/i', $data, $matches); $data = trim(substr($matches[0], 10, -1)); // extract each pattern $patterns_array = preg_split('/[\s]+/', $data); // create new language array of patterns $patterns = array(); foreach($patterns_array as $val) { if (!TCPDF_STATIC::empty_string($val)) { $val = trim($val); $val = str_replace('\'', '\\\'', $val); $key = preg_replace('/[0-9]+/', '', $val); $patterns[$key] = $val; } } return $patterns; } /** * Get the Path-Painting Operators. * @param string $style Style of rendering. Possible values are: *
    *
  • S or D: Stroke the path.
  • *
  • s or d: Close and stroke the path.
  • *
  • f or F: Fill the path, using the nonzero winding number rule to determine the region to fill.
  • *
  • f* or F*: Fill the path, using the even-odd rule to determine the region to fill.
  • *
  • B or FD or DF: Fill and then stroke the path, using the nonzero winding number rule to determine the region to fill.
  • *
  • B* or F*D or DF*: Fill and then stroke the path, using the even-odd rule to determine the region to fill.
  • *
  • b or fd or df: Close, fill, and then stroke the path, using the nonzero winding number rule to determine the region to fill.
  • *
  • b or f*d or df*: Close, fill, and then stroke the path, using the even-odd rule to determine the region to fill.
  • *
  • CNZ: Clipping mode using the even-odd rule to determine which regions lie inside the clipping path.
  • *
  • CEO: Clipping mode using the nonzero winding number rule to determine which regions lie inside the clipping path
  • *
  • n: End the path object without filling or stroking it.
  • *
* @param string $default default style * @return string * @author Nicola Asuni * @since 5.0.000 (2010-04-30) * @public static */ public static function getPathPaintOperator($style, $default='S') { $op = ''; switch($style) { case 'S': case 'D': { $op = 'S'; break; } case 's': case 'd': { $op = 's'; break; } case 'f': case 'F': { $op = 'f'; break; } case 'f*': case 'F*': { $op = 'f*'; break; } case 'B': case 'FD': case 'DF': { $op = 'B'; break; } case 'B*': case 'F*D': case 'DF*': { $op = 'B*'; break; } case 'b': case 'fd': case 'df': { $op = 'b'; break; } case 'b*': case 'f*d': case 'df*': { $op = 'b*'; break; } case 'CNZ': { $op = 'W n'; break; } case 'CEO': { $op = 'W* n'; break; } case 'n': { $op = 'n'; break; } default: { if (!empty($default)) { $op = self::getPathPaintOperator($default, ''); } else { $op = ''; } } } return $op; } /** * Get the product of two SVG tranformation matrices * @param array $ta first SVG tranformation matrix * @param array $tb second SVG tranformation matrix * @return array transformation array * @author Nicola Asuni * @since 5.0.000 (2010-05-02) * @public static */ public static function getTransformationMatrixProduct($ta, $tb) { $tm = array(); $tm[0] = ($ta[0] * $tb[0]) + ($ta[2] * $tb[1]); $tm[1] = ($ta[1] * $tb[0]) + ($ta[3] * $tb[1]); $tm[2] = ($ta[0] * $tb[2]) + ($ta[2] * $tb[3]); $tm[3] = ($ta[1] * $tb[2]) + ($ta[3] * $tb[3]); $tm[4] = ($ta[0] * $tb[4]) + ($ta[2] * $tb[5]) + $ta[4]; $tm[5] = ($ta[1] * $tb[4]) + ($ta[3] * $tb[5]) + $ta[5]; return $tm; } /** * Get the tranformation matrix from SVG transform attribute * @param string $attribute transformation * @return array of transformations * @author Nicola Asuni * @since 5.0.000 (2010-05-02) * @public static */ public static function getSVGTransformMatrix($attribute) { // identity matrix $tm = array(1, 0, 0, 1, 0, 0); $transform = array(); if (preg_match_all('/(matrix|translate|scale|rotate|skewX|skewY)[\s]*\(([^\)]+)\)/si', $attribute, $transform, PREG_SET_ORDER) > 0) { foreach ($transform as $key => $data) { if (!empty($data[2])) { $a = 1; $b = 0; $c = 0; $d = 1; $e = 0; $f = 0; $regs = array(); switch ($data[1]) { case 'matrix': { if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { $a = $regs[1]; $b = $regs[2]; $c = $regs[3]; $d = $regs[4]; $e = $regs[5]; $f = $regs[6]; } break; } case 'translate': { if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { $e = $regs[1]; $f = $regs[2]; } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) { $e = $regs[1]; } break; } case 'scale': { if (preg_match('/([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { $a = $regs[1]; $d = $regs[2]; } elseif (preg_match('/([a-z0-9\-\.]+)/si', $data[2], $regs)) { $a = $regs[1]; $d = $a; } break; } case 'rotate': { if (preg_match('/([0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)[\,\s]+([a-z0-9\-\.]+)/si', $data[2], $regs)) { $ang = deg2rad($regs[1]); $x = $regs[2]; $y = $regs[3]; $a = cos($ang); $b = sin($ang); $c = -$b; $d = $a; $e = ($x * (1 - $a)) - ($y * $c); $f = ($y * (1 - $d)) - ($x * $b); } elseif (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { $ang = deg2rad($regs[1]); $a = cos($ang); $b = sin($ang); $c = -$b; $d = $a; $e = 0; $f = 0; } break; } case 'skewX': { if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { $c = tan(deg2rad($regs[1])); } break; } case 'skewY': { if (preg_match('/([0-9\-\.]+)/si', $data[2], $regs)) { $b = tan(deg2rad($regs[1])); } break; } } $tm = self::getTransformationMatrixProduct($tm, array($a, $b, $c, $d, $e, $f)); } } } return $tm; } /** * Returns the angle in radiants between two vectors * @param int $x1 X coordinate of first vector point * @param int $y1 Y coordinate of first vector point * @param int $x2 X coordinate of second vector point * @param int $y2 Y coordinate of second vector point * @author Nicola Asuni * @since 5.0.000 (2010-05-04) * @public static */ public static function getVectorsAngle($x1, $y1, $x2, $y2) { $dprod = ($x1 * $x2) + ($y1 * $y2); $dist1 = sqrt(($x1 * $x1) + ($y1 * $y1)); $dist2 = sqrt(($x2 * $x2) + ($y2 * $y2)); $angle = acos($dprod / ($dist1 * $dist2)); if (is_nan($angle)) { $angle = M_PI; } if ((($x1 * $y2) - ($x2 * $y1)) < 0) { $angle *= -1; } return $angle; } /** * Split string by a regular expression. * This is a wrapper for the preg_split function to avoid the bug: https://bugs.php.net/bug.php?id=45850 * @param string $pattern The regular expression pattern to search for without the modifiers, as a string. * @param string $modifiers The modifiers part of the pattern, * @param string $subject The input string. * @param int $limit If specified, then only substrings up to limit are returned with the rest of the string being placed in the last substring. A limit of -1, 0 or NULL means "no limit" and, as is standard across PHP, you can use NULL to skip to the flags parameter. * @param int $flags The flags as specified on the preg_split PHP function. * @return array Returns an array containing substrings of subject split along boundaries matched by pattern.modifier * @author Nicola Asuni * @since 6.0.023 * @public static */ public static function pregSplit($pattern, $modifiers, $subject, $limit=NULL, $flags=NULL) { // PHP 8.1 deprecates nulls for $limit and $flags $limit = $limit === null ? -1 : $limit; $flags = $flags === null ? 0 : $flags; // the bug only happens on PHP 5.2 when using the u modifier if ((strpos($modifiers, 'u') === FALSE) OR (count(preg_split('//u', "\n\t", -1, PREG_SPLIT_NO_EMPTY)) == 2)) { $ret = preg_split($pattern.$modifiers, $subject, $limit, $flags); if ($ret === false) { return array(); } return is_array($ret) ? $ret : array(); } // preg_split is bugged - try alternative solution $ret = array(); while (($nl = strpos($subject, "\n")) !== FALSE) { $ret = array_merge($ret, preg_split($pattern.$modifiers, substr($subject, 0, $nl), $limit, $flags)); $ret[] = "\n"; $subject = substr($subject, ($nl + 1)); } if (strlen($subject) > 0) { $ret = array_merge($ret, preg_split($pattern.$modifiers, $subject, $limit, $flags)); } return $ret; } /** * Wrapper to use fopen only with local files * @param string $filename Name of the file to open * @param string $mode * @return resource|false Returns a file pointer resource on success, or FALSE on error. * @public static */ public static function fopenLocal($filename, $mode) { if (strpos($filename, '://') === false) { $filename = 'file://'.$filename; } elseif (stream_is_local($filename) !== true) { return false; } return fopen($filename, $mode); } /** * Check if the URL exist. * @param string $url URL to check. * @return bool Returns TRUE if the URL exists; FALSE otherwise. * @public static * @since 6.2.25 */ public static function url_exists($url) { $crs = curl_init(); $curlopts = []; if ( (ini_get('open_basedir') == '') && (ini_get('safe_mode') === '' || ini_get('safe_mode') === false) ) { $curlopts[CURLOPT_FOLLOWLOCATION] = true; } $curlopts = array_replace($curlopts, self::CURLOPT_DEFAULT); $curlopts = array_replace($curlopts, K_CURLOPTS); $curlopts = array_replace($curlopts, self::CURLOPT_FIXED); $curlopts[CURLOPT_URL] = $url; curl_setopt_array($crs, $curlopts); curl_exec($crs); $code = curl_getinfo($crs, CURLINFO_HTTP_CODE); curl_close($crs); return ($code == 200); } /** * Encode query params in URL * * @param string $url * @return string * @since 6.3.3 (2019-11-01) * @public static */ public static function encodeUrlQuery($url) { $urlData = parse_url($url); if (isset($urlData['query']) && $urlData['query']) { $urlQueryData = array(); parse_str(urldecode($urlData['query']), $urlQueryData); $port = isset($urlData['port']) ? ':'.$urlData['port'] : ''; $updatedUrl = $urlData['scheme'].'://'.$urlData['host'].$port.$urlData['path'].'?'.http_build_query($urlQueryData); } else { $updatedUrl = $url; } return $updatedUrl; } /** * Wrapper for file_exists. * Checks whether a file or directory exists. * Only allows some protocols and local files. * @param string $filename Path to the file or directory. * @return bool Returns TRUE if the file or directory specified by filename exists; FALSE otherwise. * @public static */ public static function file_exists($filename) { if (preg_match('|^https?://|', $filename) == 1) { return self::url_exists($filename); } if (strpos($filename, '://')) { return false; // only support http and https wrappers for security reasons } return @file_exists($filename); } /** * Reads entire file into a string. * The file can be also an URL. * @param string $file Name of the file or URL to read. * @return string|false The function returns the read data or FALSE on failure. * @author Nicola Asuni * @since 6.0.025 * @public static */ public static function fileGetContents($file) { $alt = array($file); // if ((strlen($file) > 1) && ($file[0] === '/') && ($file[1] !== '/') && !empty($_SERVER['DOCUMENT_ROOT']) && ($_SERVER['DOCUMENT_ROOT'] !== '/') ) { $findroot = strpos($file, $_SERVER['DOCUMENT_ROOT']); if (($findroot === false) || ($findroot > 1)) { $alt[] = htmlspecialchars_decode(urldecode($_SERVER['DOCUMENT_ROOT'].$file)); } } // $protocol = 'http'; if (!empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) { $protocol .= 's'; } // $url = $file; if (preg_match('%^//%', $url) && !empty($_SERVER['HTTP_HOST'])) { $url = $protocol.':'.str_replace(' ', '%20', $url); } $url = htmlspecialchars_decode($url); $alt[] = $url; // if (preg_match('%^(https?)://%', $url) && empty($_SERVER['HTTP_HOST']) && empty($_SERVER['DOCUMENT_ROOT']) ) { $urldata = parse_url($url); if (empty($urldata['query'])) { $host = $protocol.'://'.$_SERVER['HTTP_HOST']; if (strpos($url, $host) === 0) { // convert URL to full server path $tmp = str_replace($host, $_SERVER['DOCUMENT_ROOT'], $url); $alt[] = htmlspecialchars_decode(urldecode($tmp)); } } } // if (isset($_SERVER['SCRIPT_URI']) && !preg_match('%^(https?|ftp)://%', $file) && !preg_match('%^//%', $file) ) { $urldata = @parse_url($_SERVER['SCRIPT_URI']); $alt[] = $urldata['scheme'].'://'.$urldata['host'].(($file[0] == '/') ? '' : '/').$file; } // $alt = array_unique($alt); foreach ($alt as $path) { if (!self::file_exists($path)) { continue; } $ret = @file_get_contents($path); if ( $ret != false ) { return $ret; } // try to use CURL for URLs if (!ini_get('allow_url_fopen') && function_exists('curl_init') && preg_match('%^(https?|ftp)://%', $path) ) { // try to get remote file data using cURL $crs = curl_init(); $curlopts = []; if ( (ini_get('open_basedir') == '') && (ini_get('safe_mode') === '' || ini_get('safe_mode') === false) ) { $curlopts[CURLOPT_FOLLOWLOCATION] = true; } $curlopts = array_replace($curlopts, self::CURLOPT_DEFAULT); $curlopts = array_replace($curlopts, K_CURLOPTS); $curlopts = array_replace($curlopts, self::CURLOPT_FIXED); $curlopts[CURLOPT_URL] = $url; curl_setopt_array($crs, $curlopts); $ret = curl_exec($crs); curl_close($crs); if ($ret !== false) { return $ret; } } } return false; } /** * Get ULONG from string (Big Endian 32-bit unsigned integer). * @param string $str string from where to extract value * @param int $offset point from where to read the data * @return int 32 bit value * @author Nicola Asuni * @since 5.2.000 (2010-06-02) * @public static */ public static function _getULONG($str, $offset) { $v = unpack('Ni', substr($str, $offset, 4)); return $v['i']; } /** * Get USHORT from string (Big Endian 16-bit unsigned integer). * @param string $str string from where to extract value * @param int $offset point from where to read the data * @return int 16 bit value * @author Nicola Asuni * @since 5.2.000 (2010-06-02) * @public static */ public static function _getUSHORT($str, $offset) { $v = unpack('ni', substr($str, $offset, 2)); return $v['i']; } /** * Get SHORT from string (Big Endian 16-bit signed integer). * @param string $str String from where to extract value. * @param int $offset Point from where to read the data. * @return int 16 bit value * @author Nicola Asuni * @since 5.2.000 (2010-06-02) * @public static */ public static function _getSHORT($str, $offset) { $v = unpack('si', substr($str, $offset, 2)); return $v['i']; } /** * Get FWORD from string (Big Endian 16-bit signed integer). * @param string $str String from where to extract value. * @param int $offset Point from where to read the data. * @return int 16 bit value * @author Nicola Asuni * @since 5.9.123 (2011-09-30) * @public static */ public static function _getFWORD($str, $offset) { $v = self::_getUSHORT($str, $offset); if ($v > 0x7fff) { $v -= 0x10000; } return $v; } /** * Get UFWORD from string (Big Endian 16-bit unsigned integer). * @param string $str string from where to extract value * @param int $offset point from where to read the data * @return int 16 bit value * @author Nicola Asuni * @since 5.9.123 (2011-09-30) * @public static */ public static function _getUFWORD($str, $offset) { $v = self::_getUSHORT($str, $offset); return $v; } /** * Get FIXED from string (32-bit signed fixed-point number (16.16). * @param string $str string from where to extract value * @param int $offset point from where to read the data * @return int 16 bit value * @author Nicola Asuni * @since 5.9.123 (2011-09-30) * @public static */ public static function _getFIXED($str, $offset) { // mantissa $m = self::_getFWORD($str, $offset); // fraction $f = self::_getUSHORT($str, ($offset + 2)); $v = floatval(''.$m.'.'.$f.''); return $v; } /** * Get BYTE from string (8-bit unsigned integer). * @param string $str String from where to extract value. * @param int $offset Point from where to read the data. * @return int 8 bit value * @author Nicola Asuni * @since 5.2.000 (2010-06-02) * @public static */ public static function _getBYTE($str, $offset) { $v = unpack('Ci', substr($str, $offset, 1)); return $v['i']; } /** * Binary-safe and URL-safe file read. * Reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read; EOF (end of file) is reached. * @param resource $handle * @param int $length * @return string|false Returns the read string or FALSE in case of error. * @author Nicola Asuni * @since 4.5.027 (2009-03-16) * @public static */ public static function rfread($handle, $length) { $data = fread($handle, $length); if ($data === false) { return false; } $rest = ($length - strlen($data)); if (($rest > 0) && !feof($handle)) { $data .= self::rfread($handle, $rest); } return $data; } /** * Read a 4-byte (32 bit) integer from file. * @param resource $f file resource. * @return int 4-byte integer * @public static */ public static function _freadint($f) { $a = unpack('Ni', fread($f, 4)); return $a['i']; } /** * Array of page formats * measures are calculated in this way: (inches * 72) or (millimeters * 72 / 25.4) * @public static * * @var array */ public static $page_formats = array( // ISO 216 A Series + 2 SIS 014711 extensions 'A0' => array( 2383.937, 3370.394), // = ( 841 x 1189 ) mm = ( 33.11 x 46.81 ) in 'A1' => array( 1683.780, 2383.937), // = ( 594 x 841 ) mm = ( 23.39 x 33.11 ) in 'A2' => array( 1190.551, 1683.780), // = ( 420 x 594 ) mm = ( 16.54 x 23.39 ) in 'A3' => array( 841.890, 1190.551), // = ( 297 x 420 ) mm = ( 11.69 x 16.54 ) in 'A4' => array( 595.276, 841.890), // = ( 210 x 297 ) mm = ( 8.27 x 11.69 ) in 'A5' => array( 419.528, 595.276), // = ( 148 x 210 ) mm = ( 5.83 x 8.27 ) in 'A6' => array( 297.638, 419.528), // = ( 105 x 148 ) mm = ( 4.13 x 5.83 ) in 'A7' => array( 209.764, 297.638), // = ( 74 x 105 ) mm = ( 2.91 x 4.13 ) in 'A8' => array( 147.402, 209.764), // = ( 52 x 74 ) mm = ( 2.05 x 2.91 ) in 'A9' => array( 104.882, 147.402), // = ( 37 x 52 ) mm = ( 1.46 x 2.05 ) in 'A10' => array( 73.701, 104.882), // = ( 26 x 37 ) mm = ( 1.02 x 1.46 ) in 'A11' => array( 51.024, 73.701), // = ( 18 x 26 ) mm = ( 0.71 x 1.02 ) in 'A12' => array( 36.850, 51.024), // = ( 13 x 18 ) mm = ( 0.51 x 0.71 ) in // ISO 216 B Series + 2 SIS 014711 extensions 'B0' => array( 2834.646, 4008.189), // = ( 1000 x 1414 ) mm = ( 39.37 x 55.67 ) in 'B1' => array( 2004.094, 2834.646), // = ( 707 x 1000 ) mm = ( 27.83 x 39.37 ) in 'B2' => array( 1417.323, 2004.094), // = ( 500 x 707 ) mm = ( 19.69 x 27.83 ) in 'B3' => array( 1000.630, 1417.323), // = ( 353 x 500 ) mm = ( 13.90 x 19.69 ) in 'B4' => array( 708.661, 1000.630), // = ( 250 x 353 ) mm = ( 9.84 x 13.90 ) in 'B5' => array( 498.898, 708.661), // = ( 176 x 250 ) mm = ( 6.93 x 9.84 ) in 'B6' => array( 354.331, 498.898), // = ( 125 x 176 ) mm = ( 4.92 x 6.93 ) in 'B7' => array( 249.449, 354.331), // = ( 88 x 125 ) mm = ( 3.46 x 4.92 ) in 'B8' => array( 175.748, 249.449), // = ( 62 x 88 ) mm = ( 2.44 x 3.46 ) in 'B9' => array( 124.724, 175.748), // = ( 44 x 62 ) mm = ( 1.73 x 2.44 ) in 'B10' => array( 87.874, 124.724), // = ( 31 x 44 ) mm = ( 1.22 x 1.73 ) in 'B11' => array( 62.362, 87.874), // = ( 22 x 31 ) mm = ( 0.87 x 1.22 ) in 'B12' => array( 42.520, 62.362), // = ( 15 x 22 ) mm = ( 0.59 x 0.87 ) in // ISO 216 C Series + 2 SIS 014711 extensions + 5 EXTENSION 'C0' => array( 2599.370, 3676.535), // = ( 917 x 1297 ) mm = ( 36.10 x 51.06 ) in 'C1' => array( 1836.850, 2599.370), // = ( 648 x 917 ) mm = ( 25.51 x 36.10 ) in 'C2' => array( 1298.268, 1836.850), // = ( 458 x 648 ) mm = ( 18.03 x 25.51 ) in 'C3' => array( 918.425, 1298.268), // = ( 324 x 458 ) mm = ( 12.76 x 18.03 ) in 'C4' => array( 649.134, 918.425), // = ( 229 x 324 ) mm = ( 9.02 x 12.76 ) in 'C5' => array( 459.213, 649.134), // = ( 162 x 229 ) mm = ( 6.38 x 9.02 ) in 'C6' => array( 323.150, 459.213), // = ( 114 x 162 ) mm = ( 4.49 x 6.38 ) in 'C7' => array( 229.606, 323.150), // = ( 81 x 114 ) mm = ( 3.19 x 4.49 ) in 'C8' => array( 161.575, 229.606), // = ( 57 x 81 ) mm = ( 2.24 x 3.19 ) in 'C9' => array( 113.386, 161.575), // = ( 40 x 57 ) mm = ( 1.57 x 2.24 ) in 'C10' => array( 79.370, 113.386), // = ( 28 x 40 ) mm = ( 1.10 x 1.57 ) in 'C11' => array( 56.693, 79.370), // = ( 20 x 28 ) mm = ( 0.79 x 1.10 ) in 'C12' => array( 39.685, 56.693), // = ( 14 x 20 ) mm = ( 0.55 x 0.79 ) in 'C76' => array( 229.606, 459.213), // = ( 81 x 162 ) mm = ( 3.19 x 6.38 ) in 'DL' => array( 311.811, 623.622), // = ( 110 x 220 ) mm = ( 4.33 x 8.66 ) in 'DLE' => array( 323.150, 637.795), // = ( 114 x 225 ) mm = ( 4.49 x 8.86 ) in 'DLX' => array( 340.158, 666.142), // = ( 120 x 235 ) mm = ( 4.72 x 9.25 ) in 'DLP' => array( 280.630, 595.276), // = ( 99 x 210 ) mm = ( 3.90 x 8.27 ) in (1/3 A4) // SIS 014711 E Series 'E0' => array( 2491.654, 3517.795), // = ( 879 x 1241 ) mm = ( 34.61 x 48.86 ) in 'E1' => array( 1757.480, 2491.654), // = ( 620 x 879 ) mm = ( 24.41 x 34.61 ) in 'E2' => array( 1247.244, 1757.480), // = ( 440 x 620 ) mm = ( 17.32 x 24.41 ) in 'E3' => array( 878.740, 1247.244), // = ( 310 x 440 ) mm = ( 12.20 x 17.32 ) in 'E4' => array( 623.622, 878.740), // = ( 220 x 310 ) mm = ( 8.66 x 12.20 ) in 'E5' => array( 439.370, 623.622), // = ( 155 x 220 ) mm = ( 6.10 x 8.66 ) in 'E6' => array( 311.811, 439.370), // = ( 110 x 155 ) mm = ( 4.33 x 6.10 ) in 'E7' => array( 221.102, 311.811), // = ( 78 x 110 ) mm = ( 3.07 x 4.33 ) in 'E8' => array( 155.906, 221.102), // = ( 55 x 78 ) mm = ( 2.17 x 3.07 ) in 'E9' => array( 110.551, 155.906), // = ( 39 x 55 ) mm = ( 1.54 x 2.17 ) in 'E10' => array( 76.535, 110.551), // = ( 27 x 39 ) mm = ( 1.06 x 1.54 ) in 'E11' => array( 53.858, 76.535), // = ( 19 x 27 ) mm = ( 0.75 x 1.06 ) in 'E12' => array( 36.850, 53.858), // = ( 13 x 19 ) mm = ( 0.51 x 0.75 ) in // SIS 014711 G Series 'G0' => array( 2715.591, 3838.110), // = ( 958 x 1354 ) mm = ( 37.72 x 53.31 ) in 'G1' => array( 1919.055, 2715.591), // = ( 677 x 958 ) mm = ( 26.65 x 37.72 ) in 'G2' => array( 1357.795, 1919.055), // = ( 479 x 677 ) mm = ( 18.86 x 26.65 ) in 'G3' => array( 958.110, 1357.795), // = ( 338 x 479 ) mm = ( 13.31 x 18.86 ) in 'G4' => array( 677.480, 958.110), // = ( 239 x 338 ) mm = ( 9.41 x 13.31 ) in 'G5' => array( 479.055, 677.480), // = ( 169 x 239 ) mm = ( 6.65 x 9.41 ) in 'G6' => array( 337.323, 479.055), // = ( 119 x 169 ) mm = ( 4.69 x 6.65 ) in 'G7' => array( 238.110, 337.323), // = ( 84 x 119 ) mm = ( 3.31 x 4.69 ) in 'G8' => array( 167.244, 238.110), // = ( 59 x 84 ) mm = ( 2.32 x 3.31 ) in 'G9' => array( 119.055, 167.244), // = ( 42 x 59 ) mm = ( 1.65 x 2.32 ) in 'G10' => array( 82.205, 119.055), // = ( 29 x 42 ) mm = ( 1.14 x 1.65 ) in 'G11' => array( 59.528, 82.205), // = ( 21 x 29 ) mm = ( 0.83 x 1.14 ) in 'G12' => array( 39.685, 59.528), // = ( 14 x 21 ) mm = ( 0.55 x 0.83 ) in // ISO Press 'RA0' => array( 2437.795, 3458.268), // = ( 860 x 1220 ) mm = ( 33.86 x 48.03 ) in 'RA1' => array( 1729.134, 2437.795), // = ( 610 x 860 ) mm = ( 24.02 x 33.86 ) in 'RA2' => array( 1218.898, 1729.134), // = ( 430 x 610 ) mm = ( 16.93 x 24.02 ) in 'RA3' => array( 864.567, 1218.898), // = ( 305 x 430 ) mm = ( 12.01 x 16.93 ) in 'RA4' => array( 609.449, 864.567), // = ( 215 x 305 ) mm = ( 8.46 x 12.01 ) in 'SRA0' => array( 2551.181, 3628.346), // = ( 900 x 1280 ) mm = ( 35.43 x 50.39 ) in 'SRA1' => array( 1814.173, 2551.181), // = ( 640 x 900 ) mm = ( 25.20 x 35.43 ) in 'SRA2' => array( 1275.591, 1814.173), // = ( 450 x 640 ) mm = ( 17.72 x 25.20 ) in 'SRA3' => array( 907.087, 1275.591), // = ( 320 x 450 ) mm = ( 12.60 x 17.72 ) in 'SRA4' => array( 637.795, 907.087), // = ( 225 x 320 ) mm = ( 8.86 x 12.60 ) in // German DIN 476 '4A0' => array( 4767.874, 6740.787), // = ( 1682 x 2378 ) mm = ( 66.22 x 93.62 ) in '2A0' => array( 3370.394, 4767.874), // = ( 1189 x 1682 ) mm = ( 46.81 x 66.22 ) in // Variations on the ISO Standard 'A2_EXTRA' => array( 1261.417, 1754.646), // = ( 445 x 619 ) mm = ( 17.52 x 24.37 ) in 'A3+' => array( 932.598, 1369.134), // = ( 329 x 483 ) mm = ( 12.95 x 19.02 ) in 'A3_EXTRA' => array( 912.756, 1261.417), // = ( 322 x 445 ) mm = ( 12.68 x 17.52 ) in 'A3_SUPER' => array( 864.567, 1440.000), // = ( 305 x 508 ) mm = ( 12.01 x 20.00 ) in 'SUPER_A3' => array( 864.567, 1380.472), // = ( 305 x 487 ) mm = ( 12.01 x 19.17 ) in 'A4_EXTRA' => array( 666.142, 912.756), // = ( 235 x 322 ) mm = ( 9.25 x 12.68 ) in 'A4_SUPER' => array( 649.134, 912.756), // = ( 229 x 322 ) mm = ( 9.02 x 12.68 ) in 'SUPER_A4' => array( 643.465, 1009.134), // = ( 227 x 356 ) mm = ( 8.94 x 14.02 ) in 'A4_LONG' => array( 595.276, 986.457), // = ( 210 x 348 ) mm = ( 8.27 x 13.70 ) in 'F4' => array( 595.276, 935.433), // = ( 210 x 330 ) mm = ( 8.27 x 12.99 ) in 'SO_B5_EXTRA' => array( 572.598, 782.362), // = ( 202 x 276 ) mm = ( 7.95 x 10.87 ) in 'A5_EXTRA' => array( 490.394, 666.142), // = ( 173 x 235 ) mm = ( 6.81 x 9.25 ) in // ANSI Series 'ANSI_E' => array( 2448.000, 3168.000), // = ( 864 x 1118 ) mm = ( 34.00 x 44.00 ) in 'ANSI_D' => array( 1584.000, 2448.000), // = ( 559 x 864 ) mm = ( 22.00 x 34.00 ) in 'ANSI_C' => array( 1224.000, 1584.000), // = ( 432 x 559 ) mm = ( 17.00 x 22.00 ) in 'ANSI_B' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in 'ANSI_A' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in // Traditional 'Loose' North American Paper Sizes 'USLEDGER' => array( 1224.000, 792.000), // = ( 432 x 279 ) mm = ( 17.00 x 11.00 ) in 'LEDGER' => array( 1224.000, 792.000), // = ( 432 x 279 ) mm = ( 17.00 x 11.00 ) in 'ORGANIZERK' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in 'BIBLE' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in 'USTABLOID' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in 'TABLOID' => array( 792.000, 1224.000), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in 'ORGANIZERM' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in 'USLETTER' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in 'LETTER' => array( 612.000, 792.000), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in 'USLEGAL' => array( 612.000, 1008.000), // = ( 216 x 356 ) mm = ( 8.50 x 14.00 ) in 'LEGAL' => array( 612.000, 1008.000), // = ( 216 x 356 ) mm = ( 8.50 x 14.00 ) in 'GOVERNMENTLETTER' => array( 576.000, 756.000), // = ( 203 x 267 ) mm = ( 8.00 x 10.50 ) in 'GLETTER' => array( 576.000, 756.000), // = ( 203 x 267 ) mm = ( 8.00 x 10.50 ) in 'JUNIORLEGAL' => array( 576.000, 360.000), // = ( 203 x 127 ) mm = ( 8.00 x 5.00 ) in 'JLEGAL' => array( 576.000, 360.000), // = ( 203 x 127 ) mm = ( 8.00 x 5.00 ) in // Other North American Paper Sizes 'QUADDEMY' => array( 2520.000, 3240.000), // = ( 889 x 1143 ) mm = ( 35.00 x 45.00 ) in 'SUPER_B' => array( 936.000, 1368.000), // = ( 330 x 483 ) mm = ( 13.00 x 19.00 ) in 'QUARTO' => array( 648.000, 792.000), // = ( 229 x 279 ) mm = ( 9.00 x 11.00 ) in 'GOVERNMENTLEGAL' => array( 612.000, 936.000), // = ( 216 x 330 ) mm = ( 8.50 x 13.00 ) in 'FOLIO' => array( 612.000, 936.000), // = ( 216 x 330 ) mm = ( 8.50 x 13.00 ) in 'MONARCH' => array( 522.000, 756.000), // = ( 184 x 267 ) mm = ( 7.25 x 10.50 ) in 'EXECUTIVE' => array( 522.000, 756.000), // = ( 184 x 267 ) mm = ( 7.25 x 10.50 ) in 'ORGANIZERL' => array( 396.000, 612.000), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in 'STATEMENT' => array( 396.000, 612.000), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in 'MEMO' => array( 396.000, 612.000), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in 'FOOLSCAP' => array( 595.440, 936.000), // = ( 210 x 330 ) mm = ( 8.27 x 13.00 ) in 'COMPACT' => array( 306.000, 486.000), // = ( 108 x 171 ) mm = ( 4.25 x 6.75 ) in 'ORGANIZERJ' => array( 198.000, 360.000), // = ( 70 x 127 ) mm = ( 2.75 x 5.00 ) in // Canadian standard CAN 2-9.60M 'P1' => array( 1587.402, 2437.795), // = ( 560 x 860 ) mm = ( 22.05 x 33.86 ) in 'P2' => array( 1218.898, 1587.402), // = ( 430 x 560 ) mm = ( 16.93 x 22.05 ) in 'P3' => array( 793.701, 1218.898), // = ( 280 x 430 ) mm = ( 11.02 x 16.93 ) in 'P4' => array( 609.449, 793.701), // = ( 215 x 280 ) mm = ( 8.46 x 11.02 ) in 'P5' => array( 396.850, 609.449), // = ( 140 x 215 ) mm = ( 5.51 x 8.46 ) in 'P6' => array( 303.307, 396.850), // = ( 107 x 140 ) mm = ( 4.21 x 5.51 ) in // North American Architectural Sizes 'ARCH_E' => array( 2592.000, 3456.000), // = ( 914 x 1219 ) mm = ( 36.00 x 48.00 ) in 'ARCH_E1' => array( 2160.000, 3024.000), // = ( 762 x 1067 ) mm = ( 30.00 x 42.00 ) in 'ARCH_D' => array( 1728.000, 2592.000), // = ( 610 x 914 ) mm = ( 24.00 x 36.00 ) in 'BROADSHEET' => array( 1296.000, 1728.000), // = ( 457 x 610 ) mm = ( 18.00 x 24.00 ) in 'ARCH_C' => array( 1296.000, 1728.000), // = ( 457 x 610 ) mm = ( 18.00 x 24.00 ) in 'ARCH_B' => array( 864.000, 1296.000), // = ( 305 x 457 ) mm = ( 12.00 x 18.00 ) in 'ARCH_A' => array( 648.000, 864.000), // = ( 229 x 305 ) mm = ( 9.00 x 12.00 ) in // -- North American Envelope Sizes // - Announcement Envelopes 'ANNENV_A2' => array( 314.640, 414.000), // = ( 111 x 146 ) mm = ( 4.37 x 5.75 ) in 'ANNENV_A6' => array( 342.000, 468.000), // = ( 121 x 165 ) mm = ( 4.75 x 6.50 ) in 'ANNENV_A7' => array( 378.000, 522.000), // = ( 133 x 184 ) mm = ( 5.25 x 7.25 ) in 'ANNENV_A8' => array( 396.000, 584.640), // = ( 140 x 206 ) mm = ( 5.50 x 8.12 ) in 'ANNENV_A10' => array( 450.000, 692.640), // = ( 159 x 244 ) mm = ( 6.25 x 9.62 ) in 'ANNENV_SLIM' => array( 278.640, 638.640), // = ( 98 x 225 ) mm = ( 3.87 x 8.87 ) in // - Commercial Envelopes 'COMMENV_N6_1/4' => array( 252.000, 432.000), // = ( 89 x 152 ) mm = ( 3.50 x 6.00 ) in 'COMMENV_N6_3/4' => array( 260.640, 468.000), // = ( 92 x 165 ) mm = ( 3.62 x 6.50 ) in 'COMMENV_N8' => array( 278.640, 540.000), // = ( 98 x 191 ) mm = ( 3.87 x 7.50 ) in 'COMMENV_N9' => array( 278.640, 638.640), // = ( 98 x 225 ) mm = ( 3.87 x 8.87 ) in 'COMMENV_N10' => array( 296.640, 684.000), // = ( 105 x 241 ) mm = ( 4.12 x 9.50 ) in 'COMMENV_N11' => array( 324.000, 746.640), // = ( 114 x 263 ) mm = ( 4.50 x 10.37 ) in 'COMMENV_N12' => array( 342.000, 792.000), // = ( 121 x 279 ) mm = ( 4.75 x 11.00 ) in 'COMMENV_N14' => array( 360.000, 828.000), // = ( 127 x 292 ) mm = ( 5.00 x 11.50 ) in // - Catalogue Envelopes 'CATENV_N1' => array( 432.000, 648.000), // = ( 152 x 229 ) mm = ( 6.00 x 9.00 ) in 'CATENV_N1_3/4' => array( 468.000, 684.000), // = ( 165 x 241 ) mm = ( 6.50 x 9.50 ) in 'CATENV_N2' => array( 468.000, 720.000), // = ( 165 x 254 ) mm = ( 6.50 x 10.00 ) in 'CATENV_N3' => array( 504.000, 720.000), // = ( 178 x 254 ) mm = ( 7.00 x 10.00 ) in 'CATENV_N6' => array( 540.000, 756.000), // = ( 191 x 267 ) mm = ( 7.50 x 10.50 ) in 'CATENV_N7' => array( 576.000, 792.000), // = ( 203 x 279 ) mm = ( 8.00 x 11.00 ) in 'CATENV_N8' => array( 594.000, 810.000), // = ( 210 x 286 ) mm = ( 8.25 x 11.25 ) in 'CATENV_N9_1/2' => array( 612.000, 756.000), // = ( 216 x 267 ) mm = ( 8.50 x 10.50 ) in 'CATENV_N9_3/4' => array( 630.000, 810.000), // = ( 222 x 286 ) mm = ( 8.75 x 11.25 ) in 'CATENV_N10_1/2' => array( 648.000, 864.000), // = ( 229 x 305 ) mm = ( 9.00 x 12.00 ) in 'CATENV_N12_1/2' => array( 684.000, 900.000), // = ( 241 x 318 ) mm = ( 9.50 x 12.50 ) in 'CATENV_N13_1/2' => array( 720.000, 936.000), // = ( 254 x 330 ) mm = ( 10.00 x 13.00 ) in 'CATENV_N14_1/4' => array( 810.000, 882.000), // = ( 286 x 311 ) mm = ( 11.25 x 12.25 ) in 'CATENV_N14_1/2' => array( 828.000, 1044.000), // = ( 292 x 368 ) mm = ( 11.50 x 14.50 ) in // Japanese (JIS P 0138-61) Standard B-Series 'JIS_B0' => array( 2919.685, 4127.244), // = ( 1030 x 1456 ) mm = ( 40.55 x 57.32 ) in 'JIS_B1' => array( 2063.622, 2919.685), // = ( 728 x 1030 ) mm = ( 28.66 x 40.55 ) in 'JIS_B2' => array( 1459.843, 2063.622), // = ( 515 x 728 ) mm = ( 20.28 x 28.66 ) in 'JIS_B3' => array( 1031.811, 1459.843), // = ( 364 x 515 ) mm = ( 14.33 x 20.28 ) in 'JIS_B4' => array( 728.504, 1031.811), // = ( 257 x 364 ) mm = ( 10.12 x 14.33 ) in 'JIS_B5' => array( 515.906, 728.504), // = ( 182 x 257 ) mm = ( 7.17 x 10.12 ) in 'JIS_B6' => array( 362.835, 515.906), // = ( 128 x 182 ) mm = ( 5.04 x 7.17 ) in 'JIS_B7' => array( 257.953, 362.835), // = ( 91 x 128 ) mm = ( 3.58 x 5.04 ) in 'JIS_B8' => array( 181.417, 257.953), // = ( 64 x 91 ) mm = ( 2.52 x 3.58 ) in 'JIS_B9' => array( 127.559, 181.417), // = ( 45 x 64 ) mm = ( 1.77 x 2.52 ) in 'JIS_B10' => array( 90.709, 127.559), // = ( 32 x 45 ) mm = ( 1.26 x 1.77 ) in 'JIS_B11' => array( 62.362, 90.709), // = ( 22 x 32 ) mm = ( 0.87 x 1.26 ) in 'JIS_B12' => array( 45.354, 62.362), // = ( 16 x 22 ) mm = ( 0.63 x 0.87 ) in // PA Series 'PA0' => array( 2381.102, 3174.803), // = ( 840 x 1120 ) mm = ( 33.07 x 44.09 ) in 'PA1' => array( 1587.402, 2381.102), // = ( 560 x 840 ) mm = ( 22.05 x 33.07 ) in 'PA2' => array( 1190.551, 1587.402), // = ( 420 x 560 ) mm = ( 16.54 x 22.05 ) in 'PA3' => array( 793.701, 1190.551), // = ( 280 x 420 ) mm = ( 11.02 x 16.54 ) in 'PA4' => array( 595.276, 793.701), // = ( 210 x 280 ) mm = ( 8.27 x 11.02 ) in 'PA5' => array( 396.850, 595.276), // = ( 140 x 210 ) mm = ( 5.51 x 8.27 ) in 'PA6' => array( 297.638, 396.850), // = ( 105 x 140 ) mm = ( 4.13 x 5.51 ) in 'PA7' => array( 198.425, 297.638), // = ( 70 x 105 ) mm = ( 2.76 x 4.13 ) in 'PA8' => array( 147.402, 198.425), // = ( 52 x 70 ) mm = ( 2.05 x 2.76 ) in 'PA9' => array( 99.213, 147.402), // = ( 35 x 52 ) mm = ( 1.38 x 2.05 ) in 'PA10' => array( 73.701, 99.213), // = ( 26 x 35 ) mm = ( 1.02 x 1.38 ) in // Standard Photographic Print Sizes 'PASSPORT_PHOTO' => array( 99.213, 127.559), // = ( 35 x 45 ) mm = ( 1.38 x 1.77 ) in 'E' => array( 233.858, 340.157), // = ( 82 x 120 ) mm = ( 3.25 x 4.72 ) in 'L' => array( 252.283, 360.000), // = ( 89 x 127 ) mm = ( 3.50 x 5.00 ) in '3R' => array( 252.283, 360.000), // = ( 89 x 127 ) mm = ( 3.50 x 5.00 ) in 'KG' => array( 289.134, 430.866), // = ( 102 x 152 ) mm = ( 4.02 x 5.98 ) in '4R' => array( 289.134, 430.866), // = ( 102 x 152 ) mm = ( 4.02 x 5.98 ) in '4D' => array( 340.157, 430.866), // = ( 120 x 152 ) mm = ( 4.72 x 5.98 ) in '2L' => array( 360.000, 504.567), // = ( 127 x 178 ) mm = ( 5.00 x 7.01 ) in '5R' => array( 360.000, 504.567), // = ( 127 x 178 ) mm = ( 5.00 x 7.01 ) in '8P' => array( 430.866, 575.433), // = ( 152 x 203 ) mm = ( 5.98 x 7.99 ) in '6R' => array( 430.866, 575.433), // = ( 152 x 203 ) mm = ( 5.98 x 7.99 ) in '6P' => array( 575.433, 720.000), // = ( 203 x 254 ) mm = ( 7.99 x 10.00 ) in '8R' => array( 575.433, 720.000), // = ( 203 x 254 ) mm = ( 7.99 x 10.00 ) in '6PW' => array( 575.433, 864.567), // = ( 203 x 305 ) mm = ( 7.99 x 12.01 ) in 'S8R' => array( 575.433, 864.567), // = ( 203 x 305 ) mm = ( 7.99 x 12.01 ) in '4P' => array( 720.000, 864.567), // = ( 254 x 305 ) mm = ( 10.00 x 12.01 ) in '10R' => array( 720.000, 864.567), // = ( 254 x 305 ) mm = ( 10.00 x 12.01 ) in '4PW' => array( 720.000, 1080.000), // = ( 254 x 381 ) mm = ( 10.00 x 15.00 ) in 'S10R' => array( 720.000, 1080.000), // = ( 254 x 381 ) mm = ( 10.00 x 15.00 ) in '11R' => array( 790.866, 1009.134), // = ( 279 x 356 ) mm = ( 10.98 x 14.02 ) in 'S11R' => array( 790.866, 1224.567), // = ( 279 x 432 ) mm = ( 10.98 x 17.01 ) in '12R' => array( 864.567, 1080.000), // = ( 305 x 381 ) mm = ( 12.01 x 15.00 ) in 'S12R' => array( 864.567, 1292.598), // = ( 305 x 456 ) mm = ( 12.01 x 17.95 ) in // Common Newspaper Sizes 'NEWSPAPER_BROADSHEET' => array( 2125.984, 1700.787), // = ( 750 x 600 ) mm = ( 29.53 x 23.62 ) in 'NEWSPAPER_BERLINER' => array( 1332.283, 892.913), // = ( 470 x 315 ) mm = ( 18.50 x 12.40 ) in 'NEWSPAPER_TABLOID' => array( 1218.898, 793.701), // = ( 430 x 280 ) mm = ( 16.93 x 11.02 ) in 'NEWSPAPER_COMPACT' => array( 1218.898, 793.701), // = ( 430 x 280 ) mm = ( 16.93 x 11.02 ) in // Business Cards 'CREDIT_CARD' => array( 153.014, 242.646), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in 'BUSINESS_CARD' => array( 153.014, 242.646), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in 'BUSINESS_CARD_ISO7810' => array( 153.014, 242.646), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in 'BUSINESS_CARD_ISO216' => array( 147.402, 209.764), // = ( 52 x 74 ) mm = ( 2.05 x 2.91 ) in 'BUSINESS_CARD_IT' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in 'BUSINESS_CARD_UK' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in 'BUSINESS_CARD_FR' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in 'BUSINESS_CARD_DE' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in 'BUSINESS_CARD_ES' => array( 155.906, 240.945), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in 'BUSINESS_CARD_CA' => array( 144.567, 252.283), // = ( 51 x 89 ) mm = ( 2.01 x 3.50 ) in 'BUSINESS_CARD_US' => array( 144.567, 252.283), // = ( 51 x 89 ) mm = ( 2.01 x 3.50 ) in 'BUSINESS_CARD_JP' => array( 155.906, 257.953), // = ( 55 x 91 ) mm = ( 2.17 x 3.58 ) in 'BUSINESS_CARD_HK' => array( 153.071, 255.118), // = ( 54 x 90 ) mm = ( 2.13 x 3.54 ) in 'BUSINESS_CARD_AU' => array( 155.906, 255.118), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in 'BUSINESS_CARD_DK' => array( 155.906, 255.118), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in 'BUSINESS_CARD_SE' => array( 155.906, 255.118), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in 'BUSINESS_CARD_RU' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in 'BUSINESS_CARD_CZ' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in 'BUSINESS_CARD_FI' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in 'BUSINESS_CARD_HU' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in 'BUSINESS_CARD_IL' => array( 141.732, 255.118), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in // Billboards '4SHEET' => array( 2880.000, 4320.000), // = ( 1016 x 1524 ) mm = ( 40.00 x 60.00 ) in '6SHEET' => array( 3401.575, 5102.362), // = ( 1200 x 1800 ) mm = ( 47.24 x 70.87 ) in '12SHEET' => array( 8640.000, 4320.000), // = ( 3048 x 1524 ) mm = (120.00 x 60.00 ) in '16SHEET' => array( 5760.000, 8640.000), // = ( 2032 x 3048 ) mm = ( 80.00 x 120.00) in '32SHEET' => array(11520.000, 8640.000), // = ( 4064 x 3048 ) mm = (160.00 x 120.00) in '48SHEET' => array(17280.000, 8640.000), // = ( 6096 x 3048 ) mm = (240.00 x 120.00) in '64SHEET' => array(23040.000, 8640.000), // = ( 8128 x 3048 ) mm = (320.00 x 120.00) in '96SHEET' => array(34560.000, 8640.000), // = (12192 x 3048 ) mm = (480.00 x 120.00) in // -- Old European Sizes // - Old Imperial English Sizes 'EN_EMPEROR' => array( 3456.000, 5184.000), // = ( 1219 x 1829 ) mm = ( 48.00 x 72.00 ) in 'EN_ANTIQUARIAN' => array( 2232.000, 3816.000), // = ( 787 x 1346 ) mm = ( 31.00 x 53.00 ) in 'EN_GRAND_EAGLE' => array( 2070.000, 3024.000), // = ( 730 x 1067 ) mm = ( 28.75 x 42.00 ) in 'EN_DOUBLE_ELEPHANT' => array( 1926.000, 2880.000), // = ( 679 x 1016 ) mm = ( 26.75 x 40.00 ) in 'EN_ATLAS' => array( 1872.000, 2448.000), // = ( 660 x 864 ) mm = ( 26.00 x 34.00 ) in 'EN_COLOMBIER' => array( 1692.000, 2484.000), // = ( 597 x 876 ) mm = ( 23.50 x 34.50 ) in 'EN_ELEPHANT' => array( 1656.000, 2016.000), // = ( 584 x 711 ) mm = ( 23.00 x 28.00 ) in 'EN_DOUBLE_DEMY' => array( 1620.000, 2556.000), // = ( 572 x 902 ) mm = ( 22.50 x 35.50 ) in 'EN_IMPERIAL' => array( 1584.000, 2160.000), // = ( 559 x 762 ) mm = ( 22.00 x 30.00 ) in 'EN_PRINCESS' => array( 1548.000, 2016.000), // = ( 546 x 711 ) mm = ( 21.50 x 28.00 ) in 'EN_CARTRIDGE' => array( 1512.000, 1872.000), // = ( 533 x 660 ) mm = ( 21.00 x 26.00 ) in 'EN_DOUBLE_LARGE_POST' => array( 1512.000, 2376.000), // = ( 533 x 838 ) mm = ( 21.00 x 33.00 ) in 'EN_ROYAL' => array( 1440.000, 1800.000), // = ( 508 x 635 ) mm = ( 20.00 x 25.00 ) in 'EN_SHEET' => array( 1404.000, 1692.000), // = ( 495 x 597 ) mm = ( 19.50 x 23.50 ) in 'EN_HALF_POST' => array( 1404.000, 1692.000), // = ( 495 x 597 ) mm = ( 19.50 x 23.50 ) in 'EN_SUPER_ROYAL' => array( 1368.000, 1944.000), // = ( 483 x 686 ) mm = ( 19.00 x 27.00 ) in 'EN_DOUBLE_POST' => array( 1368.000, 2196.000), // = ( 483 x 775 ) mm = ( 19.00 x 30.50 ) in 'EN_MEDIUM' => array( 1260.000, 1656.000), // = ( 445 x 584 ) mm = ( 17.50 x 23.00 ) in 'EN_DEMY' => array( 1260.000, 1620.000), // = ( 445 x 572 ) mm = ( 17.50 x 22.50 ) in 'EN_LARGE_POST' => array( 1188.000, 1512.000), // = ( 419 x 533 ) mm = ( 16.50 x 21.00 ) in 'EN_COPY_DRAUGHT' => array( 1152.000, 1440.000), // = ( 406 x 508 ) mm = ( 16.00 x 20.00 ) in 'EN_POST' => array( 1116.000, 1386.000), // = ( 394 x 489 ) mm = ( 15.50 x 19.25 ) in 'EN_CROWN' => array( 1080.000, 1440.000), // = ( 381 x 508 ) mm = ( 15.00 x 20.00 ) in 'EN_PINCHED_POST' => array( 1062.000, 1332.000), // = ( 375 x 470 ) mm = ( 14.75 x 18.50 ) in 'EN_BRIEF' => array( 972.000, 1152.000), // = ( 343 x 406 ) mm = ( 13.50 x 16.00 ) in 'EN_FOOLSCAP' => array( 972.000, 1224.000), // = ( 343 x 432 ) mm = ( 13.50 x 17.00 ) in 'EN_SMALL_FOOLSCAP' => array( 954.000, 1188.000), // = ( 337 x 419 ) mm = ( 13.25 x 16.50 ) in 'EN_POTT' => array( 900.000, 1080.000), // = ( 318 x 381 ) mm = ( 12.50 x 15.00 ) in // - Old Imperial Belgian Sizes 'BE_GRAND_AIGLE' => array( 1984.252, 2948.031), // = ( 700 x 1040 ) mm = ( 27.56 x 40.94 ) in 'BE_COLOMBIER' => array( 1757.480, 2409.449), // = ( 620 x 850 ) mm = ( 24.41 x 33.46 ) in 'BE_DOUBLE_CARRE' => array( 1757.480, 2607.874), // = ( 620 x 920 ) mm = ( 24.41 x 36.22 ) in 'BE_ELEPHANT' => array( 1746.142, 2182.677), // = ( 616 x 770 ) mm = ( 24.25 x 30.31 ) in 'BE_PETIT_AIGLE' => array( 1700.787, 2381.102), // = ( 600 x 840 ) mm = ( 23.62 x 33.07 ) in 'BE_GRAND_JESUS' => array( 1559.055, 2069.291), // = ( 550 x 730 ) mm = ( 21.65 x 28.74 ) in 'BE_JESUS' => array( 1530.709, 2069.291), // = ( 540 x 730 ) mm = ( 21.26 x 28.74 ) in 'BE_RAISIN' => array( 1417.323, 1842.520), // = ( 500 x 650 ) mm = ( 19.69 x 25.59 ) in 'BE_GRAND_MEDIAN' => array( 1303.937, 1714.961), // = ( 460 x 605 ) mm = ( 18.11 x 23.82 ) in 'BE_DOUBLE_POSTE' => array( 1233.071, 1601.575), // = ( 435 x 565 ) mm = ( 17.13 x 22.24 ) in 'BE_COQUILLE' => array( 1218.898, 1587.402), // = ( 430 x 560 ) mm = ( 16.93 x 22.05 ) in 'BE_PETIT_MEDIAN' => array( 1176.378, 1502.362), // = ( 415 x 530 ) mm = ( 16.34 x 20.87 ) in 'BE_RUCHE' => array( 1020.472, 1303.937), // = ( 360 x 460 ) mm = ( 14.17 x 18.11 ) in 'BE_PROPATRIA' => array( 977.953, 1218.898), // = ( 345 x 430 ) mm = ( 13.58 x 16.93 ) in 'BE_LYS' => array( 898.583, 1125.354), // = ( 317 x 397 ) mm = ( 12.48 x 15.63 ) in 'BE_POT' => array( 870.236, 1088.504), // = ( 307 x 384 ) mm = ( 12.09 x 15.12 ) in 'BE_ROSETTE' => array( 765.354, 983.622), // = ( 270 x 347 ) mm = ( 10.63 x 13.66 ) in // - Old Imperial French Sizes 'FR_UNIVERS' => array( 2834.646, 3685.039), // = ( 1000 x 1300 ) mm = ( 39.37 x 51.18 ) in 'FR_DOUBLE_COLOMBIER' => array( 2551.181, 3571.654), // = ( 900 x 1260 ) mm = ( 35.43 x 49.61 ) in 'FR_GRANDE_MONDE' => array( 2551.181, 3571.654), // = ( 900 x 1260 ) mm = ( 35.43 x 49.61 ) in 'FR_DOUBLE_SOLEIL' => array( 2267.717, 3401.575), // = ( 800 x 1200 ) mm = ( 31.50 x 47.24 ) in 'FR_DOUBLE_JESUS' => array( 2154.331, 3174.803), // = ( 760 x 1120 ) mm = ( 29.92 x 44.09 ) in 'FR_GRAND_AIGLE' => array( 2125.984, 3004.724), // = ( 750 x 1060 ) mm = ( 29.53 x 41.73 ) in 'FR_PETIT_AIGLE' => array( 1984.252, 2664.567), // = ( 700 x 940 ) mm = ( 27.56 x 37.01 ) in 'FR_DOUBLE_RAISIN' => array( 1842.520, 2834.646), // = ( 650 x 1000 ) mm = ( 25.59 x 39.37 ) in 'FR_JOURNAL' => array( 1842.520, 2664.567), // = ( 650 x 940 ) mm = ( 25.59 x 37.01 ) in 'FR_COLOMBIER_AFFICHE' => array( 1785.827, 2551.181), // = ( 630 x 900 ) mm = ( 24.80 x 35.43 ) in 'FR_DOUBLE_CAVALIER' => array( 1757.480, 2607.874), // = ( 620 x 920 ) mm = ( 24.41 x 36.22 ) in 'FR_CLOCHE' => array( 1700.787, 2267.717), // = ( 600 x 800 ) mm = ( 23.62 x 31.50 ) in 'FR_SOLEIL' => array( 1700.787, 2267.717), // = ( 600 x 800 ) mm = ( 23.62 x 31.50 ) in 'FR_DOUBLE_CARRE' => array( 1587.402, 2551.181), // = ( 560 x 900 ) mm = ( 22.05 x 35.43 ) in 'FR_DOUBLE_COQUILLE' => array( 1587.402, 2494.488), // = ( 560 x 880 ) mm = ( 22.05 x 34.65 ) in 'FR_JESUS' => array( 1587.402, 2154.331), // = ( 560 x 760 ) mm = ( 22.05 x 29.92 ) in 'FR_RAISIN' => array( 1417.323, 1842.520), // = ( 500 x 650 ) mm = ( 19.69 x 25.59 ) in 'FR_CAVALIER' => array( 1303.937, 1757.480), // = ( 460 x 620 ) mm = ( 18.11 x 24.41 ) in 'FR_DOUBLE_COURONNE' => array( 1303.937, 2040.945), // = ( 460 x 720 ) mm = ( 18.11 x 28.35 ) in 'FR_CARRE' => array( 1275.591, 1587.402), // = ( 450 x 560 ) mm = ( 17.72 x 22.05 ) in 'FR_COQUILLE' => array( 1247.244, 1587.402), // = ( 440 x 560 ) mm = ( 17.32 x 22.05 ) in 'FR_DOUBLE_TELLIERE' => array( 1247.244, 1927.559), // = ( 440 x 680 ) mm = ( 17.32 x 26.77 ) in 'FR_DOUBLE_CLOCHE' => array( 1133.858, 1700.787), // = ( 400 x 600 ) mm = ( 15.75 x 23.62 ) in 'FR_DOUBLE_POT' => array( 1133.858, 1757.480), // = ( 400 x 620 ) mm = ( 15.75 x 24.41 ) in 'FR_ECU' => array( 1133.858, 1474.016), // = ( 400 x 520 ) mm = ( 15.75 x 20.47 ) in 'FR_COURONNE' => array( 1020.472, 1303.937), // = ( 360 x 460 ) mm = ( 14.17 x 18.11 ) in 'FR_TELLIERE' => array( 963.780, 1247.244), // = ( 340 x 440 ) mm = ( 13.39 x 17.32 ) in 'FR_POT' => array( 878.740, 1133.858), // = ( 310 x 400 ) mm = ( 12.20 x 15.75 ) in ); /** * Get page dimensions from format name. * @param mixed $format The format name @see self::$page_format