public virtual void PdfA1bButtonAppearanceRegenerateTest()
        {
            String          name         = "pdfA1b_ButtonAppearanceRegenerateTest";
            String          outPath      = destinationFolder + name + ".pdf";
            String          cmpPath      = cmpFolder + "cmp_" + name + ".pdf";
            String          diff         = "diff_" + name + "_";
            PdfWriter       writer       = new PdfWriter(outPath);
            Stream          @is          = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
            PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
                                                               , @is);
            PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);

            doc.SetTagged();
            doc.GetCatalog().SetLang(new PdfString("en-US"));
            doc.AddNewPage();
            PdfAcroForm  form   = PdfAcroForm.GetAcroForm(doc, true);
            Rectangle    rect   = new Rectangle(36, 626, 100, 40);
            PdfFont      font   = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", true);
            PdfFormField button = PdfFormField.CreatePushButton(doc, rect, "push button", "push", font, 12, PdfAConformanceLevel
                                                                .PDF_A_1B);

            button.RegenerateField();
            form.AddField(button);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
                                                                             ));
        }
        public virtual void CheckIfOcgForPdfA2Works()
        {
            String fileName    = "createdOcgPdfA.pdf";
            Stream colorStream = new FileStream(sourceFolder + "color/sRGB_CS_profile.icm", FileMode.Open, FileAccess.Read
                                                );
            String      outFileName = destinationFolder + fileName;
            String      cmpFileName = sourceFolder + "cmp/PdfA2LayoutOcgTest/cmp_" + fileName;
            PdfDocument pdfDoc      = new PdfADocument(new PdfWriter(outFileName), PdfAConformanceLevel.PDF_A_2A, new PdfOutputIntent
                                                           ("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", colorStream));

            pdfDoc.SetTagged();
            pdfDoc.GetCatalog().SetLang(new PdfString("en-US"));
            pdfDoc.AddNewPage();
            iText.Layout.Element.Image image1 = new Image(ImageDataFactory.Create(sourceFolder + "images/manualTransparency_for_png.png"
                                                                                  ));
            PdfCanvas pdfCanvas = new PdfCanvas(pdfDoc, 1);

            iText.Layout.Canvas canvas1     = new iText.Layout.Canvas(pdfCanvas, pdfDoc, new Rectangle(0, 0, 590, 420));
            PdfLayer            imageLayer1 = new PdfLayer("*[email protected]", pdfDoc);

            imageLayer1.SetOn(true);
            pdfCanvas.BeginLayer(imageLayer1);
            canvas1.Add(image1);
            pdfCanvas.EndLayer();
            canvas1.Close();
            pdfDoc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff01_"));
        }
        public virtual void PdfA1aCheckFieldOffAppearanceTest()
        {
            String       name    = "pdfA1a_checkFieldOffAppearance";
            String       outPath = destinationFolder + name + ".pdf";
            String       cmpPath = cmpFolder + "cmp_" + name + ".pdf";
            String       diff    = "diff_" + name + "_";
            PdfWriter    writer  = new PdfWriter(outPath);
            Stream       @is     = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
            PdfADocument doc     = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom", ""
                                                                                                               , "http://www.color.org", "sRGB IEC61966-2.1", @is));

            doc.SetTagged();
            doc.GetCatalog().SetLang(new PdfString("en-US"));
            doc.AddNewPage();
            PdfAcroForm  form = PdfAcroForm.GetAcroForm(doc, true);
            PdfFormField chk  = PdfFormField.CreateCheckBox(doc, new Rectangle(100, 500, 50, 50), "name", "Off", PdfFormField
                                                            .TYPE_CHECK, PdfAConformanceLevel.PDF_A_1A);

            chk.SetBorderColor(ColorConstants.BLACK);
            chk.SetBorderWidth(1);
            form.AddField(chk);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
                                                                             ));
        }
        public virtual void CatalogCheck01()
        {
            String       outPdf = destinationFolder + "pdfA3b_catalogCheck01.pdf";
            String       cmpPdf = cmpFolder + "cmp_pdfA3b_catalogCheck01.pdf";
            PdfWriter    writer = new PdfWriter(outPdf);
            Stream       @is    = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
            PdfADocument doc    = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B, new PdfOutputIntent("Custom", ""
                                                                                                              , "http://www.color.org", "sRGB IEC61966-2.1", @is));

            doc.AddNewPage();
            PdfDictionary ocProperties = new PdfDictionary();
            PdfDictionary d            = new PdfDictionary();

            d.Put(PdfName.Name, new PdfString("CustomName"));
            PdfDictionary orderItem = new PdfDictionary();

            orderItem.Put(PdfName.Name, new PdfString("CustomName2"));
            PdfArray ocgs = new PdfArray();

            ocgs.Add(orderItem);
            ocProperties.Put(PdfName.OCGs, ocgs);
            ocProperties.Put(PdfName.D, d);
            doc.GetCatalog().Put(PdfName.OCProperties, ocProperties);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf));
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder));
        }
Exemple #5
0
        public virtual void PdfA1aRadioFieldOffAppearanceTest()
        {
            String          name         = "pdfA1a_radioFieldOffAppearance";
            String          outPath      = destinationFolder + name + ".pdf";
            String          cmpPath      = cmpFolder + "cmp_" + name + ".pdf";
            String          diff         = "diff_" + name + "_";
            PdfWriter       writer       = new PdfWriter(outPath);
            Stream          @is          = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
            PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
                                                               , @is);
            PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);

            doc.SetTagged();
            doc.GetCatalog().SetLang(new PdfString("en-US"));
            doc.AddNewPage();
            PdfAcroForm        form  = PdfAcroForm.GetAcroForm(doc, true);
            PdfButtonFormField group = PdfFormField.CreateRadioGroup(doc, "group", "1", PdfAConformanceLevel.PDF_A_1B);

            group.SetReadOnly(true);
            Rectangle rect1 = new Rectangle(36, 700, 20, 20);
            Rectangle rect2 = new Rectangle(36, 680, 20, 20);

            PdfFormField.CreateRadioButton(doc, rect1, group, "1", PdfAConformanceLevel.PDF_A_1B).SetBorderWidth(2).SetBorderColor
                (ColorConstants.RED).SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetVisibility(PdfFormField.VISIBLE);
            PdfFormField.CreateRadioButton(doc, rect2, group, "2", PdfAConformanceLevel.PDF_A_1B).SetBorderWidth(2).SetBorderColor
                (ColorConstants.RED).SetBackgroundColor(ColorConstants.LIGHT_GRAY).SetVisibility(PdfFormField.VISIBLE);
            form.AddField(group);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
                                                                             ));
        }
        public virtual void CheckThatFlushingPreventedWhenAddingElementToDocument()
        {
            // Expected log message that page flushing was not performed
            String       outPdf = destinationFolder + "checkThatFlushingPreventedWhenAddingElementToDocument.pdf";
            PdfWriter    writer = new PdfWriter(outPdf);
            PdfADocument pdfDoc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom"
                                                                                                              , "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(sourceFolder + "sRGB Color Space Profile.icm"
                                                                                                                                                                                , FileMode.Open, FileAccess.Read)));

            pdfDoc.SetTagged();
            pdfDoc.GetCatalog().SetLang(new PdfString("en-US"));
            PdfAPageTest.EndPageEventHandler eventHandler = new PdfAPageTest.EndPageEventHandler();
            pdfDoc.AddEventHandler(PdfDocumentEvent.END_PAGE, eventHandler);
            int      pageCount = 3;
            Document document  = new Document(pdfDoc, PageSize.A4);

            for (int i = 1; i < pageCount; i++)
            {
                // Adding a area break causes a new page to be added and an attempt to flush the page will occur,
                // but flushing these pages will be prevented due to a condition added to the PdfAPage#flush method
                document.Add(new AreaBreak());
            }
            // Before closing document have 3 pages, but no one call of end page event
            NUnit.Framework.Assert.AreEqual(pageCount, document.GetPdfDocument().GetNumberOfPages());
            NUnit.Framework.Assert.AreEqual(0, eventHandler.GetCounter());
            document.Close();
            // During the closing event was called on each document page
            NUnit.Framework.Assert.AreEqual(pageCount, eventHandler.GetCounter());
            NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf));
        }
        public virtual void CheckFlushingOfCheckedPage()
        {
            String       outPdf = destinationFolder + "checkFlushingOfCheckedPage.pdf";
            PdfWriter    writer = new PdfWriter(outPdf);
            PdfADocument pdfDoc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom"
                                                                                                              , "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(sourceFolder + "sRGB Color Space Profile.icm"
                                                                                                                                                                                , FileMode.Open, FileAccess.Read)));

            pdfDoc.SetTagged();
            pdfDoc.GetCatalog().SetLang(new PdfString("en-US"));
            PdfAPageTest.EndPageEventHandler eventHandler = new PdfAPageTest.EndPageEventHandler();
            pdfDoc.AddEventHandler(PdfDocumentEvent.END_PAGE, eventHandler);
            int pageCount = 3;

            for (int i = 0; i < pageCount; i++)
            {
                PdfPage page = pdfDoc.AddNewPage();
                pdfDoc.checker.CheckSinglePage(page);
                page.Flush(false);
            }
            NUnit.Framework.Assert.AreEqual(pageCount, pdfDoc.GetNumberOfPages());
            NUnit.Framework.Assert.AreEqual(pageCount, eventHandler.GetCounter());
            pdfDoc.Close();
            NUnit.Framework.Assert.AreEqual(pageCount, eventHandler.GetCounter());
            NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(outPdf));
        }
 public virtual void ActionCheck11()
 {
     NUnit.Framework.Assert.That(() => {
         PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
         Stream @is       = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
         PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
                                                                                                        , "http://www.color.org", "sRGB IEC61966-2.1", @is));
         doc.GetCatalog().SetAdditionalAction(PdfName.C, PdfAction.CreateJavaScript("js"));
         doc.Close();
     }
                                 , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.A_CATALOG_DICTIONARY_SHALL_NOT_CONTAIN_AA_ENTRY));
     ;
 }
