/// <summary> /// Creates the PDF file. /// </summary> /// <param name="src">the path to the source HTML file</param> /// <param name="dest">the path to the resulting PDF</param> public void CreatePdf(String src, String dest) { ConverterProperties converterProperties = new ConverterProperties(); converterProperties.SetCssApplierFactory(new CustomCssApplierFactory()); HtmlConverter.ConvertToPdf(new FileInfo(src), new FileInfo(dest), converterProperties); }
/// <summary> /// Creates the PDF file. /// </summary> /// <param name="src">the path to the source HTML file</param> /// <param name="dest">the path to the resulting PDF</param> public void CreatePdf(String src, String dest) { ConverterProperties properties = new ConverterProperties(); properties .SetCssApplierFactory(new QRCodeTagCssApplierFactory()) .SetTagWorkerFactory(new QRCodeTagWorkerFactory()); HtmlConverter.ConvertToPdf(new FileInfo(src), new FileInfo(dest), properties); }
public void ManipulatePdf(string html, string pdfDest) { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(pdfDest)); pdfDoc.AddNewPage(); DefaultCssApplierFactory cssApplierFactory = new CellTagCssApplierFactory(); ConverterProperties converterProperties = new ConverterProperties(); // Using custom css applier with OverflowPropertyValue.FIT set, // we can achieve that text content of table's cell suits their width converterProperties.SetCssApplierFactory(cssApplierFactory); HtmlConverter.ConvertToPdf(html, pdfDoc, converterProperties); pdfDoc.Close(); }
public void ManipulatePdf(string htmlSource, string pdfDest, string resourceLoc) { // Base URI is required to resolve the path to source files ConverterProperties converterProperties = new ConverterProperties().SetBaseUri(resourceLoc); // Create custom css applier factory. // Current custom css applier factory handle <div> and <span> tags of html and returns corresponding css applier. // All of that css appliers change value of RGB colors // to simulate color blindness of people (like Tritanopia, Achromatopsia, etc.) DefaultCssApplierFactory cssApplierFactory = new ColorBlindnessCssApplierFactory(ColorBlindnessTransforms.DEUTERANOMALY); converterProperties.SetCssApplierFactory(cssApplierFactory); HtmlConverter.ConvertToPdf( new FileStream(htmlSource, FileMode.Open, FileAccess.Read, FileShare.Read), new FileStream(pdfDest, FileMode.Create, FileAccess.Write), converterProperties); }
public virtual void AlterOrphansWidowsTest() { ConverterProperties converterProperties = new ConverterProperties(); DefaultCssApplierFactory cssApplierFactory = new OrphansWidowsUnitTest.CustomBlockCssApplierFactory(); converterProperties.SetCssApplierFactory(cssApplierFactory); IList <IElement> elements = HtmlConverter.ConvertToElements(new FileStream(sourceFolder + "orphansWidows.html" , FileMode.Open, FileAccess.Read), converterProperties); Div div = (Div)elements[0]; NUnit.Framework.Assert.IsNotNull(div); Paragraph paragraph = (Paragraph)div.GetChildren()[0]; NUnit.Framework.Assert.IsNotNull(paragraph); ParagraphWidowsControl paragraphWidowsControl = paragraph.GetProperty <ParagraphWidowsControl>(Property.WIDOWS_CONTROL ); NUnit.Framework.Assert.IsNotNull(paragraphWidowsControl); NUnit.Framework.Assert.AreEqual(3, paragraphWidowsControl.GetMaxLinesToMove()); NUnit.Framework.Assert.IsTrue(paragraphWidowsControl.IsOverflowOnWidowsViolation()); }
/// <summary> /// Convierte texto html de entrada en un archivo pdf. /// </summary> /// <param name="html">Html a convertir en pdf.</param> /// <param name="orientation">OrientaciĆ³n.</param> /// <param name="fontData">Byte content of the font program file.</param> /// <returns>Datos binarios del pdf.</returns> public byte[] GetPdfFormHtml(string html, string orientation = "PORTRAIT", byte[] fontData = null) { QRCodeTagWorkerFactory = new QRCodeTagWorkerFactory(); ConverterProperties properties = new ConverterProperties(); properties.SetTagWorkerFactory(QRCodeTagWorkerFactory); properties.SetCssApplierFactory(new QRCodeTagCssApplierFactory()); if (fontData != null) { FontProvider fontProvider = new FontProvider(); fontProvider.AddFont(fontData, PdfEncodings.IDENTITY_H); properties.SetFontProvider(fontProvider); } byte[] result = null; using (var ms = new MemoryStream()) { using (var pdfDocument = new PdfDocument(new PdfWriter(ms))) { if (orientation.ToUpper() == "LANDSCAPE") { pdfDocument.SetDefaultPageSize(PageSize.A4.Rotate()); } HtmlConverter.ConvertToPdf(html, pdfDocument, properties); result = ms.ToArray(); } } return(result); }