Serialises an in-memory pdfium_doc (typically produced by
pdf_doc_open() with readwrite = TRUE and one or more mutators)
to a file. Wraps FPDF_SaveAsCopy and FPDF_SaveWithVersion.
Usage
pdf_save(
doc,
file,
incremental = FALSE,
remove_security = FALSE,
subset_new_fonts = TRUE,
version = NULL
)Arguments
- doc
A
pdfium_docfrompdf_doc_open()orpdf_doc_new().- file
Destination path. The directory must exist.
- incremental
Logical. If
TRUE, append an incremental update preserving the original byte layout (required for signed-PDF workflows). IfFALSE(default), rewrite the whole file.- remove_security
Logical. If
TRUE, strip the encryption dictionary from the saved copy. DefaultsFALSE. Use with caution.- subset_new_fonts
Logical. If
TRUE(default), subset newly-embedded fonts the same way Acrobat does. SetFALSEto embed full font tables.- version
Integer or
NULL. The PDF version in PDFium's "10 * major + minor" form (e.g.17for PDF 1.7).NULL(default) preserves the input file's declared version.
Details
pdf_save() writes atomically: PDFium's bytes go into a
tempfile in the destination directory, and on success the
tempfile is renamed over file. If the save fails mid-write,
the original file (if any) is preserved untouched.
Works on read-only documents too — opening a PDF, calling
pdf_save(), and re-opening the result is a way to "normalise"
a PDF (rebuild the xref table, etc.) without modifying its
content.
See also
pdf_save_to_raw() for in-memory output;
pdf_doc_open() for the read side; pdf_doc_new() for a fresh
document.