Exemple #9
0
 public virtual void CatalogCheck09()
 {
     NUnit.Framework.Assert.That(() => {
         PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
         Stream @is       = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
         PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
                                                                                                        , "http://www.color.org", "sRGB IEC61966-2.1", @is));
         doc.AddNewPage();
         PdfDictionary names = new PdfDictionary();
         names.Put(PdfName.AlternatePresentations, new PdfDictionary());
         doc.GetCatalog().Put(PdfName.Names, names);
         doc.Close();
     }
                                 , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.A_CATALOG_DICTIONARY_SHALL_NOT_CONTAIN_ALTERNATEPRESENTATIONS_NAMES_ENTRY));
     ;
 }
Exemple #10
0
 public virtual void ActionCheck07()
 {
     NUnit.Framework.Assert.That(() => {
         PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
         Stream @is       = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
         PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
                                                                                                        , "http://www.color.org", "sRGB IEC61966-2.1", @is));
         doc.AddNewPage();
         PdfDictionary openActions = new PdfDictionary();
         openActions.Put(PdfName.S, PdfName.JavaScript);
         doc.GetCatalog().Put(PdfName.OpenAction, openActions);
         doc.Close();
     }
                                 , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException._1ActionsAreNotAllowed));
     ;
 }
Exemple #11
0
 public virtual void AnnotationCheckTest08()
 {
     NUnit.Framework.Assert.That(() => {
         PdfWriter writer = new PdfWriter(new ByteArrayOutputStream());
         Stream @is       = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
         PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom", ""
                                                                                                        , "http://www.color.org", "sRGB IEC61966-2.1", @is));
         doc.SetTagged();
         doc.GetCatalog().SetLang(new PdfString("en-US"));
         PdfPage page        = doc.AddNewPage();
         Rectangle rect      = new Rectangle(100, 100, 100, 100);
         PdfAnnotation annot = new PdfStampAnnotation(rect);
         annot.SetFlag(PdfAnnotation.PRINT);
         page.AddAnnotation(annot);
         doc.Close();
     }
                                 , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.AnnotationOfType1ShouldHaveContentsKey));
     ;
 }
        public virtual void AnnotationCheckTest09()
        {
            String       outPdf = destinationFolder + "pdfA1a_annotationCheckTest09.pdf";
            String       cmpPdf = cmpFolder + "cmp_pdfA1a_annotationCheckTest09.pdf";
            PdfWriter    writer = new PdfWriter(outPdf);
            Stream       @is    = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
            PdfADocument doc    = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom", ""
                                                                                                              , "http://www.color.org", "sRGB IEC61966-2.1", @is));

            doc.SetTagged();
            doc.GetCatalog().SetLang(new PdfString("en-US"));
            PdfPage       page  = doc.AddNewPage();
            Rectangle     rect  = new Rectangle(100, 100, 100, 100);
            PdfAnnotation annot = new PdfStampAnnotation(rect);

            annot.SetFlag(PdfAnnotation.PRINT);
            annot.SetContents("Hello world");
            page.AddAnnotation(annot);
            doc.Close();
            CompareResult(outPdf, cmpPdf);
        }