diff --git a/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/Convert-HTML-to-PDF-in-Azure-Function-App-Container.md b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/Convert-HTML-to-PDF-in-Azure-Function-App-Container.md index 4c684dfdf..c17e4a920 100644 --- a/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/Convert-HTML-to-PDF-in-Azure-Function-App-Container.md +++ b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/Convert-HTML-to-PDF-in-Azure-Function-App-Container.md @@ -64,7 +64,7 @@ public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post ms = new MemoryStream(); // Save and close the PDF document document.Save(ms); - document.Close(); + document.Close(true); } catch (Exception ex) { diff --git a/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/aws.md b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/aws.md index 42ad72e19..7c4ed2544 100644 --- a/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/aws.md +++ b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/aws.md @@ -19,15 +19,16 @@ The Syncfusion® [HTML to PDF converter](https://www.syncfusion.co ## Convert HTML to PDF in AWS Lambda -<<<<<<< HEAD HTML to PDF converter .NET library supports conversion in AWS Lambda. Refer to [this](https://help.syncfusion.com/document-processing/pdf/conversions/html-to-pdf/net/convert-html-to-pdf-in-aws-lambda) section for more information about HTML to PDF conversion in AWS Lambda. ## Convert HTML to PDF in AWS Lambda with NET 6 container image -HTML to PDF converter .NET library supports conversion in AWS Lambda with NET 6 container image. Refer to [this](https://help.syncfusion.com/document-processing/pdf/conversions/html-to-pdf/net/convert-html-to-pdf-in-aws-lambda-with-net6-container-image) section for more information about HTML to PDF conversion in AWS Lambda with NET 6 container image. +HTML to PDF converter .NET library supports conversion in AWS Lambda with NET 6 container image. Refer to [this](https://help.syncfusion.com/document-processing/pdf/conversions/html-to-pdf/net/convert-html-to-pdf-in-aws-lambda-with-net-6-container-image) section for more information about HTML to PDF conversion in AWS Lambda with NET 6 container image. -## Convert HTML to PDF in AWS Elastic Beanstalk. +## Convert HTML to PDF in AWS Elastic Beanstalk HTML to PDF converter .NET library supports conversion in AWS Elastic Beanstalk. Refer to [this](https://help.syncfusion.com/document-processing/pdf/conversions/html-to-pdf/net/convert-html-to-pdf-in-aws-elastic-beanstalk) section for more information about HTML to PDF conversion in AWS Elastic Beanstalk. +## Convert HTML to PDF in Amazon ECS with Fargate +HTML to PDF converter .NET library supports conversion in Amazon ECS with Fargate. Refer to this section for more information about HTML to PDF conversion in Amazon ECS with Fargate. \ No newline at end of file diff --git a/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/features.md b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/features.md index 5282696e6..3ce65618b 100644 --- a/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/features.md +++ b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/features.md @@ -16,13 +16,16 @@ To convert website URL or local HTML file to PDF document using [Convert](https: {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Convert-website-URL-to-PDF-document/.NET/Convert-website-URL-to-PDF-document/Program.cs, 300" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Convert URL to PDF PdfDocument document = htmlConverter.Convert("https://www.google.com"); -FileStream fileStream = new FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite); + //Save and close the PDF document. -document.Save(fileStream); +document.Save("Output.pdf"); document.Close(true); @@ -30,13 +33,16 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + 'Initialize HTML to PDF converter Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() 'Convert URL to PDF Dim document As PdfDocument = htmlConverter.Convert("https://www.google.com") + 'Save and close the PDF document document.Save("Output.pdf") - document.Close(True) {% endhighlight %} @@ -63,6 +69,9 @@ To convert the HTML string to PDF using [Convert](https://help.syncfusion.com/cr {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Convert-the-HTML-string-to-PDF-document/.NET/Convert-the-HTML-string-to-PDF-document/Program.cs, 300" %} +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; + //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); @@ -72,15 +81,18 @@ string baseUrl = @"C:/Temp/HTMLFiles/"; //Convert URL to PDF PdfDocument document = htmlConverter.Convert(htmlText, baseUrl); -FileStream fileStream = new FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite); + //Save and close the PDF document. -document.Save(fileStream); +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.HtmlConverter + 'Initialize HTML to PDF converter Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() @@ -118,38 +130,43 @@ To convert website URL or local HTML file to Image using [ConvertToImage](https: {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Convert-website-URL-to-image-file/.NET/Convert-website-URL-to-image-file/Program.cs, 300" %} +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; + //Initialize HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Convert URL to Image Image image = htmlConverter.ConvertToImage("https://www.google.com"); -byte[] imageByte = image.ImageData; -//Save the image -File.WriteAllBytes("Output.jpg", imageByte); +//Save the image. +File.WriteAllBytes(Path.GetFullPath(@"Output/Output.jpg"), image.ImageData); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; + //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Convert URL to Image Image[] image = htmlConverter.ConvertToImage("https://www.google.com"); -//Save and dispose the image file -image[0].Save("Output.jpg"); -image[0].Dispose(); +//Save the image. +File.WriteAllBytes(Path.GetFullPath(@"Output/Output.jpg"), image.ImageData); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.HtmlConverter + 'Initialize HTML to PDF converter. Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() 'Convert URL to Image Dim image As Image[] = htmlConverter.ConvertToImage("https://www.google.com") -'Save and dispose the image file -image[0].Save("Output.jpg") - -image[0].Dispose(True) +'Save the image. +File.WriteAllBytes(Path.GetFullPath(@"Output/Output.jpg"), image.ImageData) {% endhighlight %} @@ -175,6 +192,9 @@ To convert the HTML string to Image using [ConvertToImage](https://help.syncfusi {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Convert-the-HTML-string-to-image-file/.NET/Convert-the-HTML-string-to-image-file/Program.cs, 300" %} +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; + //Initialize HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); @@ -184,14 +204,16 @@ string baseUrl = @"C:/Temp/HTMLFiles/"; //Convert HTML string to Image Image image = htmlConverter.ConvertToImage(htmlText, baseUrl); -byte[] imageByte = image.ImageData; -//Save the image -File.WriteAllBytes("Output.jpg", imageByte); +//Save the image. +File.WriteAllBytes(Path.GetFullPath(@"Output/Output.jpg"), image.ImageData); {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +using System.Drawing; +using Syncfusion.HtmlConverter; + //Initialize HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); @@ -200,15 +222,17 @@ string htmlText = "\"Syncfusion The HTML converter internally uses the viewport size in points. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Adjusting-the-HTML-content-size-in-PDF-document/.NET/Adjusting-the-HTML-content-size-in-PDF-document/Program.cs, 300" %} +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize the HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); @@ -1225,15 +1354,19 @@ htmlConverter.ConverterSettings = blinkConverterSettings; //Convert URL to PDF PdfDocument document = htmlConverter.Convert("https://www.google.com"); -FileStream fileStream = new FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite); + //Save and close the PDF document. -document.Save(fileStream); +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + 'Initialize the HTML to PDF converter. Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() @@ -1263,20 +1396,26 @@ The Blink rendering engine provides support for converting only the part of an H {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Convert-partial-webpage-to-PDF-document/.NET/Convert-partial-webpage-to-PDF-document/Program.cs, 300" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize the HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Convert Partial webpage to PDF PdfDocument document = htmlConverter.ConvertPartialHtml("input.html", "pic"); -FileStream fileStream = new FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite); + //Save and close the PDF document. -document.Save(fileStream); +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + 'Initialize the HTML to PDF converter. Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() @@ -1327,6 +1466,9 @@ Refer to the following code snippet. {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize the HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); @@ -1338,15 +1480,18 @@ htmlConverter.ConverterSettings = settings; //Convert URL to PDF PdfDocument document = htmlConverter.Convert("https://www.google.com"); -FileStream fileStream = new FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite); + //Save and close the PDF document. -document.Save(fileStream); +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + 'Initialize the HTML to PDF converter. Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() @@ -1374,6 +1519,9 @@ Getting height of the HTML content in PDF document is possible by using the [Pdf {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize the HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); @@ -1383,15 +1531,18 @@ PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com", out l //Draw the text at the end of HTML content PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 11); document.Pages[document.Pages.Count - 1].Graphics.DrawString("End of HTML content", font, PdfBrushes.Red, new PointF(0, layoutResult.Bounds.Bottom)); -FileStream fileStream = new FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite); + //Save and close the PDF document. -document.Save(fileStream); +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + 'Initialize the HTML to PDF converter. Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() @@ -1423,6 +1574,9 @@ Refer to the following code snippet. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Set-windows-status-while-converting-HTML-to-PDF/.NET/Set-windows-status-while-converting-HTML-to-PDF/Program.cs, 300" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + // Initialize the HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); @@ -1434,15 +1588,18 @@ htmlConverter.ConverterSettings = blinkConverterSettings; //Convert URL to PDF PdfDocument document = htmlConverter.Convert("input.html"); -FileStream fileStream = new FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite); + //Save and close the PDF document. -document.Save(fileStream); +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + 'Initialize HTML to PDF converter. Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() @@ -1492,6 +1649,9 @@ To set the page size when converting HTML to PDF, utilize the [PdfPageSize](http {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/HTML-to-PDF-page-size-customization/.NET/HTML-to-PDF-page-size-customization/Program.cs, 300" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize the HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Initialize blink converter settings. @@ -1503,10 +1663,8 @@ htmlConverter.ConverterSettings = blinkConverterSettings; //Convert URL to PDF document. PdfDocument document = htmlConverter.Convert("https://www.google.com"); -//Create a file stream. -FileStream fileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite); -//Save the PDF document to the file stream. -document.Save(fileStream); +//Save the PDF document +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -1514,6 +1672,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + 'Initialize HTML to PDF converter. Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() Dim blinkConverterSettings As BlinkConverterSettings = New BlinkConverterSettings() @@ -1524,10 +1685,8 @@ htmlConverter.ConverterSettings = blinkConverterSettings 'Convert URL to PDF document. Dim document As PdfDocument = htmlConverter.Convert("https://www.google.com") -'Create file stream to save the PDF document. -Dim fileStream As FileStream = New FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite) 'Save and close the PDF document. -document.Save(fileStream) +document.Save("Output.pdf") document.Close(True) {% endhighlight %} @@ -1544,6 +1703,9 @@ To set the margin when converting HTML to PDF, utilize the [Margin](https://help {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/HTML-to-PDF-margin-customization/.NET/HTML-to-PDF-margin-customization/Program.cs, 300" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize the HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Initialize blink converter settings. @@ -1555,10 +1717,8 @@ htmlConverter.ConverterSettings = blinkConverterSettings; //Convert URL to PDF document. PdfDocument document = htmlConverter.Convert("https://www.google.com"); -//Create a file stream. -FileStream fileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite); -//Save the PDF document to the file stream. -document.Save(fileStream); +//Save the PDF document +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -1566,6 +1726,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + 'Initialize HTML to PDF converter. Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() Dim blinkConverterSettings As BlinkConverterSettings = New BlinkConverterSettings() @@ -1576,10 +1739,8 @@ htmlConverter.ConverterSettings = blinkConverterSettings 'Convert URL to PDF document. Dim document As PdfDocument = htmlConverter.Convert("https://www.google.com") -'Create file stream to save the PDF document. -Dim fileStream As FileStream = New FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite) 'Save and close the PDF document. -document.Save(fileStream) +document.Save("Output.pdf") document.Close(True) {% endhighlight %} @@ -1596,6 +1757,11 @@ To set the header and footer when converting HTML to PDF, utilize the [PdfHeader {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/HTML-to-PDF-Header-and-footer/.NET/HTML-to-PDF-Header-and-footer/Program.cs, 300" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf; +using Syncfusion.Drawing; + //Initialize HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); @@ -1626,10 +1792,8 @@ htmlConverter.ConverterSettings = blinkConverterSettings; //Convert URL to PDF. PdfDocument document = htmlConverter.Convert("https://www.google.com/"); -//Create a file stream. -FileStream fileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite); -//Save a PDF document to the file stream. -document.Save(fileStream); +//Save a PDF document +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -1637,6 +1801,11 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf.Graphics +Imports Syncfusion.Pdf +Imports System.Drawing + 'Initialize HTML to PDF converter. Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() Dim blinkConverterSettings As BlinkConverterSettings = New BlinkConverterSettings() @@ -1668,10 +1837,8 @@ htmlConverter.ConverterSettings = blinkConverterSettings 'Convert URL to PDF document. Dim document As PdfDocument = htmlConverter.Convert("https://www.google.com") -'Create file stream to save the PDF document. -Dim fileStream As FileStream = New FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite) 'Save and close the PDF document. -document.Save(fileStream) +document.Save("Output.pdf") document.Close(True) {% endhighlight %} @@ -1688,6 +1855,9 @@ To set the Orientation when converting HTML to PDF, utilize the [Orientation](ht {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/HTML-to-PDF-page-orientation-customization/.NET/HTML-to-PDF-page-orientation-customization/Program.cs, 300" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize the HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Initialize blink converter settings. @@ -1699,10 +1869,8 @@ htmlConverter.ConverterSettings = blinkConverterSettings; //Convert URL to PDF document. PdfDocument document = htmlConverter.Convert("https://www.google.com"); -//Create a file stream. -FileStream fileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite); -//Save a PDF document to a file stream. -document.Save(fileStream); +//Save a PDF document. +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -1710,6 +1878,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + 'Initialize HTML to PDF converter. Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() Dim blinkConverterSettings As BlinkConverterSettings = New BlinkConverterSettings() @@ -1720,10 +1891,8 @@ htmlConverter.ConverterSettings = blinkConverterSettings 'Convert URL to PDF document. Dim document As PdfDocument = htmlConverter.Convert("https://www.google.com") -'Create file stream to save the PDF document. -Dim fileStream As FileStream = New FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite) 'Save and close the PDF document. -document.Save(fileStream) +document.Save("Output.pdf") document.Close(True) {% endhighlight %} @@ -1740,6 +1909,9 @@ To set the page rotation when converting HTML to PDF, utilize the [PageRotateAng {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/HTML-to-PDF-rotate-page/.NET/HTML-to-PDF-rotate-page/Program.cs, 300" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize the HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Initialize blink converter settings. @@ -1751,10 +1923,8 @@ htmlConverter.ConverterSettings = blinkConverterSettings; //Convert URL to PDF document. PdfDocument document = htmlConverter.Convert("https://www.google.com"); -//Create a file stream. -FileStream fileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite); -//Save a PDF document to a file stream. -document.Save(fileStream); +//Save a PDF document +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -1762,6 +1932,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + 'Initialize HTML to PDF converter. Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() Dim blinkConverterSettings As BlinkConverterSettings = New BlinkConverterSettings() @@ -1772,10 +1945,8 @@ htmlConverter.ConverterSettings = blinkConverterSettings 'Convert URL to PDF document. Dim document As PdfDocument = htmlConverter.Convert("https://www.google.com") -'Create file stream to save the PDF document. -Dim fileStream As FileStream = New FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite) 'Save and close the PDF document. -document.Save(fileStream) +document.Save("Output.pdf") document.Close(True) {% endhighlight %} @@ -1792,6 +1963,10 @@ When converting HTML to PDF, you can set an HTML file as header and footer. Use {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/HTML-Header-and-Footer/.NET/HTML-Header-and-Footer/Program.cs, 300" %} +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Initialize blink converter settings. @@ -1811,16 +1986,18 @@ htmlConverter.ConverterSettings = blinkConverterSettings; //Convert the URL to a PDF document. PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com"); -//Create a filestream. -FileStream fileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite); //Save and close a PDF document. -document.Save(fileStream); +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf +Imports System.Drawing + 'Initialize HTML to PDF converter. Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() 'Initialize blink converter settings. @@ -1840,10 +2017,8 @@ htmlConverter.ConverterSettings = blinkConverterSettings 'Convert the URL to a PDF document. Dim document As PdfDocument = htmlConverter.Convert("https://www.syncfusion.com") -'Create a filestream. -Dim fileStream As FileStream = New FileStream("Output.pdf", FileMode.CreateNew, FileAccess.ReadWrite) 'Save and close a PDF document. -document.Save(fileStream) +document.Save("Output.pdf") document.Close(True) {% endhighlight %} @@ -1864,6 +2039,10 @@ The Blink rendering engine supports the injection of custom CSS to be applied to {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Inject_custom_CSS_to_HTML/.NET/Inject_custom_CSS_to_HTML/Program.cs, 300" %} +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize the HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); @@ -1875,16 +2054,19 @@ blinkConverterSettings.Css = "body {\r\n background-color: red; \r\n}"; htmlConverter.ConverterSettings = blinkConverterSettings; //Convert the URL to PDF document. PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com"); -//Create a filestream. -FileStream fileStream = new FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite); + //Save and close the PDF document. -document.Save(fileStream); +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf +Imports System.Drawing + 'Initialize the HTML to PDF converter. Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() Dim blinkConverterSettings As BlinkConverterSettings = New BlinkConverterSettings() @@ -1896,10 +2078,9 @@ blinkConverterSettings.Css = "body {\r\n background-color: red; \r\n}" htmlConverter.ConverterSettings = blinkConverterSettings 'Convert the URL to PDF document. Dim document As PdfDocument = htmlConverter.Convert(https://www.syncfusion.com) -'Create a filestream. -Dim fileStream As FileStream = New FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite) + 'Save and close the PDF document. -document.Save(fileStream) +document.Save("Output.pdf") document.Close(true) {% endhighlight %} @@ -1918,6 +2099,10 @@ The Blink rendering engine offers support for injecting custom JavaScript to be {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Inject_custom_JavaScript_to_HTML/.NET/Inject_custom_JavaScript_to_HTML/Program.cs, 300" %} +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize the HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); @@ -1929,16 +2114,19 @@ blinkConverterSettings.JavaScript = "document.querySelectorAll('img').forEach((n htmlConverter.ConverterSettings = blinkConverterSettings; //Convert the URL to PDF document. PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com"); -//Create a filestream. -FileStream fileStream = new FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite); + //Save and close the PDF document. -document.Save(fileStream); +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf +Imports System.Drawing + 'Initialize the HTML to PDF converter. Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() Dim blinkConverterSettings As BlinkConverterSettings = New BlinkConverterSettings() @@ -1950,10 +2138,9 @@ blinkConverterSettings.JavaScript = "document.querySelectorAll('img').forEach((n htmlConverter.ConverterSettings = blinkConverterSettings 'Convert the URL to PDF document. Dim document As PdfDocument = htmlConverter.Convert("https://www.syncfusion.com") -'Create a filestream. -Dim fileStream As FileStream = New FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite) + 'Save and close the PDF document. -document.Save(fileStream) +document.Save("Output.pdf") document.Close(true) {% endhighlight %} @@ -1972,14 +2159,16 @@ The Blink rendering engine provides support for reusing the browser process to o {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Optimize-HTML-to-PDF-performance/.NET/Optimize-HTML-to-PDF-performance/Program.cs, 300" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize the HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Reuse the browser instance. htmlConverter.ReuseBrowserProcess = true; //Create PDF document. PdfDocument document = new PdfDocument(); -//Create memory stream. -MemoryStream memoryStream = new MemoryStream(); + for (int i = 0; i < 10; i++) { //Initialize the blink converter settings. @@ -1991,9 +2180,8 @@ for (int i = 0; i < 10; i++) //Convert the URL to PDF document. document = htmlConverter.Convert("https://www.google.com"); //Save and close the PDF document. - document.Save(memoryStream); + document.Save("Output.pdf"); document.Close(true); - File.WriteAllBytes("ReuseBrowserProcess" + Guid.NewGuid().ToString() + ".pdf", memoryStream.ToArray()); } //Close HTML converter. htmlConverter.Close(); @@ -2002,14 +2190,16 @@ htmlConverter.Close(); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + 'Initialize the HTML to PDF converter. Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() 'Reuse the browser instance. htmlConverter.ReuseBrowserProcess = True 'Create PDF document. Dim document As PdfDocument = New PdfDocument() -'Create memory stream. -Dim memoryStream As MemoryStream = New MemoryStream() + For i As Integer = 0 To 10 - 1 'Initialize the blink converter settings. Dim settings As BlinkConverterSettings = New BlinkConverterSettings() @@ -2020,9 +2210,8 @@ For i As Integer = 0 To 10 - 1 'Convert the URL to PDF document. document = htmlConverter.Convert("https://www.google.com") 'Save and close the PDF document. - document.Save(memoryStream) + document.Save("Output.pdf") document.Close(True) - File.WriteAllBytes("ReuseBrowserProcess" & Guid.NewGuid().ToString() & ".pdf", memoryStream.ToArray()) Next 'Close HTML converter. htmlConverter.Close() @@ -2031,6 +2220,8 @@ htmlConverter.Close() {% endtabs %} +N> Our HTML to PDF converter is thread-safe and suitable for multi-threaded environments without synchronization conflicts or data corruption. However, when the [ReuseBrowserProcess](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.HtmlToPdfConverter.html#Syncfusion_HtmlConverter_HtmlToPdfConverter_ReuseBrowserProcess) property is `enabled`, the same HtmlToPdfConverter instance must be reused across threads, which involves sharing a single browser process. This makes it not thread-safe unless proper synchronization mechanisms, such as locks, are used to serialize access. `Disabling ReuseBrowserProcess` allows true parallelism with isolated browser instances per thread. + You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/HTML%20to%20PDF/Blink/Optimize-HTML-to-PDF-performance). ## Temporary path @@ -2045,6 +2236,9 @@ The temporary path can be changed by using the [TempPath](https://help.syncfusio {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Set-temporary-path-while-converting-HTML-to-PDF/.NET/Set-temporary-path-while-converting-HTML-to-PDF/Program.cs, 300" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize the HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); @@ -2056,15 +2250,18 @@ htmlConverter.ConverterSettings = blinkConverterSettings; //Convert URL to PDF PdfDocument document = htmlConverter.Convert("https://www.google.com"); -FileStream fileStream = new FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite); + //Save and close the PDF document. -document.Save(fileStream); +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + 'Initialize the HTML to PDF converter. Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() @@ -2096,6 +2293,9 @@ N> * The BlinkBinaries also available in NuGet package installed location if you {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Set_blink_path_in_HTML_to_PDF/.NET/Set_blink_path_in_HTML_to_PDF/Program.cs, 300" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); @@ -2106,16 +2306,17 @@ htmlConverter.ConverterSettings = blinkConverterSettings; //Convert URL to PDF document. PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com"); -//Create file stream to save the PDF document. -FileStream fileStream = new FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite); //Save and close the PDF document. -document.Save(fileStream); +document.Save("Output.pdf"); document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + 'Initialize HTML to PDF converter. Dim htmlConverter As HtmlToPdfConverter = New HtmlToPdfConverter() Dim blinkConverterSettings As BlinkConverterSettings = New BlinkConverterSettings() @@ -2126,10 +2327,8 @@ htmlConverter.ConverterSettings = blinkConverterSettings 'Convert URL to PDF document. Dim document As PdfDocument = htmlConverter.Convert("https://www.syncfusion.com") -'Create file stream to save the PDF document. -Dim fileStream As FileStream = New FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite) 'Save and close the PDF document. -document.Save(fileStream) +document.Save("Output.pdf") document.Close(True) {% endhighlight %} @@ -2149,6 +2348,9 @@ Refer to the following code snippet to resize the page content size. {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/HTML-to-PDF-scale-property/.NET/Scale_property_in_HTML_converter/Program.cs, 300" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + //Initialize the HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Initialize the blink converter settings. @@ -2159,10 +2361,9 @@ blinkConverterSettings.Scale = 1.0f; htmlConverter.ConverterSettings = blinkConverterSettings; //Convert the URL to a PDF document. PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com"); -//Create a file stream. -FileStream fileStream = new FileStream("HTMLtoPDF.pdf", FileMode.Create, FileAccess.ReadWrite); -//Save a PDF document to a file stream. -document.Save(fileStream); + +//Save a PDF document +document.Save("Output.pdf"); //Close the document. document.Close(true); @@ -2170,6 +2371,9 @@ document.Close(true); {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + 'Initialize the HTML to PDF converter. Dim htmlConverter As New HtmlToPdfConverter() 'Initialize the blink converter settings. @@ -2180,7 +2384,7 @@ blinkConverterSettings.Scale = 1.0F htmlConverter.ConverterSettings = blinkConverterSettings 'Convert the URL to a PDF document. Dim document As PdfDocument = htmlConverter.Convert("https://www.syncfusion.com") -'Save a PDF document to a file stream. +'Save a PDF document document.Save("HTMLtoPDF.pdf") 'Close the document. document.Close(True) @@ -2201,48 +2405,49 @@ N> EnableAutoScaling and GetHtmlBounds cannot be used simultaneously in the HTM {% highlight c# tabtitle="C# [Cross-platform]" %} - // Initialize the HTML to PDF converter. - HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); - // Initialize BlinkConverterSettings to configure the Blink rendering engine. - BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; - // Enables automatic scaling to adjust the HTML content to fit the PDF's dimensions. - blinkConverterSettings.EnableAutoScaling = true; +// Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +// Initialize BlinkConverterSettings to configure the Blink rendering engine. +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); - // Assigns the Blink settings to the HTML to PDF converter. - htmlConverter.ConverterSettings = blinkConverterSettings; - // Converts the HTML file to a PDF document, using the path of the HTML file. - PdfDocument document = htmlConverter.Convert(Path.GetFullPath("../../../Input.html")); - // Save the generated PDF document to a specified output file. - using (FileStream fileStream = new FileStream("Output.pdf", FileMode.Create)) - { - document.Save(fileStream); - } - // Close the document. - document.Close(true); +// Enables automatic scaling to adjust the HTML content to fit the PDF's dimensions. +blinkConverterSettings.EnableAutoScaling = true; + +// Assigns the Blink settings to the HTML to PDF converter. +htmlConverter.ConverterSettings = blinkConverterSettings; +// Converts the HTML file to a PDF document, using the path of the HTML file. +PdfDocument document = htmlConverter.Convert(Path.GetFullPath("../../../Input.html")); +// Save the generated PDF document to a specified output file. +document.Save("Output.pdf"); +// Close the document. +document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} - ' Initialize the HTML to PDF converter. - Dim htmlConverter As New HtmlToPdfConverter() - ' Initialize BlinkConverterSettings to configure the Blink rendering engine. - Dim blinkConverterSettings As New BlinkConverterSettings() +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf - ' Enables automatic scaling to adjust the HTML content to fit the PDF's dimensions. - blinkConverterSettings.EnableAutoScaling = True +' Initialize the HTML to PDF converter. +Dim htmlConverter As New HtmlToPdfConverter() +' Initialize BlinkConverterSettings to configure the Blink rendering engine. +Dim blinkConverterSettings As New BlinkConverterSettings() - ' Assigns the Blink settings to the HTML to PDF converter. - htmlConverter.ConverterSettings = blinkConverterSettings - ' Converts the HTML file to a PDF document, using the path of the HTML file. - Dim document As PdfDocument = htmlConverter.Convert(Path.GetFullPath("../../../Input.html")) - ' Save the generated PDF document to a specified output file. - Using fileStream As New FileStream("Output.pdf", FileMode.Create) - document.Save(fileStream) - End Using - ' Close the document. - document.Close() +' Enables automatic scaling to adjust the HTML content to fit the PDF's dimensions. +blinkConverterSettings.EnableAutoScaling = True + +' Assigns the Blink settings to the HTML to PDF converter. +htmlConverter.ConverterSettings = blinkConverterSettings +' Converts the HTML file to a PDF document, using the path of the HTML file. +Dim document As PdfDocument = htmlConverter.Convert(Path.GetFullPath("../../../Input.html")) +' Save the generated PDF document to a specified output file. +document.Save("Output.pdf") +' Close the document. +document.Close(True) {% endhighlight %} @@ -2257,44 +2462,46 @@ Refer to the following code snippet to set the timeout for HTML to PDF conversio {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Time-out-support-in-HTML-to-PDF/.NET/Time-out-support-in-HTML-to-PDF/Program.cs, 300" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize the HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +//Initialize the blink converter settings. +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +// Set the conversion timeout to 5000 milliseconds +blinkConverterSettings.ConversionTimeout = 5000; +//Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = blinkConverterSettings; +//Convert URL to PDF +PdfDocument document = htmlConverter.Convert("https://www.google.com"); - //Initialize the HTML to PDF converter. - HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); - //Initialize the blink converter settings. - BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); - // Set the conversion timeout to 5000 milliseconds - blinkConverterSettings.ConversionTimeout = 5000; - //Assign Blink converter settings to HTML converter - htmlConverter.ConverterSettings = blinkConverterSettings; - //Convert URL to PDF - PdfDocument document = htmlConverter.Convert("https://www.google.com"); - //Create a file stream. - FileStream fileStream = new FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite); - //Save and close the PDF document. - document.Save(fileStream); - //Close the document. - document.Close(true); +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} - 'Initialize the HTML to PDF converter. - Dim htmlConverter As New HtmlToPdfConverter() - 'Initialize the blink converter settings. - Dim blinkConverterSettings As New BlinkConverterSettings() - 'Set the conversion timeout to 5000 milliseconds - blinkConverterSettings.ConversionTimeout = 5000 - 'Assign Blink converter settings to HTML converter - htmlConverter.ConverterSettings = blinkConverterSettings - 'Convert URL to PDF - Dim document As PdfDocument = htmlConverter.Convert("https://www.google.com") - 'Create a file stream. - Dim fileStream As New FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite) - 'Save and close the PDF document. - document.Save(fileStream) - 'Close the document. - document.Close(True) +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + +'Initialize the HTML to PDF converter. +Dim htmlConverter As New HtmlToPdfConverter() +'Initialize the blink converter settings. +Dim blinkConverterSettings As New BlinkConverterSettings() +'Set the conversion timeout to 5000 milliseconds +blinkConverterSettings.ConversionTimeout = 5000 +'Assign Blink converter settings to HTML converter +htmlConverter.ConverterSettings = blinkConverterSettings +'Convert URL to PDF +Dim document As PdfDocument = htmlConverter.Convert("https://www.google.com") + +'Save and close the PDF document. +document.Save("Output.pdf") +document.Close(True) {% endhighlight %} @@ -2310,6 +2517,9 @@ The [WaitForExternalFonts](https://help.syncfusion.com/cr/document-processing/Sy {% highlight c# tabtitle="C# [Cross-platform]" %} +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + // Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); // Initialize Blink converter settings @@ -2322,19 +2532,18 @@ htmlConverter.ConverterSettings = blinkConverterSettings; // Convert URL (or file path) to PDF PdfDocument document = htmlConverter.Convert(Path.GetFullPath("Input.html")); -// Create a FileStream to save the PDF document to a file -using (FileStream fileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.Write)) -{ - // Save the PDF document to the file stream - document.Save(fileStream); -} -// Close the document after saving +// Save the PDF document. +document.Save("Output.pdf"); +// Close the document. document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + ' Initialize HTML to PDF converter Dim htmlConverter As New HtmlToPdfConverter() ' Initialize Blink converter settings @@ -2347,13 +2556,10 @@ htmlConverter.ConverterSettings = blinkConverterSettings ' Convert URL (or file path) to PDF Dim document As PdfDocument = htmlConverter.Convert(Path.GetFullPath("Input.html")) -' Create a FileStream to save the PDF document to a file -Using fileStream As New FileStream("Output.pdf", FileMode.Create, FileAccess.Write) - ' Save the PDF document to the file stream - document.Save(fileStream) -End Using -' Close the document after saving -document.Close() +' Save the PDF document. +document.Save("Output.pdf") +' Close the document. +document.Close(True) {% endhighlight %} @@ -2367,41 +2573,45 @@ N> This support fully depends on the Chromium headless browser. Our converter pr {% tabs %} -{% highlight c# tabtitle="C# [Cross-platform]" %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Accessible_PDF_In_HTML_to_PDF/.NET/Accessible%20PDF/Program.cs, 300" %} - //Initialize HTML to PDF converter. - HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); - //Initialize the BlinkConverterSettings. - BlinkConverterSettings settings = new BlinkConverterSettings(); - //Set true to enable the accessibility tags in PDF generation. - settings.EnableAccessibilityTags= true; - //Assign the BlinkConverterSettings to the ConverterSettings property of HtmlToPdfConverter. - htmlConverter.ConverterSettings = settings; - //Convert URL to PDF. - PdfDocument document = htmlConverter.Convert("Input.html"); - //Save and close the PDF document. - FileStream fileStream = new FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite); - document.Save(fileStream); - document.Close(true); +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +//Initialize HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +//Initialize the BlinkConverterSettings. +BlinkConverterSettings settings = new BlinkConverterSettings(); +//Set true to enable the accessibility tags in PDF generation. +settings.EnableAccessibilityTags= true; +//Assign the BlinkConverterSettings to the ConverterSettings property of HtmlToPdfConverter. +htmlConverter.ConverterSettings = settings; +//Convert URL to PDF. +PdfDocument document = htmlConverter.Convert("Input.html"); +//Save and close the PDF document. +document.Save("Output.pdf"); +document.Close(true); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} - 'Initialize HTML to PDF converter. - Dim htmlConverter As New HtmlToPdfConverter() - 'Initialize the BlinkConverterSettings. - Dim settings As New BlinkConverterSettings() - 'Set true to enable the accessibility tags in PDF generation. - settings.EnableAccessibilityTags = True - 'Assign the BlinkConverterSettings to the ConverterSettings property of HtmlToPdfConverter. - htmlConverter.ConverterSettings = settings - 'Convert URL to PDF. - Dim document As PdfDocument = htmlConverter.Convert("Input.html") - 'Save and close the PDF document. - Dim fileStream As New FileStream("HTML-to-PDF.pdf", FileMode.CreateNew, FileAccess.ReadWrite) - document.Save(fileStream) - document.Close(True) +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + +'Initialize HTML to PDF converter. +Dim htmlConverter As New HtmlToPdfConverter() +'Initialize the BlinkConverterSettings. +Dim settings As New BlinkConverterSettings() +'Set true to enable the accessibility tags in PDF generation. +settings.EnableAccessibilityTags = True +'Assign the BlinkConverterSettings to the ConverterSettings property of HtmlToPdfConverter. +htmlConverter.ConverterSettings = settings +'Convert URL to PDF. +Dim document As PdfDocument = htmlConverter.Convert("Input.html") +'Save and close the PDF document. +document.Save("Output.pdf") +document.Close(True) {% endhighlight %} @@ -2418,37 +2628,41 @@ The Blink HTML converter support adding the image background from HTML to Image {% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Image_Background_In_HTML_to_PDF/.NET/Image_Background_In_HTML_to_PDF/Program.cs, 300" %} - //Initialize HTML to PDF converter. - HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); - //Initialize the BlinkConverterSettings. - BlinkConverterSettings settings = new BlinkConverterSettings(); - //Set the Image Background color. - settings.ImageBackgroundColor = Color.Transparent; - //Assign the BlinkConverterSettings to the ConverterSettings property of HtmlToPdfConverter. - htmlConverter.ConverterSettings = settings; - //Convert HTML to Image. - Image image = htmlConverter.ConvertToImage("Input.html"); - //Save the Image. - byte[] imageByte = image.ImageData; - File.WriteAllBytes("Output.png", imageByte); +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; + +//Initialize HTML to PDF converter. +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +//Initialize the BlinkConverterSettings. +BlinkConverterSettings settings = new BlinkConverterSettings(); +//Set the Image Background color. +settings.ImageBackgroundColor = Color.Transparent; +//Assign the BlinkConverterSettings to the ConverterSettings property of HtmlToPdfConverter. +htmlConverter.ConverterSettings = settings; +//Convert HTML to Image. +Image image = htmlConverter.ConvertToImage("Input.html"); +//Save the image. +File.WriteAllBytes(Path.GetFullPath(@"Output/Output.jpg"), image.ImageData); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} - ' Initialize HTML to PDF converter. - Dim htmlConverter As New HtmlToPdfConverter() - ' Initialize the BlinkConverterSettings. - Dim settings As New BlinkConverterSettings() - ' Set the Image Background color. - settings.ImageBackgroundColor = Color.Transparent - ' Assign the BlinkConverterSettings to the ConverterSettings property of HtmlToPdfConverter. - htmlConverter.ConverterSettings = settings - ' Convert HTML to Image. - Dim image As Image = htmlConverter.ConvertToImage("Input.html") - ' Save the Image. - Dim imageByte As Byte() = image.ImageData - File.WriteAllBytes("Output.png", imageByte) +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + +' Initialize HTML to PDF converter. +Dim htmlConverter As New HtmlToPdfConverter() +' Initialize the BlinkConverterSettings. +Dim settings As New BlinkConverterSettings() +' Set the Image Background color. +settings.ImageBackgroundColor = Color.Transparent +' Assign the BlinkConverterSettings to the ConverterSettings property of HtmlToPdfConverter. +htmlConverter.ConverterSettings = settings +' Convert HTML to Image. +Dim image As Image = htmlConverter.ConvertToImage("Input.html") +' Save the image. +File.WriteAllBytes(Path.GetFullPath(@"Output/Output.jpg"), image.ImageData) {% endhighlight %} @@ -2464,41 +2678,47 @@ N> EnableAutoScaling and GetHtmlBounds cannot be used simultaneously in the HTML {% tabs %} -{% highlight c# tabtitle="C# [Cross-platform]" %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Get-Bounds-in-HTML-file/.NET/Get-Bounds-in-HTML-file/Program.cs, 300" %} - // Initialize HTML to PDF converter - HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); - // Initialize Blink converter settings - BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; - // Set the crop region for the HTML conversion based on the bounds of the HTML file - blinkConverterSettings.CropRegion = htmlConverter.GetHtmlBounds(Path.GetFullPath("Input.html")); +// Initialize HTML to PDF converter +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); +// Initialize Blink converter settings +BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); - // Assign Blink converter settings to the HTML converter - htmlConverter.ConverterSettings = blinkConverterSettings; - // Convert the HTML file to an image - Image image = htmlConverter.ConvertToImage(Path.GetFullPath("Input.html")); - // Save the image as a PNG file - File.WriteAllBytes("Output.png", image.ImageData); +// Set the crop region for the HTML conversion based on the bounds of the HTML file +blinkConverterSettings.CropRegion = htmlConverter.GetHtmlBounds(Path.GetFullPath("Input.html")); + +// Assign Blink converter settings to the HTML converter +htmlConverter.ConverterSettings = blinkConverterSettings; +// Convert the HTML file to an image +Image image = htmlConverter.ConvertToImage(Path.GetFullPath("Input.html")); +//Save the image. +File.WriteAllBytes(Path.GetFullPath(@"Output/Output.jpg"), image.ImageData); {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} - ' Initialize HTML to PDF converter - Dim htmlConverter As New HtmlToPdfConverter() - ' Initialize Blink converter settings - Dim blinkConverterSettings As New BlinkConverterSettings() +Imports Syncfusion.HtmlConverter +Imports System.Pdf + +' Initialize HTML to PDF converter +Dim htmlConverter As New HtmlToPdfConverter() +' Initialize Blink converter settings +Dim blinkConverterSettings As New BlinkConverterSettings() - ' Set the crop region for the HTML conversion based on the bounds of the HTML file - blinkConverterSettings.CropRegion = htmlConverter.GetHtmlBounds(Path.GetFullPath("Input.html")) +' Set the crop region for the HTML conversion based on the bounds of the HTML file +blinkConverterSettings.CropRegion = htmlConverter.GetHtmlBounds(Path.GetFullPath("Input.html")) - ' Assign Blink converter settings to the HTML converter - htmlConverter.ConverterSettings = blinkConverterSettings - ' Convert the HTML file to an image - Dim image As Image = htmlConverter.ConvertToImage(Path.GetFullPath("Input.html")) - ' Save the image as a PNG file - File.WriteAllBytes("Output.png", image.ImageData) +' Assign Blink converter settings to the HTML converter +htmlConverter.ConverterSettings = blinkConverterSettings +' Convert the HTML file to an image +Dim image As Image = htmlConverter.ConvertToImage(Path.GetFullPath("Input.html")) +' Save the image +File.WriteAllBytes(Path.GetFullPath(@"Output/Output.jpg"), image.ImageData) {% endhighlight %} @@ -2514,7 +2734,11 @@ Refer to the following code sample to Disabling local file access. {% tabs %} -{% highlight c# tabtitle="C# [Cross-platform]" %} +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PDF-Examples/master/HTML%20to%20PDF/Blink/Disabling-local-file-access-HTML-to-PDF/.NET/Disabling-local-file-access-HTML-to-PDF/Program.cs, 300" %} + +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; // Initialize HTML to PDF converter with a using statement to ensure disposal using (HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter()) @@ -2522,7 +2746,7 @@ using (HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter()) // Initialize Blink converter settings BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); // Set Blink viewport size - blinkConverterSettings.ViewPortSize = new Syncfusion.Drawing.Size(1280, 0); + blinkConverterSettings.ViewPortSize = new Size(1280, 0); // Restricts external CSS and images in local HTML content blinkConverterSettings.EnableLocalFileAccess = false; @@ -2534,12 +2758,8 @@ using (HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter()) // Convert HTML to PDF document using (PdfDocument document = htmlConverter.Convert(html, "")) { - // Create a file stream with a using statement to ensure disposal - using (FileStream fileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite)) - { - // Save the PDF document to the file stream - document.Save(fileStream); - } + // Save the PDF document. + document.Save("Output.pdf"); } } @@ -2547,12 +2767,16 @@ using (HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter()) {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Imports System.Drawing +Imports Syncfusion.HtmlConverter +Imports Syncfusion.Pdf + ' Initialize HTML to PDF converter with a Using statement to ensure disposal Using htmlConverter As New HtmlToPdfConverter() ' Initialize Blink converter settings Dim blinkConverterSettings As New BlinkConverterSettings() ' Set Blink viewport size - blinkConverterSettings.ViewPortSize = New Syncfusion.Drawing.Size(1280, 0) + blinkConverterSettings.ViewPortSize = New Size(1280, 0) ' Restricts external CSS and images in local HTML content blinkConverterSettings.EnableLocalFileAccess = False @@ -2563,11 +2787,8 @@ Using htmlConverter As New HtmlToPdfConverter() Dim html As String = File.ReadAllText("sample.html") ' Convert HTML to PDF document Using document As PdfDocument = htmlConverter.Convert(html, "") - ' Create a file stream with a Using statement to ensure disposal - Using fileStream As New FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite) - ' Save the PDF document to the file stream - document.Save(fileStream) - End Using + ' Save the PDF document + document.Save("Output.pdf") End Using End Using @@ -2579,137 +2800,47 @@ You can download a complete working sample from [GitHub](https://github.com/Sync N> This property determines whether the Blink rendering engine can load local resources such as CSS files, JavaScript files, images, and fonts referenced in the HTML. By default, this property is set to true. -## Best Practices: CEF Rendering Engine +## Adding Digital Signatures to HTML-converted PDFs -You can utilize various features, such as Scale, Margin, AdditionalDelay, and more, in the CEF converter settings when performing HTML to PDF conversion with the CEF rendering engine. Initialize the rendering engine first and then configure the specific property values. This ensures that the property values are applied correctly and preserved in the resulting PDF document. +This section demonstrates implementing digital signatures in PDFs generated from HTML sources using [HtmlToPdfConverter](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.HtmlToPdfConverter.html) class. Digital signatures provide cryptographic proof of document authenticity and integrity. -To define the settings, please refer to the sample code example below: +The following code examples demonstrate how to convert HTML to PDF and programmatically add signature fields to the generated document. {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" %} -byte[] CreatePdfFromUrl(string url, CefConverterSettings settings) -{ - // Create an instance of the HTML to PDF converter - HtmlToPdfConverter pdfConverter = new HtmlToPdfConverter() - { - RenderingEngine = HtmlRenderingEngine.Cef, // Set the rendering engine to Cef - ConverterSettings = settings, // Apply the provided converter settings - }; +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; - // Convert the URL to a PDF document - using (PdfDocument document = pdfConverter.Convert(url)) - { - // Save the document to a memory stream - using (MemoryStream stream = new MemoryStream()) - { - document.Save(stream); // Save the converted document to the stream - stream.Position = 0; // Reset the stream position to the beginning - return stream.ToArray(); // Return the byte array of the PDF - } - } -} - -// Define the URL and settings -string url = "http://google.com"; +// Initialize the HTML to PDF converter using the Blink rendering engine +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); -// Create a PDF from the URL with custom settings -byte[] pdfBytes = CreatePdfFromUrl(url, new CefConverterSettings() +// Configure the converter to preserve form fields in the PDF +BlinkConverterSettings settings = new BlinkConverterSettings { - AdditionalDelay = 5000, // Wait time before conversion starts - ViewPortSize = new Syncfusion.Drawing.Size(1920, 1080), // Set the viewport size for the rendering - Orientation = PdfPageOrientation.Landscape, // Set the PDF orientation to Landscape - Scale = 0.7f, // Set the scale of the rendered content - EnableJavaScript = true, // Enable JavaScript execution - EnableHyperLink = false, // Disable hyperlinks in the PDF - HtmlEncoding = Encoding.UTF8 // Set the encoding for the HTML content -}); + EnableForm = true // Ensures form elements like ,