This sample extracts every embedded file from a PDF, prints basic metadata (name, description, file type), and writes the attachment bytes to an output folder.
This sample embeds an external file into the PDF as an attachment, assigning a display name and description, and then saves the updated document.
importgroupdocs.watermarkasgwimportgroupdocs.watermark.contents.pdfasgwc_pdfload_options=gw.PdfLoadOptions()withgw.Watermarker("document.pdf",load_options)aswatermarker:pdf_content=watermarker.get_content(gwc_pdf.PdfContent)withopen("sample.docx","rb")asf:pdf_content.attachments.add(f.read(),"sample doc","sample doc as attachment")watermarker.save("document.pdf")
Remove attachment from PDF document
This sample finds and removes attachments that match custom criteria (for example, a name containing “sample” and the DOCX file type), and then saves the PDF.