Chapter 12
File Attachments

PDF supports adding attachments (files of any kind, including other PDFs) to an existing file. The cpdf tool supports adding and removing document-level attachments — that is, ones which are associated with the document as a whole rather than with an individual page, and also page-level attachments, associated with a particular page.

12.1 Adding Attachments

To add an attachment, use the -attach-file option. For instance,

attaches the Excel spreadsheet sheet.xls to the input file. If the file already has attachments, the new file is added to their number. You can specify multiple files to be attached by using -attach-file multiple times. They will be attached in the given order.

The -to-page option can be used to specify that the files will be attached to the given page, rather than at the document level. The -to-page option may be specified at most once.

12.2 Listing Attachments

To list all document- and page-level attachments, use the -list-attached-files operation. The page number and filename of each attachment is given, page 0 representing a document-level attachment.

12.3 Removing Attachments

To remove all document-level and page-level attachments from a file, use the -remove-files operation: