Example #1
0
        internal static bool EmbedPDFAttachment(PDFAttachmentItem attachment, PDDocument doc)
        {
            bool flag;

            try
            {
                PDEmbeddedFilesNameTreeNode pDEmbeddedFilesNameTreeNode = new PDEmbeddedFilesNameTreeNode();
                List arrayList = new ArrayList();
                PDComplexFileSpecification pDComplexFileSpecification = new PDComplexFileSpecification();
                pDComplexFileSpecification.setFile(System.IO.Path.GetFileName(attachment.filePath));
                java.io.File   file           = new java.io.File(attachment.filePath);
                byte[]         numArray       = Files.readAllBytes(file.toPath());
                PDEmbeddedFile pDEmbeddedFile = new PDEmbeddedFile(doc, new ByteArrayInputStream(numArray));
                pDEmbeddedFile.setSize((int)numArray.Length);
                pDEmbeddedFile.setCreationDate(new GregorianCalendar());
                pDComplexFileSpecification.setEmbeddedFile(pDEmbeddedFile);
                PDEmbeddedFilesNameTreeNode pDEmbeddedFilesNameTreeNode1 = new PDEmbeddedFilesNameTreeNode();
                pDEmbeddedFilesNameTreeNode1.setNames(Collections.singletonMap("My first attachment", pDComplexFileSpecification));
                arrayList.@add(pDEmbeddedFilesNameTreeNode1);
                pDEmbeddedFilesNameTreeNode.setKids(arrayList);
                PDDocumentNameDictionary pDDocumentNameDictionary = new PDDocumentNameDictionary(doc.getDocumentCatalog());
                pDDocumentNameDictionary.setEmbeddedFiles(pDEmbeddedFilesNameTreeNode);
                doc.getDocumentCatalog().setNames(pDDocumentNameDictionary);
                flag = true;
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                throw new PDFToolkitException(exception.Message, exception);
            }
            return(flag);
        }
Example #2
0
 public bool EmbedPDFAttachments(List <PDFAttachmentItem> attachments)
 {
     return(PDFAttachmentItem.EmbedPDFAttachment(attachments, this.PDFBoxDocument));
 }
Example #3
0
 public bool EmbedPDFAttachment(PDFAttachmentItem attachment)
 {
     return(PDFAttachmentItem.EmbedPDFAttachment(attachment, this.PDFBoxDocument));
 }