Quarto Post-Render: Enrich PDF Files with DOCX Titles
Source:R/quarto_post_render.R
quarto_pdf_post_render.RdA post-render function for Quarto projects that processes rendered PDF
output files. For each PDF, it checks if a corresponding DOCX file with
the same base name exists, extracts the title from the DOCX document
properties, sets it as the PDF metadata title, and updates the link text
in the accompanying index.html.
Usage
quarto_pdf_post_render(
output_files = strsplit(Sys.getenv("QUARTO_PROJECT_OUTPUT_FILES"), "\n")[[1L]]
)Details
To use as a Quarto post-render script, add to _quarto.yml:
Processing steps for each .pdf file:
Checks if a
.docxwith the same base name exists in the same directoryExtracts the title from the DOCX document properties (via
officer)Sets the extracted title as the PDF file's metadata title (requires Ghostscript)
Locates
index.htmlin the same directory as the PDFReplaces the
<a>link text for that PDF with the extracted title
System Requirements
Setting PDF metadata title requires Ghostscript to be installed and available on the system PATH:
Linux/macOS:
gsWindows:
gswin64corgswin32c
If Ghostscript is not found, a warning is issued and only the HTML link text update is performed.
See also
extract_docx_title() for the DOCX title extraction logic.
Examples
if (FALSE) { # \dontrun{
# Called automatically by Quarto post-render, or manually:
quarto_pdf_post_render(c("_site/report/report.pdf"))
} # }