List of usage examples for com.lowagie.text.pdf PdfAnnotation createFileAttachment
public static PdfAnnotation createFileAttachment(PdfWriter writer, Rectangle rect, String contents, byte fileStore[], String file, String fileDisplay) throws IOException
From source file:org.revager.export.PDFCellEventExtRef.java
License:Open Source License
@Override public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) { PdfContentByte cb = canvas[PdfPTable.LINECANVAS]; // cb.reset(); Rectangle attachmentRect = new Rectangle(rect.getLeft() - 25, rect.getTop() - 25, rect.getRight() - rect.getWidth() - 40, rect.getTop() - 10); String fileDesc = file.getName() + " (" + translate("File Attachment") + ")"; try {// ww w .j av a 2 s. co m PdfAnnotation attachment = PdfAnnotation.createFileAttachment(writer, attachmentRect, fileDesc, null, file.getAbsolutePath(), file.getName()); writer.addAnnotation(attachment); } catch (IOException e) { /* * just do not add a reference if the file was not found or another * error occured. */ } // cb.setColorStroke(new GrayColor(0.8f)); // cb.roundRectangle(rect.getLeft() + 4, rect.getBottom(), // rect.getWidth() - 8, rect.getHeight() - 4, 4); cb.stroke(); }
From source file:questions.encryption.HelloWorldFullyEncrypted.java
public static void main(String[] args) { // step 1//w w w. ja v a 2s. c o m Document document = new Document(); try { // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); writer.setEncryption("hello".getBytes(), "world".getBytes(), 0, PdfWriter.ENCRYPTION_AES_128); writer.createXmpMetadata(); // step 3 document.open(); // step 4 document.add(new Paragraph("Hello World")); writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 650f, 150f, 700f), "This is some text", "some text".getBytes(), null, "some.txt")); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5 document.close(); }
From source file:questions.encryption.HelloWorldMetadataNotEncrypted.java
public static void main(String[] args) { // step 1/*from w w w. j a va 2 s . c o m*/ Document document = new Document(); try { // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); writer.setEncryption("hello".getBytes(), "world".getBytes(), 0, PdfWriter.ENCRYPTION_AES_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA); writer.createXmpMetadata(); writer.setPdfVersion(PdfWriter.VERSION_1_5); // step 3 document.open(); // step 4 document.add(new Paragraph("Hello World")); writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 650f, 150f, 700f), "This is some text", "some text".getBytes(), null, "some.txt")); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5 document.close(); }
From source file:questions.stamppages.RemoveAttachmentAnnotations.java
public static void createPdfWithAttachments() throws IOException, DocumentException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESOURCE)); document.open();//from w w w. ja v a 2 s . c o m document.add(new Paragraph("page 1")); writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 780f, 120f, 800f), "This is some text", "some text".getBytes(), null, "some.txt")); writer.addAnnotation(PdfAnnotation.createText(writer, new Rectangle(100f, 750f, 120f, 770f), "Help", "This Help annotation was made with 'createText'", false, "Help")); document.newPage(); document.add(new Paragraph("page 2")); document.newPage(); document.add(new Paragraph("page 3")); PdfFileSpecification fs1 = PdfFileSpecification.fileEmbedded(writer, TXT, "caesar.txt", null); writer.addAnnotation( PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 780f, 120f, 800f), "Caesar", fs1)); PdfFileSpecification fs2 = PdfFileSpecification.fileEmbedded(writer, IMG, "1t3xt.gif", null); writer.addAnnotation( PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 750f, 120f, 770f), "1t3xt", fs2)); document.close(); }