Пример #1
0
        private HtmlResourceResolver CreateResolver()
        {
            ConverterProperties cp = new ConverterProperties();

            cp.SetBaseUri(sourceFolder);
            return(new HtmlResourceResolver(sourceFolder, new ProcessorContext(cp)));
        }
Пример #2
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        /// <exception cref="Javax.Xml.Parsers.ParserConfigurationException"/>
        /// <exception cref="Org.Xml.Sax.SAXException"/>
        public virtual void ConvertToPdfAcroformFlattenAndCompare(String name, String sourceFolder, String destinationFolder
                                                                  , bool tagged)
        {
            String sourceHtml = sourceFolder + name + ".html";

            if (tagged)
            {
                name = name + "Tagged";
            }
            String outPdfPath            = destinationFolder + name + ".pdf";
            String outPdfPathAcro        = destinationFolder + name + "_acro.pdf";
            String outPdfPathFlatted     = destinationFolder + name + "_acro_flatten.pdf";
            String cmpPdfPath            = sourceFolder + "cmp_" + name + ".pdf";
            String cmpPdfPathAcro        = sourceFolder + "cmp_" + name + "_acro.pdf";
            String cmpPdfPathAcroFlatten = sourceFolder + "cmp_" + name + "_acro_flatten.pdf";
            String diff1 = "diff1_" + name;
            String diff2 = "diff2_" + name;
            String diff3 = "diff3_" + name;
            //convert tagged PDF without acroform (from html with form elements)
            PdfWriter   taggedWriter = new PdfWriter(outPdfPath);
            PdfDocument pdfTagged    = new PdfDocument(taggedWriter);

            if (tagged)
            {
                pdfTagged.SetTagged();
            }
            HtmlConverter.ConvertToPdf(new FileStream(sourceHtml, FileMode.Open, FileAccess.Read), pdfTagged, new ConverterProperties
                                           ().SetBaseUri(sourceFolder));
            //convert PDF with acroform
            PdfWriter   writerAcro    = new PdfWriter(outPdfPathAcro);
            PdfDocument pdfTaggedAcro = new PdfDocument(writerAcro);

            if (tagged)
            {
                pdfTaggedAcro.SetTagged();
            }
            ConverterProperties converterPropertiesAcro = new ConverterProperties();

            converterPropertiesAcro.SetBaseUri(sourceFolder);
            converterPropertiesAcro.SetCreateAcroForm(true);
            HtmlConverter.ConvertToPdf(new FileStream(sourceHtml, FileMode.Open, FileAccess.Read), pdfTaggedAcro, converterPropertiesAcro
                                       );
            System.Console.Out.WriteLine("html: file:///" + UrlUtil.ToNormalizedURI(sourceHtml).AbsolutePath + "\n");
            //flatted created tagged PDF with acroform
            PdfDocument document = new PdfDocument(new PdfReader(outPdfPathAcro), new PdfWriter(outPdfPathFlatted));
            PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(document, false);

            acroForm.FlattenFields();
            document.Close();
            //compare with cmp
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdfPath, cmpPdfPath, destinationFolder
                                                                             , diff1));
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdfPathAcro, cmpPdfPathAcro, destinationFolder
                                                                             , diff2));
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdfPathFlatted, cmpPdfPathAcroFlatten,
                                                                             destinationFolder, diff3));
            //compare tags structure if tagged
            if (tagged)
            {
                CompareTagStructure(outPdfPath, cmpPdfPath);
                CompareTagStructure(outPdfPathAcro, cmpPdfPathAcro);
                CompareTagStructure(outPdfPathFlatted, cmpPdfPathAcroFlatten);
            }
        }