Exemplo n.º 1
0
        public virtual void FontsResourcesHelvFontTest()
        {
            String      filename = "fontsResourcesHelvFontTest.pdf";
            PdfDocument pdfDoc   = new PdfDocument(new PdfReader(sourceFolder + "drWithHelv.pdf"), new PdfWriter(destinationFolder
                                                                                                                 + filename));
            PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "NotoSans-Regular.ttf", PdfEncodings.IDENTITY_H);

            font.SetSubset(false);
            PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, false);

            form.GetField("description").SetValue(TEXT, font, 12f);
            pdfDoc.Close();
            PdfDocument   document            = new PdfDocument(new PdfReader(destinationFolder + filename));
            PdfDictionary actualDocumentFonts = PdfAcroForm.GetAcroForm(document, false).GetPdfObject().GetAsDictionary
                                                    (PdfName.DR).GetAsDictionary(PdfName.Font);
            // Note that we know the structure of the expected pdf file
            PdfString expectedFieldsDAFont = new PdfString("/F2 12 Tf");
            PdfObject actualFieldDAFont    = document.GetCatalog().GetPdfObject().GetAsDictionary(PdfName.AcroForm).GetAsArray
                                                 (PdfName.Fields).GetAsDictionary(0).Get(PdfName.DA);

            NUnit.Framework.Assert.AreEqual(new PdfName("Helvetica"), actualDocumentFonts.GetAsDictionary(new PdfName(
                                                                                                              "F1")).Get(PdfName.BaseFont), "There is no Helvetica font within DR key");
            NUnit.Framework.Assert.AreEqual(new PdfName("NotoSans"), actualDocumentFonts.GetAsDictionary(new PdfName("F2"
                                                                                                                     )).Get(PdfName.BaseFont), "There is no NotoSans font within DR key.");
            NUnit.Framework.Assert.AreEqual(expectedFieldsDAFont, actualFieldDAFont, "There is no NotoSans(/F2) font within Fields DA key"
                                            );
            document.Close();
            ExtendedITextTest.PrintOutputPdfNameAndDir(destinationFolder + filename);
        }
Exemplo n.º 2
0
 /// <summary>Returns target directory (because target/test could not exist).</summary>
 public static String GetTargetDirectory()
 {
     if (!File.Exists(System.IO.Path.Combine(TARGET_DIRECTORY)))
     {
         ExtendedITextTest.CreateDestinationFolder(TARGET_DIRECTORY);
     }
     return(TARGET_DIRECTORY);
 }
Exemplo n.º 3
0
 public virtual void PageCountTestTableFloatLeft()
 {
     NUnit.Framework.Assert.That(() => {
         //TODO: DEVSIX-1570, SUP-2322. Remove junitExpectedException after the fix.
         String expectedText         = "Page 3 of 3";
         String nameFloatLeft        = "htmlWithTableFloatLeft.html";
         String pdfOutputName        = DESTINATION_FOLDER + nameFloatLeft + ".pdf";
         FileInfo pdfOutputFloatLeft = new FileInfo(pdfOutputName);
         HtmlConverter.ConvertToPdf(new FileInfo(SOURCE_FOLDER + nameFloatLeft), pdfOutputFloatLeft);
         PdfDocument pdfDocument = new PdfDocument(new PdfReader(pdfOutputFloatLeft));
         String textFromPage     = PdfTextExtractor.GetTextFromPage(pdfDocument.GetPage(3));
         // Print the output file. No comparison will be made on the following line
         ExtendedITextTest.PrintOutputPdfNameAndDir(pdfOutputName);
         NUnit.Framework.Assert.IsTrue(textFromPage.Contains(expectedText), "Page doesn't contain text " + expectedText
                                       );
     }
                                 , NUnit.Framework.Throws.InstanceOf <AssertionException>())
     ;
 }