{"id":1622,"library":"pikepdf","title":"pikepdf","description":"pikepdf is a Python library that enables reading, writing, repairing, and transforming PDF files, leveraging the powerful `qpdf` C++ library. It offers comprehensive PDF manipulation capabilities, including merging, splitting, compressing, and extracting data. Currently at version 10.5.1, it follows a regular release cadence with several minor and patch releases per year.","status":"active","version":"10.5.1","language":"en","source_language":"en","source_url":"https://github.com/pikepdf/pikepdf","tags":["pdf","document processing","qpdf","file manipulation","document generation"],"install":[{"cmd":"pip install pikepdf","lang":"bash","label":"Install pikepdf"}],"dependencies":[],"imports":[{"symbol":"Pdf","correct":"from pikepdf import Pdf"},{"symbol":"Page","correct":"from pikepdf import Page"}],"quickstart":{"code":"from pikepdf import Pdf, Page\nimport os\n\n# Create a new PDF and add a blank page\noutput_filename = \"my_first_pikepdf.pdf\"\nwith Pdf.new() as pdf:\n    pdf.add_blank_page()\n    pdf.save(output_filename)\n\nprint(f\"Created {output_filename} with one blank page.\")\n\n# Open an existing PDF, add another page, and save it to a new file\nmodified_filename = \"my_modified_pikepdf.pdf\"\nwith Pdf.open(output_filename) as pdf:\n    pdf.add_blank_page()\n    print(f\"PDF now has {len(pdf.pages)} pages.\")\n    pdf.save(modified_filename)\n\nprint(f\"Modified PDF saved to {modified_filename}.\")\n\n# Clean up generated files (optional)\n# os.remove(output_filename)\n# os.remove(modified_filename)","lang":"python","description":"This quickstart demonstrates how to create a new PDF, add pages to it, and then open and modify an existing PDF file using `pikepdf`. The `Pdf` object should always be used within a `with` statement for proper resource management."},"warnings":[{"fix":"Install `qpdf` via your system's package manager (e.g., `apt install qpdf` on Debian/Ubuntu, `brew install qpdf` on macOS, or download from qpdf.sourceforge.io for Windows).","message":"pikepdf is a Python wrapper around the `qpdf` C++ library. You must have `qpdf` installed on your system for pikepdf to function. It is not installed via pip.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Replace `Pdf.read(filename)` with `with Pdf.open(filename) as pdf:`.","message":"The `Pdf.read()` method was removed in favor of `Pdf.open()`. Always use `Pdf.open()` and it is strongly recommended to use it as a context manager (`with Pdf.open(...) as pdf:`).","severity":"breaking","affected_versions":">= 10.0.0"},{"fix":"When accessing page box coordinates, adapt your code from `box[0]` to `box.as_list()[0]` or use `box.left`, `box.bottom`, etc. directly on the `PageBox` object.","message":"Attributes like `page.trimbox` and `page.cropbox` now return `PageBox` objects instead of simple tuples or lists of numbers. These `PageBox` objects have methods like `pagebox.as_list()` or `pagebox.as_tuple()` to get the raw coordinates.","severity":"breaking","affected_versions":">= 10.0.0"},{"fix":"Ensure `pdf.save(output_filename)` is called after all modifications. When using `with Pdf.open(...) as pdf:`, `pdf.save()` should be called within the `with` block.","message":"Changes made to a `Pdf` object are not saved until `pdf.save()` is explicitly called. If you modify a PDF and forget to call `save()`, your changes will be lost.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}