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_")); }
/// <summary> /// Converts HTML obtained from an /// <see cref="System.IO.Stream"/> /// to a /// <see cref="System.Collections.IList{E}"/> /// of /// iText objects ( /// <see cref="iText.Layout.Element.IElement"/> /// instances), using specific /// <see cref="ConverterProperties"/> /// . /// </summary> /// <param name="htmlStream"> /// the /// <see cref="System.IO.Stream"/> /// with the source HTML /// </param> /// <param name="converterProperties"> /// a /// <see cref="ConverterProperties"/> /// instance /// </param> /// <returns>a list of iText building blocks</returns> /// <exception cref="System.IO.IOException">Signals that an I/O exception has occurred.</exception> public static IList <IElement> ConvertToElements(Stream htmlStream, ConverterProperties converterProperties ) { try { String licenseKeyClassName = "iText.License.LicenseKey, itext.licensekey"; String licenseKeyProductClassName = "iText.License.LicenseKeyProduct, itext.licensekey"; String licenseKeyFeatureClassName = "iText.License.LicenseKeyProductFeature, itext.licensekey"; String checkLicenseKeyMethodName = "ScheduledCheck"; Type licenseKeyClass = GetClass(licenseKeyClassName); if (licenseKeyClass != null) { Type licenseKeyProductClass = GetClass(licenseKeyProductClassName); Type licenseKeyProductFeatureClass = GetClass(licenseKeyFeatureClassName); Array array = Array.CreateInstance(licenseKeyProductFeatureClass, 0); object[] objects = new object[] { Html2PdfProductInfo.PRODUCT_NAME, Html2PdfProductInfo.MAJOR_VERSION, Html2PdfProductInfo.MINOR_VERSION, array }; Object productObject = System.Activator.CreateInstance(licenseKeyProductClass, objects); MethodInfo m = licenseKeyClass.GetMethod(checkLicenseKeyMethodName); m.Invoke(System.Activator.CreateInstance(licenseKeyClass), new object[] { productObject }); } } catch (Exception e) { if (!Kernel.Version.IsAGPLVersion()) { throw; } } IXmlParser parser = new JsoupHtmlParser(); IDocumentNode doc = parser.Parse(htmlStream, converterProperties != null ? converterProperties.GetCharset( ) : null); return(Attacher.Attach(doc, converterProperties)); }
/// <summary> /// Converts HTML obtained from an /// <see cref="System.IO.Stream"/> /// to a /// <see cref="System.Collections.IList{E}"/> /// of /// iText objects ( /// <see cref="iText.Layout.Element.IElement"/> /// instances), using specific /// <see cref="ConverterProperties"/>. /// </summary> /// <param name="htmlStream"> /// the /// <see cref="System.IO.Stream"/> /// with the source HTML /// </param> /// <param name="converterProperties"> /// a /// <see cref="ConverterProperties"/> /// instance /// </param> /// <returns>a list of iText building blocks</returns> public static IList <IElement> ConvertToElements(Stream htmlStream, ConverterProperties converterProperties ) { ReflectionUtils.ScheduledLicenseCheck(); IXmlParser parser = new JsoupHtmlParser(); IDocumentNode doc = parser.Parse(htmlStream, converterProperties != null ? converterProperties.GetCharset( ) : null); return(Attacher.Attach(doc, converterProperties)); }
/// <summary> /// Converts HTML obtained from an /// <see cref="System.IO.Stream"/> /// to objects that /// will be added to a /// <see cref="iText.Kernel.Pdf.PdfDocument"/> /// , using specific /// <see cref="ConverterProperties"/> /// , /// returning a /// <see cref="iText.Layout.Document"/> /// instance. /// </summary> /// <param name="htmlStream"> /// the /// <see cref="System.IO.Stream"/> /// with the source HTML /// </param> /// <param name="pdfDocument"> /// the /// <see cref="iText.Kernel.Pdf.PdfDocument"/> /// instance /// </param> /// <param name="converterProperties"> /// a /// <see cref="ConverterProperties"/> /// instance /// </param> /// <returns> /// a /// <see cref="iText.Layout.Document"/> /// instance /// </returns> public static Document ConvertToDocument(Stream htmlStream, PdfDocument pdfDocument, ConverterProperties converterProperties ) { ReflectionUtils.ScheduledLicenseCheck(); if (pdfDocument.GetReader() != null) { throw new Html2PdfException(Html2PdfException.PdfDocumentShouldBeInWritingMode); } IXmlParser parser = new JsoupHtmlParser(); IDocumentNode doc = parser.Parse(htmlStream, converterProperties != null ? converterProperties.GetCharset( ) : null); return(Attacher.Attach(doc, pdfDocument, converterProperties)); }