Hi everyone,
I’m looking for a way to generate PDFs in the PDF/A format for long-term archiving. From what I’ve seen, it seems that anvil.pdf
doesn’t support this feature, as I couldn’t find any relevant attributes or options for it.
Did I perhaps overlook something? Or does anyone know of a good alternative solution?
Thanks in advance!
This is entirely based on a quick chat with chatgpt, but you should just be able to convert a regular pdf to pdf/a om the server:
import pikepdf
def convert_to_pdfa(input_pdf, output_pdf):
try:
# Open the original PDF
with pikepdf.Pdf.open(input_pdf) as pdf:
# Convert to PDF/A-2B (commonly used standard)
pdf.save(output_pdf, pdfa_version='2B')
print(f"Successfully converted {input_pdf} to PDF/A format as {output_pdf}")
except Exception as e:
print(f"Error during conversion: {e}")
# Example usage
input_pdf = "example.pdf"
output_pdf = "example_pdfa.pdf"
convert_to_pdfa(input_pdf, output_pdf)
- make the pdf with anvil as normal
- convert that to pdf/a on the server side
This leads to an error:
Pdf.save() got an unexpected keyword argument ‘pdfa_version’
Does it work if you omit that argument from the code above?
yes, but it is an identical copy. pdf/a requires e.g. embedded fonts, metadata, etc.