Developer Tools
|
Office Productivity Applications
|
Enterprise Solutions
|
|||||||||||||||||||||||







There are two ways for creating PDF file attachments. One is to create a document-level file attachment. The other is to create a file attachment annotation.
Like all annotations, file attachment annotations are bound to a page. A viewer application, such as Adobe Reader, will use a paperclip, tag, graph or pushpin icon to display a file attachment annotation on a page . When users click these icons, the viewer application will show a prompt and offer to launch or save the embedded file.

Here is the code to create a page-level PDF file attachment.
public static void main(String[] args)
throws IOException, PdfException {
// Create a file attachment annotation and set its properties
PdfFileAttachmentAnnot fa =
new PdfFileAttachmentAnnot(10,10,Color.RED);
fa.setIcon(PdfFileAttachmentAnnot.ICON_PAPERCLIP);
fa.setTitle("PDF File Attachments Demo");
fa.setSubject("Embed file using a file attachment annotation");
fa.setContents("Double-click the icon for the file attachment");
fa.setFilePath("sample_file.txt");
fa.setRect(10,10,20,40);
// Add an optional popup window for the annotation
// Note: A file attachment annotation does not usually
// have a regular popup window.
PdfPopUpAnnot popup = new PdfPopUpAnnot();
popup.setRect(40,80,170,120);
fa.setPopup(popup, flase);
// Open a PDF document for editing
PdfReader reader =
PdfReader.fileReader(
"sample_doc.pdf", // Input file
"sample_doc_with_attachment_annotation.pdf"); // Output file
PdfDocument doc = new PdfDocument(reader);
// Add file attachment to page #1
doc.addAnnotation(fa,1);
doc.setOpenAfterSave(true);
// Make viewer applications show attachments panel
doc.setPageMode(PdfPageMode.USEATTACHMENTS);
// Save file and clean up
doc.write();
reader.dispose();
}
These attachments are not bound to a page. They are document-level resources in a PDF document. A viewer application such as Adobe Reader will show these files in a special attachments panel.*

public static void main(String[] args)
throws IOException, PdfException {
// Open a PDF document for editing
PdfReader reader =
PdfReader.fileReader(
"sample_doc.pdf", // Input file
"sample_doc_with_document_level_attachment.pdf"); // Output file
PdfDocument doc = new PdfDocument(reader);
// Add file attachment
doc.attachDocument("sample_file.txt");
doc.setOpenAfterSave(true);
// Make viewer applications show attachments panel
doc.setPageMode(PdfPageMode.USEATTACHMENTS);
// Save file and clean up
doc.write();
reader.dispose();
}
* - Please note that a file embedded using a file attachment annotation will also be displayed in the attachments panel.
---o0O0o---
| Our Developer Tools | |
|---|---|
eDocEngine VCLA Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools. |
PDFtoolkit VCLA Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents. |
XtremePDFConverter VCLA Delphi/C++Builder component to intelligently convert PDF to user-friendly Word RTF documents. |
|
PDFOne .NETA .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications. |
XtremeDocumentStudio .NETMulti-format document-processing component suite for .NET developers |
PDFOne (for Java™)A Java™ PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java™ applications. |
XtremeFontEngine (for Java)Java font engine to render glyphs from Type 1, Type 2 (CFF), and TrueType fonts |
| Our Office Productivity Applications |
|---|
Free PDF ReaderA free, fast, and portable application for viewing, printing and converting PDF documents. |
| Privacy | Legal | Feedback | Newsletter | Resellers | © 2002-2013 Gnostice Information Technologies Private Limited. All rights reserved. |
This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows XP users are advised to use Microsoft ClearType Tuning for optimal experience. Also, please use the latest version of a standards-compliant browser such as Firefox, Opera, or Dragon (Chromium).