MCPcopy
hub / github.com/PDFMathTranslate/PDFMathTranslate / convert_to_pdfa

Function convert_to_pdfa

pdf2zh/high_level.py:253–299  ·  view source on GitHub ↗

Convert PDF to PDF/A format Args: input_path: Path to source PDF file output_path: Path to save PDF/A file

(input_path, output_path)

Source from the content-addressed store, hash-verified

251
252
253def convert_to_pdfa(input_path, output_path):
254 """
255 Convert PDF to PDF/A format
256
257 Args:
258 input_path: Path to source PDF file
259 output_path: Path to save PDF/A file
260 """
261 from pikepdf import Dictionary, Name, Pdf
262
263 # Open the PDF file
264 pdf = Pdf.open(input_path)
265
266 # Add PDF/A conformance metadata
267 metadata = {
268 "pdfa_part": "2",
269 "pdfa_conformance": "B",
270 "title": pdf.docinfo.get("/Title", ""),
271 "author": pdf.docinfo.get("/Author", ""),
272 "creator": "PDF Math Translate",
273 }
274
275 with pdf.open_metadata() as meta:
276 meta.load_from_docinfo(pdf.docinfo)
277 meta["pdfaid:part"] = metadata["pdfa_part"]
278 meta["pdfaid:conformance"] = metadata["pdfa_conformance"]
279
280 # Create OutputIntent dictionary
281 output_intent = Dictionary(
282 {
283 "/Type": Name("/OutputIntent"),
284 "/S": Name("/GTS_PDFA1"),
285 "/OutputConditionIdentifier": "sRGB IEC61966-2.1",
286 "/RegistryName": "http://www.color.org",
287 "/Info": "sRGB IEC61966-2.1",
288 }
289 )
290
291 # Add output intent to PDF root
292 if "/OutputIntents" not in pdf.Root:
293 pdf.Root.OutputIntents = [output_intent]
294 else:
295 pdf.Root.OutputIntents.append(output_intent)
296
297 # Save as PDF/A
298 pdf.save(output_path, linearize=True)
299 pdf.close()
300
301
302def translate(

Callers 1

translateFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected