Ejemplo n.º 1
0
        public virtual void CopyFieldsTest03()
        {
            String      srcFilename = sourceFolder + "hello2_with_comments.pdf";
            String      filename    = destinationFolder + "copyFields03.pdf";
            PdfDocument doc1        = new PdfDocument(new PdfReader(new FileStream(srcFilename, FileMode.Open, FileAccess.Read
                                                                                   )));
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new FileStream(filename, FileMode.Create)));

            pdfDoc.InitializeOutlines();
            doc1.CopyPagesTo(1, doc1.GetNumberOfPages(), pdfDoc, new PdfPageFormCopier());
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, sourceFolder + "cmp_copyFields03.pdf"
                                                                             , destinationFolder, "diff_"));
        }
Ejemplo n.º 2
0
        public virtual void StructTreeCopyingTest01()
        {
            FileStream  fis    = new FileStream(sourceFolder + "iphone_user_guide.pdf", FileMode.Open, FileAccess.Read);
            PdfReader   reader = new PdfReader(fis);
            PdfDocument source = new PdfDocument(reader);
            PdfWriter   writer = new PdfWriter(new FileStream(destinationFolder + "structTreeCopyingTest01.pdf", FileMode.Create
                                                              ));
            PdfDocument destination = new PdfDocument(writer);

            destination.SetTagged();
            destination.InitializeOutlines();
            List <int> pagesToCopy = new List <int>();

            pagesToCopy.Add(3);
            pagesToCopy.Add(4);
            pagesToCopy.Add(10);
            pagesToCopy.Add(11);
            source.CopyPagesTo(pagesToCopy, destination);
            source.CopyPagesTo(50, 52, destination);
            destination.Close();
            source.Close();
            CompareResult("structTreeCopyingTest01.pdf", "cmp_structTreeCopyingTest01.pdf", "diff_copying_01_");
        }
Ejemplo n.º 3
0
        public virtual void DestCopyingTest01()
        {
            String      srcFile = sourceFolder + "simpleWithLinks.pdf";
            String      outFile = destinationFolder + "destCopyingTest01.pdf";
            String      cmpFile = sourceFolder + "cmp_destCopyingTest01.pdf";
            PdfDocument srcDoc  = new PdfDocument(new PdfReader(srcFile));
            PdfDocument destDoc = new PdfDocument(new PdfWriter(outFile));

            srcDoc.CopyPagesTo(JavaUtil.ArraysAsList(1, 2, 3), destDoc);
            destDoc.Close();
            srcDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFile, destinationFolder, "diff_"
                                                                             ));
        }
Ejemplo n.º 4
0
        public virtual void CopyPageWithRotationInPageToDocWithRotationInPagesDictTest()
        {
            String      src       = sourceFolder + "indirectPageProps.pdf";
            String      dest      = destinationFolder + "copyPageWithRotationInPageToDocWithRotationInPagesDict.pdf";
            String      cmp       = sourceFolder + "cmp_copyPageWithRotationInPageToDocWithRotationInPagesDict.pdf";
            PdfDocument pdfDoc    = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
            PdfDocument sourceDoc = new PdfDocument(new PdfReader(sourceFolder + "srcFileCopyPageWithSetRotationValueInKids.pdf"
                                                                  ));

            sourceDoc.CopyPagesTo(1, sourceDoc.GetNumberOfPages(), pdfDoc);
            sourceDoc.Close();
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(dest, cmp, destinationFolder));
        }
Ejemplo n.º 5
0
        public virtual void CopyDifferentRangesOfPagesWithBookmarksTest()
        {
            String      outFileName = destinationFolder + "copyDifferentRangesOfPagesWithBookmarksTest.pdf";
            String      cmpFileName = sourceFolder + "cmp_copyDifferentRangesOfPagesWithBookmarksTest.pdf";
            PdfDocument targetPdf   = new PdfDocument(new PdfWriter(outFileName));

            targetPdf.InitializeOutlines();
            PdfDocument sourcePdf = new PdfDocument(new PdfReader(sourceFolder + "sameDocWithBookmarksPdf.pdf"));

            sourcePdf.InitializeOutlines();
            int sourcePdfLength   = sourcePdf.GetNumberOfPages();
            int sourcePdfOutlines = sourcePdf.GetOutlines(false).GetAllChildren().Count;

            sourcePdf.CopyPagesTo(3, sourcePdfLength, targetPdf);
            sourcePdf.CopyPagesTo(1, 2, targetPdf);
            int targetOutlines = targetPdf.GetOutlines(false).GetAllChildren().Count;

            NUnit.Framework.Assert.AreEqual(sourcePdfOutlines, targetOutlines);
            sourcePdf.Close();
            targetPdf.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             ));
        }
Ejemplo n.º 6
0
        public virtual void CopyPageNoRotationToDocWithRotationInPagesDictTest()
        {
            //TODO: update cmp-files when DEVSIX-3635 will be fixed
            String      src       = sourceFolder + "indirectPageProps.pdf";
            String      dest      = destinationFolder + "copyPageNoRotationToDocWithRotationInPagesDict.pdf";
            String      cmp       = sourceFolder + "cmp_copyPageNoRotationToDocWithRotationInPagesDict.pdf";
            PdfDocument pdfDoc    = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
            PdfDocument sourceDoc = new PdfDocument(new PdfReader(sourceFolder + "noRotationProp.pdf"));

            sourceDoc.CopyPagesTo(1, sourceDoc.GetNumberOfPages(), pdfDoc);
            sourceDoc.Close();
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(dest, cmp, destinationFolder));
        }
Ejemplo n.º 7
0
        public virtual void CopyReorderTaggedHasCommonStructElem()
        {
            String      inPath    = sourceFolder + "taggedHasCommonStructElem.pdf";
            String      outPath   = destinationFolder + "copyReorderTaggedHasCommonStructElem.pdf";
            String      cmpPath   = sourceFolder + "cmp_copyReorderTaggedHasCommonStructElem.pdf";
            PdfDocument sourceDoc = new PdfDocument(new PdfReader(inPath));
            PdfDocument pdfDoc    = new PdfDocument(new PdfWriter(outPath));

            pdfDoc.SetTagged();
            sourceDoc.CopyPagesTo(JavaUtil.ArraysAsList(2, 1, 3), pdfDoc);
            sourceDoc.Close();
            pdfDoc.Close();
            Compare(outPath, cmpPath, destinationFolder, "diff_04");
        }
Ejemplo n.º 8
0
        public virtual void CopySamePageWithAnnotationsSeveralTimes()
        {
            String      filename  = sourceFolder + "rotated_annotation.pdf";
            PdfDocument sourceDoc = new PdfDocument(new PdfReader(filename));
            PdfDocument pdfDoc    = new PdfDocument(new PdfWriter(destinationFolder + "copySamePageWithAnnotationsSeveralTimes.pdf"
                                                                  ));

            sourceDoc.InitializeOutlines();
            sourceDoc.CopyPagesTo(JavaUtil.ArraysAsList(1, 1, 1), pdfDoc);
            sourceDoc.Close();
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "copySamePageWithAnnotationsSeveralTimes.pdf"
                                                                             , sourceFolder + "cmp_copySamePageWithAnnotationsSeveralTimes.pdf", destinationFolder, "diff_"));
        }
Ejemplo n.º 9
0
        public virtual void CopyPageWithFormXObjectTaggedTest()
        {
            String      cmpPdf = sourceFolder + "cmp_copyPageWithFormXobjectTaggedTest.pdf";
            String      outDoc = destinationFolder + "copyPageWithFormXobjectTaggedTest.pdf";
            PdfDocument srcPdf = new PdfDocument(new PdfReader(sourceFolder + "copyFromFile.pdf"));
            PdfDocument outPdf = new PdfDocument(new PdfReader(sourceFolder + "copyToFile.pdf"), new PdfWriter(outDoc)
                                                 );

            outPdf.SetTagged();
            srcPdf.CopyPagesTo(1, 1, outPdf);
            srcPdf.Close();
            outPdf.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outDoc, cmpPdf, destinationFolder));
        }
Ejemplo n.º 10
0
        public virtual void CopyIndirectInheritablePageEntriesTest01()
        {
            String      src       = sourceFolder + "indirectPageProps.pdf";
            String      filename  = "copyIndirectInheritablePageEntriesTest01.pdf";
            String      dest      = destinationFolder + filename;
            String      cmp       = sourceFolder + "cmp_" + filename;
            PdfDocument outputDoc = new PdfDocument(new PdfWriter(dest));
            PdfDocument sourceDoc = new PdfDocument(new PdfReader(src));

            sourceDoc.CopyPagesTo(1, 1, outputDoc);
            sourceDoc.Close();
            outputDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(dest, cmp, destinationFolder, "diff_"));
        }
Ejemplo n.º 11
0
        public virtual void CopyPagesWithInheritedResources()
        {
            String      sourceFile = sourceFolder + "AnnotationSampleStandard.pdf";
            String      destFile   = destinationFolder + "AnnotationSampleStandard_copy.pdf";
            PdfReader   reader     = new PdfReader(new FileStream(sourceFile, FileMode.Open, FileAccess.Read));
            PdfWriter   writer     = new PdfWriter(destFile);
            PdfDocument source     = new PdfDocument(reader);
            PdfDocument target     = new PdfDocument(writer);

            target.InitializeOutlines();
            source.CopyPagesTo(1, source.GetNumberOfPages(), target, new PdfPageFormCopier());
            target.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFile, sourceFolder + "cmp_AnnotationSampleStandard_copy.pdf"
                                                                             , destinationFolder, "diff_"));
        }
Ejemplo n.º 12
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(RESOURCE), new PdfWriter(dest));
            PdfDocument cover  = new PdfDocument(new PdfReader(COVER));

            // Copier contains the additional logic to copy acroform fields to a new page.
            // PdfPageFormCopier uses some caching logic which can potentially improve performance
            // in case of the reusing of the same instance.
            PdfPageFormCopier formCopier = new PdfPageFormCopier();

            cover.CopyPagesTo(1, 1, pdfDoc, 1, formCopier);

            cover.Close();
            pdfDoc.Close();
        }
Ejemplo n.º 13
0
        public virtual void CopySignedDocuments()
        {
            PdfDocument pdfDoc1 = new PdfDocument(new PdfReader(sourceFolder + "hello_signed.pdf"));
            PdfDocument pdfDoc2 = new PdfDocument(new PdfWriter(destinationFolder + "copySignedDocuments.pdf"));

            pdfDoc1.CopyPagesTo(1, 1, pdfDoc2);
            pdfDoc2.Close();
            pdfDoc1.Close();
            PdfDocument   pdfDocument = new PdfDocument(new PdfReader(destinationFolder + "copySignedDocuments.pdf"));
            PdfDictionary sig         = (PdfDictionary)pdfDocument.GetPdfObject(13);
            PdfDictionary sigRef      = sig.GetAsArray(PdfName.Reference).GetAsDictionary(0);

            NUnit.Framework.Assert.IsTrue(PdfName.SigRef.Equals(sigRef.GetAsName(PdfName.Type)));
            NUnit.Framework.Assert.IsTrue(sigRef.Get(PdfName.Data).IsNull());
        }
Ejemplo n.º 14
0
        public virtual void StructTreeCopyingTest05()
        {
            PdfDocument document = new PdfDocument(new PdfReader(sourceFolder + "iphone_user_guide.pdf"), new PdfWriter
                                                       (destinationFolder + "structTreeCopyingTest05.pdf"));
            PdfDocument document1 = new PdfDocument(new PdfReader(sourceFolder + "quick-brown-fox.pdf"));

            document1.CopyPagesTo(1, 1, document, 2);
            PdfDocument document2 = new PdfDocument(new PdfReader(sourceFolder + "quick-brown-fox-table.pdf"));

            document2.CopyPagesTo(1, 3, document, 4);
            document.Close();
            document1.Close();
            document2.Close();
            CompareResult("structTreeCopyingTest05.pdf", "cmp_structTreeCopyingTest05.pdf", "diff_copying_05_");
        }
Ejemplo n.º 15
0
        public virtual void CopyDocumentsWithFormFieldsTest()
        {
            String      filename  = sourceFolder + "fieldsOn2-sPage.pdf";
            PdfReader   reader    = new PdfReader(new FileStream(filename, FileMode.Open, FileAccess.Read));
            FileStream  fos       = new FileStream(destinationFolder + "copyDocumentsWithFormFields.pdf", FileMode.Create);
            PdfWriter   writer    = new PdfWriter(fos);
            PdfDocument sourceDoc = new PdfDocument(reader);
            PdfDocument pdfDoc    = new PdfDocument(writer);

            sourceDoc.InitializeOutlines();
            sourceDoc.CopyPagesTo(1, sourceDoc.GetNumberOfPages(), pdfDoc);
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "copyDocumentsWithFormFields.pdf"
                                                                             , sourceFolder + "cmp_copyDocumentsWithFormFields.pdf", destinationFolder, "diff_"));
        }
        public virtual void CopySeveralPagesToDocumentWithInheritedPageRotationTest()
        {
            //TODO: update cmp-files when DEVSIX-3635 will be fixed
            String      outputFileName = destinationFolder + "copySeveralPagesToDocumentWithInheritedPageRotation.pdf";
            String      cmpFileName    = sourceFolder + "cmp_copySeveralPagesToDocumentWithInheritedPageRotation.pdf";
            PdfDocument pdfDoc1        = new PdfDocument(new PdfReader(sourceFolder + "noPagesRotation.pdf"));
            PdfDocument pdfDoc2        = new PdfDocument(new PdfReader(sourceFolder + "addSeveralPagesToDocumentWithInheritedPageRotation.pdf"
                                                                       ), new PdfWriter(outputFileName));

            pdfDoc1.CopyPagesTo(1, 2, pdfDoc2);
            pdfDoc1.Close();
            pdfDoc2.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outputFileName, cmpFileName, destinationFolder
                                                                             ));
        }
Ejemplo n.º 17
0
        public virtual void CorruptedTagStructureTest04()
        {
            PdfDocument document = new PdfDocument(new PdfReader(sourceFolder + "directStructElem03.pdf"));

            NUnit.Framework.Assert.IsTrue(document.IsTagged());
            MemoryStream baos        = new MemoryStream();
            PdfDocument  docToCopyTo = new PdfDocument(new PdfWriter(baos));

            docToCopyTo.SetTagged();
            document.CopyPagesTo(1, 1, docToCopyTo);
            document.Close();
            docToCopyTo.Close();
            document = new PdfDocument(new PdfReader(new MemoryStream(baos.ToArray())));
            NUnit.Framework.Assert.IsTrue(document.IsTagged());
            document.Close();
        }
Ejemplo n.º 18
0
        public virtual void StructTreeCopyingTest04()
        {
            PdfDocument source      = new PdfDocument(new PdfReader(sourceFolder + "iphone_user_guide.pdf"));
            PdfDocument destination = new PdfDocument(new PdfWriter(destinationFolder + "structTreeCopyingTest04.pdf")
                                                      );

            destination.SetTagged();
            destination.InitializeOutlines();
            for (int i = 1; i <= source.GetNumberOfPages(); i++)
            {
                source.CopyPagesTo(i, i, destination);
            }
            destination.Close();
            source.Close();
            CompareResult("structTreeCopyingTest04.pdf", "cmp_structTreeCopyingTest04.pdf", "diff_copying_04_");
        }
Ejemplo n.º 19
0
        public void MergePDF()
        {
            var pdfWriter        = new PdfWriter(OutFile);
            var finalPdfDocument = new PdfDocument(pdfWriter);

            finalPdfDocument.InitializeOutlines();

            foreach (string fileName in PdfFileNames)
            {
                var pdfDocument = new PdfDocument(new PdfReader(fileName));
                pdfDocument.CopyPagesTo(1, pdfDocument.GetNumberOfPages(), finalPdfDocument);
                pdfDocument.Close();
            }

            finalPdfDocument.Close();
        }
Ejemplo n.º 20
0
        public virtual void StructTreeCopyingTest06()
        {
            FileStream  fis    = new FileStream(sourceFolder + "iphone_user_guide.pdf", FileMode.Open, FileAccess.Read);
            PdfReader   reader = new PdfReader(fis);
            PdfDocument source = new PdfDocument(reader);
            PdfWriter   writer = new PdfWriter(new FileStream(destinationFolder + "structTreeCopyingTest06.pdf", FileMode.Create
                                                              ));
            PdfDocument destination = new PdfDocument(writer);

            destination.SetTagged();
            destination.InitializeOutlines();
            source.CopyPagesTo(1, source.GetNumberOfPages(), destination);
            destination.Close();
            source.Close();
            CompareResult("structTreeCopyingTest06.pdf", "cmp_structTreeCopyingTest06.pdf", "diff_copying_06_");
        }
Ejemplo n.º 21
0
        public int createPdfFromPages(List <int> pages, string outputFile)
        {
            try
            {
                PdfWriter   writer = new PdfWriter(outputFile);
                PdfDocument newDoc = new PdfDocument(writer);

                doc.CopyPagesTo(pages, newDoc);
                newDoc.Close();
                return(0);
            }
            catch
            {
                return(-1);
            }
        }
Ejemplo n.º 22
0
        public static bool WriteToFile(IEnumerable <Sticker> source, int[] pattern, string file)
        {
            // check collection
            if (source == null)
            {
                Log.Fatal("Collection for writing to file can not be Null: PARAM_NAME[ {@name} ]", nameof(source));
                throw new ArgumentNullException(nameof(source));
            }

            Log.Debug("Convert collection to List");

            var stickers = source.ToList();

            if (stickers.Count == 0)
            {
                Log.Fatal("Collection is empty! PARAM_NAME[ {@name} ]", nameof(source));
                throw new ArgumentException(nameof(source));
            }

            // check path
            if (string.IsNullOrEmpty(file) || string.IsNullOrWhiteSpace(file))
            {
                Log.Fatal("File for saving can not be empty or nullable! \nPARAM_NAME[ {@name} ]\nPATH_TO_FILE[ {@file} ]", nameof(file), file);
                throw new ArgumentNullException(nameof(file));
            }

            var info = new FileInfo(file);

            // check directory
            CreateDirectoryIfNotExist(info.Directory);

            // check file for on exist
            CheckedFileToExist(ref info);

            // write to document
            int index = 0;

            using (var document = new PdfDocument(new PdfWriter(info)))
                foreach (int i in pattern)
                {
                    using (var ms = new MemoryStream(stickers[i].File))
                        using (var sticker = new PdfDocument(new PdfReader(ms)))
                            sticker.CopyPagesTo(1, ++index, document);
                }

            return(true);
        }
Ejemplo n.º 23
0
        public virtual void StructTreeCopyingTest11()
        {
            PdfDocument document = new PdfDocument(new PdfReader(sourceFolder + "88th_Academy_Awards.pdf"), new PdfWriter
                                                       (destinationFolder + "structTreeCopyingTest11.pdf"));
            PdfDocument document1 = new PdfDocument(new PdfReader(sourceFolder + "quick-brown-fox_mapping_mod.pdf"));

            document1.InitializeOutlines();
            document1.CopyPagesTo(1, 1, document, 2);
            PdfDocument document2 = new PdfDocument(new PdfReader(sourceFolder + "quick-brown-fox.pdf"));

            document2.InitializeOutlines();
            document2.CopyPagesTo(1, 1, document, 4);
            document.Close();
            document1.Close();
            document2.Close();
            CompareResult("structTreeCopyingTest11.pdf", "cmp_structTreeCopyingTest11.pdf", "diff_copying_11_");
        }
Ejemplo n.º 24
0
        public virtual void FormFieldTaggingTest02()
        {
            String      outFileName = destinationFolder + "taggedPdfWithForms02.pdf";
            String      cmpFileName = sourceFolder + "cmp_taggedPdfWithForms02.pdf";
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(outFileName));

            pdfDoc.SetTagged();
            pdfDoc.InitializeOutlines();
            PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(pdfDoc, true);

            acroForm.AddField(PdfFormField.CreateCheckBox(pdfDoc, new Rectangle(36, 560, 20, 20), "TestCheck", "1"));
            PdfDocument docToCopyFrom = new PdfDocument(new PdfReader(sourceFolder + "cmp_taggedPdfWithForms07.pdf"));

            docToCopyFrom.CopyPagesTo(1, docToCopyFrom.GetNumberOfPages(), pdfDoc, new PdfPageFormCopier());
            pdfDoc.Close();
            CompareOutput(outFileName, cmpFileName);
        }
Ejemplo n.º 25
0
 /// <summary>This method merges pages from the source document to the current one.</summary>
 /// <remarks>
 /// This method merges pages from the source document to the current one.
 /// <br/><br/>
 /// If <i>closeSourceDocuments</i> flag is set to <i>true</i> (see
 /// <see cref="SetCloseSourceDocuments(bool)"/>
 /// ),
 /// passed
 /// <c>PdfDocument</c>
 /// will be closed after pages are merged.
 /// </remarks>
 /// <param name="from">- document, from which pages will be copied.</param>
 /// <param name="pages">- List of numbers of pages which will be copied.</param>
 /// <returns>
 /// this
 /// <c>PdfMerger</c>
 /// instance.
 /// </returns>
 public virtual iText.Kernel.Utils.PdfMerger Merge(PdfDocument from, IList <int> pages)
 {
     if (mergeTags && from.IsTagged())
     {
         pdfDocument.SetTagged();
     }
     if (mergeOutlines && from.HasOutlines())
     {
         pdfDocument.InitializeOutlines();
     }
     from.CopyPagesTo(pages, pdfDocument);
     if (closeSrcDocuments)
     {
         from.Close();
     }
     return(this);
 }
Ejemplo n.º 26
0
        public virtual void StructTreeCopyingTest08()
        {
            PdfReader reader = new PdfReader(new FileStream(sourceFolder + "quick-brown-fox-table.pdf", FileMode.Open,
                                                            FileAccess.Read));
            PdfWriter writer = new PdfWriter(new FileStream(destinationFolder + "structTreeCopyingTest08.pdf", FileMode.Create
                                                            ));
            PdfDocument document = new PdfDocument(reader, writer);
            PdfReader   reader1  = new PdfReader(new FileStream(sourceFolder + "quick-brown-fox.pdf", FileMode.Open, FileAccess.Read
                                                                ));
            PdfDocument document1 = new PdfDocument(reader1);

            document1.InitializeOutlines();
            document1.CopyPagesTo(1, 1, document, 2);
            document.Close();
            document1.Close();
            CompareResult("structTreeCopyingTest08.pdf", "cmp_structTreeCopyingTest08.pdf", "diff_copying_08_");
        }
Ejemplo n.º 27
0
        public virtual void SmartModeCopyingInTaggedPdfTest()
        {
            String srcFile = sourceFolder + "simpleTaggedDocument.pdf";
            String dstFile = destinationFolder + "smartModeCopyingInTaggedPdf.pdf";
            String cmpFile = sourceFolder + "cmp_smartModeCopyingInTaggedPdf.pdf";

            using (PdfDocument pdfDest = new PdfDocument(new PdfWriter(dstFile, new WriterProperties().UseSmartMode())
                                                         )) {
                pdfDest.SetTagged();
                using (PdfDocument pdfSrc = new PdfDocument(new PdfReader(srcFile))) {
                    pdfSrc.CopyPagesTo(1, pdfSrc.GetNumberOfPages(), pdfDest);
                }
                NUnit.Framework.Assert.IsNotNull(pdfDest.GetStructTreeRoot().GetKidsObject().GetAsDictionary(0).GetAsArray
                                                     (PdfName.K).GetAsDictionary(0).Get(PdfName.K));
            }
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(dstFile, cmpFile, destinationFolder));
        }
Ejemplo n.º 28
0
 public virtual void CopyEncryptedDocument()
 {
     PdfDocument srcDoc = new PdfDocument(new PdfReader(sourceFolder + "encryptedWithCertificateAes128.pdf", new
         ReaderProperties().SetPublicKeySecurityParams(GetPublicCertificate(CERT), GetPrivateKey())));
     String fileName = "copiedEncryptedDoc.pdf";
     PdfDocument destDoc = new PdfDocument(new PdfWriter(destinationFolder + fileName));
     srcDoc.CopyPagesTo(1, 1, destDoc);
     PdfDictionary srcInfo = srcDoc.GetTrailer().GetAsDictionary(PdfName.Info);
     PdfDictionary destInfo = destDoc.GetTrailer().GetAsDictionary(PdfName.Info);
     foreach (PdfName srcInfoKey in srcInfo.KeySet()) {
         destInfo.Put((PdfName)srcInfoKey.CopyTo(destDoc), srcInfo.Get(srcInfoKey).CopyTo(destDoc));
     }
     srcDoc.Close();
     destDoc.Close();
     NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + fileName, sourceFolder
          + "cmp_" + fileName, destinationFolder, "diff_"));
 }
Ejemplo n.º 29
0
        private void MergeAsyncInternal(IEnumerable <InputFile> inputFiles, string outputFile, CancellationToken cancellationToken, IProgress <int> progress)
        {
            int processed = 0;
            int total     = 0;

            using (PdfWriter writer = new PdfWriter(outputFile))
                using (PdfDocument outputDoc = new PdfDocument(writer))
                {
                    outputDoc.InitializeOutlines();

                    foreach (InputFile input in inputFiles)
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        try
                        {
                            using (PdfReader reader = new PdfReader(input.Path))
                                using (PdfDocument inputDoc = new PdfDocument(reader))
                                {
                                    int numPages = inputDoc.GetNumberOfPages();
                                    input.PageCount = numPages;

                                    inputDoc.CopyPagesTo(1, numPages, outputDoc);
                                }

                            input.Status = InputFileStatus.OK;
                            ++processed;
                        }
                        catch (Exception ex)
                        {
                            input.Exception = ex;
                            input.Status    = InputFileStatus.Error;
                        }
                        finally
                        {
                            ++total;

                            if (progress != null)
                            {
                                progress.Report(total);
                            }
                        }
                    }
                }
        }
Ejemplo n.º 30
0
        public virtual void StreamAppendDataOnJustCopiedWithCompression()
        {
            String      srcFile     = sourceFolder + "pageWithContent.pdf";
            String      cmpFile     = sourceFolder + "cmp_streamAppendDataOnJustCopiedWithCompression.pdf";
            String      destFile    = destinationFolder + "streamAppendDataOnJustCopiedWithCompression.pdf";
            PdfDocument srcDocument = new PdfDocument(new PdfReader(srcFile));
            PdfDocument document    = new PdfDocument(new PdfWriter(destFile));

            srcDocument.CopyPagesTo(1, 1, document);
            srcDocument.Close();
            String newContentString = "BT\n" + "/F1 36 Tf\n" + "50 700 Td\n" + "(new content here!) Tj\n" + "ET";

            byte[] newContent = newContentString.GetBytes(Encoding.UTF8);
            document.GetPage(1).GetLastContentStream().SetData(newContent, true);
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFile, cmpFile, destinationFolder, "diff_"
                                                                             ));
        }