How to Compress a PDF
Provide the PDF as base64 text, run the compression operation, and inspect the returned processed PDF and size measurements. The result can be larger, unchanged, or smaller, so compare the reported byte counts.
Overview
A PDF compressor attempts to reduce the size of supplied PDF content and returns a processed PDF when the operation succeeds. This is useful when you need a smaller document for sharing or storage, but the result should be checked because compression does not guarantee a smaller file.
The tool expects the file value as base64 text. It decodes that text before parsing it as PDF content, so a local file path, web address, or raw binary value should not be substituted for the encoded PDF. The file input is optional in the interface, but leaving it empty results in no supplied file for processing.
Steps
-
Start with the PDF you want to process and convert its contents to base64 text. Keep the complete encoded value available as a single file value.
-
Provide that base64 text in the PDF file input. Do not enter a filesystem path or a URL. If the input is omitted or left empty, there is no file value to decode and processing fails.
-
Run the compression operation. The tool decodes the value, parses the PDF, and, when processing succeeds, creates a new PDF by copying each input page. It enables content-stream compression and processes page images using quality 60.
-
Read the returned measurements. Save or pass on the processed PDF represented by the returned base64 value, then compare it with the original using the reported byte counts and percentage size ratio. The result also reports the page count, which helps you confirm that the document structure was processed across its pages.
If no processed PDF is returned, check the input first: malformed base64, invalid PDF content, an exception during decoding or parsing, or unavailable PDF-writing capability can prevent completion. A missing file value is another failure condition, even though the input itself is optional.
Result interpretation
A successful result contains four useful pieces of information: a base64-encoded processed PDF, the original byte count, the compressed byte count, and a percentage size ratio rounded to one decimal place. It also includes the number of pages. Use the two byte counts to understand the actual size change rather than relying on the word “compressed.”
The percentage ratio can be non-positive, so the output may not be smaller for every document. Review the processed PDF before using it, especially when page images are important, because the image-processing setting is fixed at quality 60. A failed operation does not establish that the PDF itself is unusable; it may instead reflect malformed encoded input, parsing or output problems, or unavailable PDF-writing capability.
Worked example
A project team wants to send a meeting PDF with several pages and uses the compressor to create a processed version for review.
Convert the meeting PDF to base64 text, provide that text as the file value, run the compression operation, and inspect the returned measurements before sharing the processed document.
A successful response contains a base64-encoded processed PDF, original and compressed byte counts, a percentage size ratio rounded to one decimal place, and a page count.
Limitations
- A smaller output is not guaranteed because the reported size ratio can be non-positive.
- Page images are processed using quality 60, so review image-heavy documents after processing.
Common errors
- Cause: entering a filename, URL, incomplete base64 text, or invalid PDF content instead of complete base64-encoded PDF data. Correction: encode the PDF contents as base64 text and provide that complete value, then run the operation again.
FAQ
What input does the PDF compressor accept?
The tool decodes the supplied file value as base64 text before parsing it as PDF content. A path or URL is not the expected value.
Can the compressed PDF be larger than the original?
Yes. The reported percentage size ratio can be non-positive, so compare the original and compressed byte counts before deciding whether the result is smaller.
When can PDF compression fail?
Processing fails when no file value is provided, the encoded content cannot be decoded or parsed, output production raises an exception, or the required PDF-writing capability is unavailable.