{ "info": { "author": "Vadim Shmatov", "author_email": "shmatov96@mail.ru", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.5" ], "description": "# PdfBuilder\n\nPdfBuilder is a Python library for low-level PDF crafting. It allows:\n- creating new PDF files from list of COS objects;\n- adding new objects and editing existing ones via incremental saves;\n- working with both old xref tables and new xref stream objects.\n\n## How to install\n\n`$ pip install pdfbuilder`\n\nPdfBuilder is written in a pure Python and doesn't have any external dependencies. It requires Python 3.5 or higher to function properly.\n\n## Example\n\nA minimalistic code sample that creates \"Hello, world\" PDF file is listed below:\n```python\nimport os, zlib\nfrom pdfbuilder import PDF, Object, ObjectReference\n\n# (0) Open new, empty file\nif os.path.isfile('test.pdf'):\n os.remove('test.pdf')\ndoc = PDF('test.pdf')\n\n# (1) Add pages object to PDF\npages_object = Object({\n 'Type': '/Pages',\n 'Kids': [ObjectReference(5)], # We need to know page id beforehand :(\n 'Count': 1,\n 'MediaBox': [0, 0, 595.28, 841.89]\n})\ndoc.add_new_object(pages_object)\n\n# (2) Add font to pdf\nfont_object = Object({\n 'Type': '/Font',\n 'BaseFont': '/Helvetica',\n 'Subtype': '/Type1',\n 'Encoding': '/WinAnsiEncoding'\n})\ndoc.add_new_object(font_object)\n\n# (3) Add info object to PDF\npdf_info_object = Object({\n 'ProcSet': ['/PDF', '/Text', '/ImageB', '/ImageC', '/ImageI'],\n 'Font': [Object({'F1': font_object.ref()})]\n})\ndoc.add_new_object(pdf_info_object)\n\n# (4) Add first page content to PDF\ncontent = b'2 J\\n0.57 w\\nBT /F1 14.00 Tf ET\\nBT 56.69 785.20 Td (Hello, world!) Tj ET\\n'\ncontent_compressed = zlib.compress(content)\ncontent_object = Object({\n 'Filter': '/FlateDecode',\n 'Length': len(content_compressed)\n}, stream_data=content_compressed)\ndoc.add_new_object(content_object)\n\n# (5) Add first page to PDF\npage_object = Object({\n 'Type': '/Page',\n 'Parent': pages_object.ref(),\n 'Resources': pdf_info_object.ref(),\n 'Contents': content_object.ref()\n})\ndoc.add_new_object(page_object)\n\n# (6) Add main catalog to PDF\ncatalog_object = Object({\n 'Type': '/Catalog',\n 'Pages': pages_object.ref(),\n 'OpenAction': [page_object.ref(), '/FitH', 'null'],\n 'PageLayout': '/OneColumn'\n})\ndoc.add_new_object(catalog_object)\n\n# (7) Add xref table object and save PDF\ndoc.save(root_id=6, info_id=2)\n```\nThe following example shows how to add another page to newly created document. Updates in PDF structure will be saved incrementally.\n```python\nfrom pdfbuilder import PDF, Object, ObjectReference\n\n# (0) Open already existing PDF\ndoc = PDF('test.pdf')\n\n# (1) Add new page to PDF\nsecond_page_object = Object({\n 'Type': '/Page',\n 'Parent': ObjectReference(1),\n 'Resources': ObjectReference(3),\n 'Contents': ObjectReference(4)\n})\ndoc.add_new_object(second_page_object)\n\n# (2) Update pages object\nnew_pages_object = Object({\n 'Type': '/Pages',\n 'Kids': [ObjectReference(5), second_page_object.ref()],\n 'Count': 2,\n 'MediaBox': [0, 0, 595.28, 841.89]\n}, id=1)\ndoc.update_object(new_pages_object, 1)\n\n# (3) Add new xref table object and incrementally update PDF\ndoc.save(root_id=6, info_id=2)\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/VadimShmatov/pdfbuilder", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "pdfbuilder", "package_url": "https://pypi.org/project/pdfbuilder/", "platform": "", "project_url": "https://pypi.org/project/pdfbuilder/", "project_urls": { "Homepage": "https://github.com/VadimShmatov/pdfbuilder" }, "release_url": "https://pypi.org/project/pdfbuilder/0.1.0/", "requires_dist": null, "requires_python": ">=3.5", "summary": "A package for low-level PDF crafting", "version": "0.1.0" }, "last_serial": 5197673, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "7fc6e14cdb6516b405297de1f53463a3", "sha256": "41a6f89c150ee6ab53421a54fc4647186cc77f9a757dd5fc4c50a6c0b4573339" }, "downloads": -1, "filename": "pdfbuilder-0.0.1.tar.gz", "has_sig": false, "md5_digest": "7fc6e14cdb6516b405297de1f53463a3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 4648, "upload_time": "2019-04-27T19:46:12", "url": "https://files.pythonhosted.org/packages/fe/53/6072649a977abceb64887957ddddfb5890ca50f8acb3bbc5a9c103eafc0d/pdfbuilder-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "2719d11762c65ca931a1ec5bf913c670", "sha256": "95c44a35fd328754931b9512b4bd68125d0e065bbc3c8d684ac64d3bfe93e9bb" }, "downloads": -1, "filename": "pdfbuilder-0.0.2.tar.gz", "has_sig": false, "md5_digest": "2719d11762c65ca931a1ec5bf913c670", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 4648, "upload_time": "2019-04-27T19:50:57", "url": "https://files.pythonhosted.org/packages/0e/df/c2e5ab8752026fca97198771923a8f2c2ee700ca75c93aac4c2114dcaf2e/pdfbuilder-0.0.2.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "335f6eb7dac6eeff97e39bef78a96d08", "sha256": "e63b86f9413712d7ae7c6b1c5b031bfe3676a43cae689ab99995b22935472128" }, "downloads": -1, "filename": "pdfbuilder-0.1.0.tar.gz", "has_sig": false, "md5_digest": "335f6eb7dac6eeff97e39bef78a96d08", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 4657, "upload_time": "2019-04-27T20:04:10", "url": "https://files.pythonhosted.org/packages/0e/5f/9180f6fcd4a1c20f7de86df5e9d23049606b9d3aeb158dedc1529793e4ac/pdfbuilder-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "335f6eb7dac6eeff97e39bef78a96d08", "sha256": "e63b86f9413712d7ae7c6b1c5b031bfe3676a43cae689ab99995b22935472128" }, "downloads": -1, "filename": "pdfbuilder-0.1.0.tar.gz", "has_sig": false, "md5_digest": "335f6eb7dac6eeff97e39bef78a96d08", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 4657, "upload_time": "2019-04-27T20:04:10", "url": "https://files.pythonhosted.org/packages/0e/5f/9180f6fcd4a1c20f7de86df5e9d23049606b9d3aeb158dedc1529793e4ac/pdfbuilder-0.1.0.tar.gz" } ] }