Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
pip install gotenberg-client
This is a Python client for interfacing with Gotenberg, which in turn is a wrapper around powerful tools for PDF generation and creation in various ways, using a stateless API. It's a very powerful tool to generate and manipulate PDFs.
As far as I can tell, no active Python library exists to interface with the Gotenberg API.
Path
s insteadAll the routes and options from the Gotenberg routes are implemented, with the exception of the Prometheus metrics endpoint. All the routes use the same format and general idea.
For more detailed examples, check the documentation
Converting a single HTML file into a PDF:
from gotenberg_client import GotenbergClient
with GotenbergClient("http://localhost:3000") as client:
with client.chromium.html_to_pdf() as route:
response = route.index("my-index.html").run()
response.to_file(Path("my-index.pdf"))
Converting an HTML file with additional resources into a PDF:
from gotenberg_client import GotenbergClient
with GotenbergClient("http://localhost:3000") as client:
with client.chromium.html_to_pdf() as route:
response = route.index("my-index.html").resource("image.png").resource("style.css").run()
response.to_file(Path("my-index.pdf"))
Converting an HTML file with additional resources into a PDF/A1a format:
from gotenberg_client import GotenbergClient
from gotenberg_client.options import PdfAFormat
with GotenbergClient("http://localhost:3000") as client:
with client.chromium.html_to_pdf() as route:
response = route.index("my-index.html").resources(["image.png", "style.css"]).pdf_format(PdfAFormat.A2b).run()
response.to_file(Path("my-index.pdf"))
Converting a URL into PDF, in landscape format
from gotenberg_client import GotenbergClient
from gotenberg_client.options import PageOrientation
with GotenbergClient("http://localhost:3000") as client:
with client.chromium.url_to_pdf() as route:
response = route.url("https://hello.world").orient(PageOrientation.Landscape).run()
response.to_file(Path("my-world.pdf"))
Adding metadata to a PDF:
This example shows how to add metadata to your generated PDF. All metadata fields are optional and include:
from gotenberg_client import GotenbergClient
from datetime import datetime
with GotenbergClient("http://localhost:3000") as client:
with client.chromium.html_to_pdf() as route:
response = (route
.index("my-index.html")
.metadata(
title="My Document",
author="John Doe",
subject="Example PDF",
keywords=["sample", "document", "test"],
creation_date=datetime.now(),
trapped="Unknown"
)
.run())
response.to_file(Path("my-index.pdf"))
To ensure the proper clean up of all used resources, both the client and the route(s) should be
used as context manager. If for some reason you cannot, you should .close
the client and any
routes:
from gotenberg_client import GotenbergClient
try:
client = GotenbergClient("http://localhost:3000")
try:
route = client.merge(["myfile.pdf", "otherfile.pdf"]).run()
finally:
route.close()
finally:
client.close()
The response from any .run()
or .run_with_retry()
will be either a SingleFileResponse
or ZipFileResponse
.
There provide a slimmed down set of fields from an httpx.Response
, including the headers, the status code and
the response content. They also provide two convenience methods:
to_file
- Accepts a path and writes the content of the response to itextract_to
- Only on a ZipFileResponse
, extracts the zip into the given directory (which must exist)gotenberg-client
is distributed under the terms of the MPL 2.0 license.
FAQs
A Python client for interfacing with the Gotenberg API
We found that gotenberg-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.