Пример #1
0
        public virtual void ComparatorErrorTest()
        {
            // TODO: DEVSIX-4017 (Combination of default and pdfCalligraph fonts with italic style and '"courier new", courier,
            // monospace' family reproduces comparator exception. Update test after fixing.)
            ConverterProperties properties = new ConverterProperties();
            FontProvider        pro        = new DefaultFontProvider();

            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSansArabic-Regular.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSansArabic-Bold.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSansGurmukhi-Regular.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSansGurmukhi-Bold.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSansMyanmar-Regular.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSansMyanmar-Bold.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSansOriya-Regular.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSansOriya-Bold.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifBengali-Regular.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifBengali-Bold.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifDevanagari-Regular.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifDevanagari-Bold.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifGujarati-Regular.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifGujarati-Bold.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifHebrew-Regular.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifHebrew-Bold.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifKannada-Regular.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifKannada-Bold.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifKhmer-Regular.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifKhmer-Bold.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifMalayalam-Regular.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifMalayalam-Bold.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifMyanmar-Regular.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifMyanmar-Bold.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifTamil-Regular.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifTamil-Bold.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifTelugu-Regular.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifTelugu-Bold.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifThai-Regular.ttf"));
            pro.AddFont(FontProgramFactory.CreateFont(SOURCE_FOLDER + "NotoSerifThai-Bold.ttf"));
            properties.SetFontProvider(pro);
            bool isExceptionThrown = false;

            try {
                HtmlConverter.ConvertToPdf(new FileInfo(SOURCE_FOLDER + "comparatorError.html"), new FileInfo(DESTINATION_FOLDER
                                                                                                              + "comparatorError.pdf"), properties);
            }
            catch (ArgumentException e) {
                NUnit.Framework.Assert.AreEqual("Comparison method violates its general contract!", e.Message);
                isExceptionThrown = true;
            }
            if (!isExceptionThrown)
            {
                NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(DESTINATION_FOLDER + "comparatorError.pdf"
                                                                                 , SOURCE_FOLDER + "cmp_comparatorError.pdf", DESTINATION_FOLDER));
            }
        }
Пример #2
0
        public virtual void BatchConversionTest()
        {
            ConverterProperties properties = new ConverterProperties().SetBaseUri(sourceFolder).SetMediaDeviceDescription
                                                 (new MediaDeviceDescription(MediaType.PRINT));
            FontProvider fontProvider = new DefaultFontProvider(true, false, false);

            fontProvider.AddDirectory(sourceFolder + "fonts/");
            properties.SetFontProvider(fontProvider);
            IHtmlProcessor processor   = new DefaultHtmlProcessor(properties);
            IXmlParser     parser      = new JsoupHtmlParser();
            String         outPdfPath  = destinationFolder + "smashing1.pdf";
            PdfDocument    pdfDocument = new PdfDocument(new PdfWriter(outPdfPath));
            IDocumentNode  doc         = parser.Parse(new FileStream(sourceFolder + "smashing01.html", FileMode.Open, FileAccess.Read
                                                                     ), properties.GetCharset());
            Document document = processor.ProcessDocument(doc, pdfDocument);

            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdfPath, sourceFolder + "cmp_smashing1.pdf"
                                                                             , destinationFolder, "diff01_"));
        }
 public virtual void DoNotResetFontProviderTest()
 {
     NUnit.Framework.Assert.That(() => {
         FileStream fileInputStream = new FileStream(sourceFolder + "justHelloWorld.html", FileMode.Open, FileAccess.Read
                                                     );
         IXmlParser parser          = new JsoupHtmlParser();
         IDocumentNode documentNode = parser.Parse(fileInputStream, null);
         ConverterProperties converterProperties = new ConverterProperties();
         converterProperties.SetFontProvider(new _DefaultFontProvider_91(false, true, false));
         // Do nothing here. That should result in an exception.
         IHtmlProcessor processor = new DefaultHtmlProcessor(converterProperties);
         Document doc1            = processor.ProcessDocument(documentNode, new PdfDocument(new PdfWriter(new MemoryStream()))
                                                              );
         doc1.Close();
         Document doc2 = processor.ProcessDocument(documentNode, new PdfDocument(new PdfWriter(new MemoryStream()))
                                                   );
         doc2.Close();
         NUnit.Framework.Assert.IsTrue(false, "The test should have failed before that assert, since it's strictly forbidden not to reset the FontProvider instance after each html to pdf conversion."
                                       );
     }
                                 , NUnit.Framework.Throws.InstanceOf <PdfException>())
     ;
 }