From f489cdf5487591f53903a4a48b610803f28ae507 Mon Sep 17 00:00:00 2001 From: Srihariharan Date: Mon, 22 Jan 2024 16:59:21 +0530 Subject: [PATCH 01/11] 867214 : add proper Imageinfo method in UG --- File-Formats/PDF/Working-with-Image-Extraction.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/File-Formats/PDF/Working-with-Image-Extraction.md b/File-Formats/PDF/Working-with-Image-Extraction.md index e78916fdd..b18271b19 100644 --- a/File-Formats/PDF/Working-with-Image-Extraction.md +++ b/File-Formats/PDF/Working-with-Image-Extraction.md @@ -79,7 +79,7 @@ PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); PdfPageBase pageBase = loadedDocument.Pages[0]; //Extracts all the images info from first page -PdfImageInfo[] imagesInfo= pageBase.GetImagesInfo(); +PdfImageInfo[] imagesInfo= pageBase.ExtractImages(); //Close the document loadedDocument.Close(true); @@ -107,7 +107,7 @@ Dim loadedDocument As New PdfLoadedDocument(fileName) Dim pageBase As PdfPageBase = loadedDocument.Pages(0) 'Extracts all the images info from first page -Dim imagesInfo As PdfImageInfo[] = pageBase.ImagesInfo +Dim imagesInfo As PdfImageInfo[] = pageBase.ExtractImages() 'Close the document loadedDocument.Close(True) From 8fae97c3b7cfd07925abe8e841e918f146a200c9 Mon Sep 17 00:00:00 2001 From: Srihariharan Date: Mon, 22 Jan 2024 17:59:41 +0530 Subject: [PATCH 02/11] 867214 : Remove unwanted changes --- File-Formats-toc.html | 5 ----- 1 file changed, 5 deletions(-) diff --git a/File-Formats-toc.html b/File-Formats-toc.html index 7c0342910..82d9d8b4e 100644 --- a/File-Formats-toc.html +++ b/File-Formats-toc.html @@ -1508,11 +1508,6 @@
  • AWS Lambda
  • -
  • Google Cloud Platform (GCP) - -
  • Chart to Image Conversion
  • From 2fa2f8ec5798a112f6a1a719ca67893d2714a51a Mon Sep 17 00:00:00 2001 From: Srihariharan Date: Tue, 23 Jan 2024 09:13:11 +0530 Subject: [PATCH 03/11] 867214 : Remove unwanted XlSlO changes. --- .../XlsIO/convert-excel-to-image-in-google-app-engine.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/File-Formats/XlsIO/convert-excel-to-image-in-google-app-engine.md b/File-Formats/XlsIO/convert-excel-to-image-in-google-app-engine.md index beed36636..36b98f908 100644 --- a/File-Formats/XlsIO/convert-excel-to-image-in-google-app-engine.md +++ b/File-Formats/XlsIO/convert-excel-to-image-in-google-app-engine.md @@ -89,8 +89,6 @@ Step 7: Add a new button in the Index.cshtml as shown below. } Html.EndForm(); } -{% endhighlight %} -{% endtabs %} Step 8: Add a new action method **ConvertExcelToImage** in HomeController.cs and include the below code snippet to **convert the Excel document to image** and download it. From 6b7e3128d768346f69037e731a44d9af642d643b Mon Sep 17 00:00:00 2001 From: KurmithaSF4004 Date: Mon, 29 Jan 2024 16:43:02 +0530 Subject: [PATCH 04/11] Highlight_tag_Issue_in_XlsIO --- File-Formats-toc.html | 5 +++++ .../XlsIO/convert-excel-to-image-in-google-app-engine.md | 2 ++ 2 files changed, 7 insertions(+) diff --git a/File-Formats-toc.html b/File-Formats-toc.html index 8cea0ee1b..e00709ec4 100644 --- a/File-Formats-toc.html +++ b/File-Formats-toc.html @@ -1508,6 +1508,11 @@
  • AWS Lambda
  • +
  • Google Cloud Platform (GCP) + +
  • Chart to Image Conversion
  • diff --git a/File-Formats/XlsIO/convert-excel-to-image-in-google-app-engine.md b/File-Formats/XlsIO/convert-excel-to-image-in-google-app-engine.md index 36b98f908..beed36636 100644 --- a/File-Formats/XlsIO/convert-excel-to-image-in-google-app-engine.md +++ b/File-Formats/XlsIO/convert-excel-to-image-in-google-app-engine.md @@ -89,6 +89,8 @@ Step 7: Add a new button in the Index.cshtml as shown below. } Html.EndForm(); } +{% endhighlight %} +{% endtabs %} Step 8: Add a new action method **ConvertExcelToImage** in HomeController.cs and include the below code snippet to **convert the Excel document to image** and download it. From 9bfae184ab8d0e561c55d7f1fd8b27250fa1008d Mon Sep 17 00:00:00 2001 From: "sneha.biju" Date: Tue, 30 Jan 2024 17:38:39 +0530 Subject: [PATCH 05/11] Added content for showing warning for unsupported element --- File-Formats/DocIO/word-to-pdf.md | 166 ++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/File-Formats/DocIO/word-to-pdf.md b/File-Formats/DocIO/word-to-pdf.md index 253c451ee..5dd446c13 100644 --- a/File-Formats/DocIO/word-to-pdf.md +++ b/File-Formats/DocIO/word-to-pdf.md @@ -2367,6 +2367,172 @@ In .NET Core and latest target, we have limitation in metafile. Refer {{'[here]( +## Show Warning for Unsupported Elements + +When converting a Word document to a PDF, the presence of unsupported elements in the input Word document can lead to preservation issues in the converted PDF. The .NET Word library (DocIO) contains [Warning](https://help.syncfusion.com/cr/file-formats/Syncfusion.DocToPDFConverter.DocToPDFConverterSettings.html#Syncfusion_DocToPDFConverter_DocToPDFConverterSettings_Warning) API, which helps to detect and handle these unsupported elements during the conversion process. This API holds the information of unsupported elements once found in the input Word document. + +Users can display warning messages for the unsupported elements using the [WarningType](https://help.syncfusion.com/cr/file-formats/Syncfusion.DocIO.DLS.WarningInfo.html#Syncfusion_DocIO_DLS_WarningInfo_WarningType) during Word to PDF conversion. Users can set a flag to stop the conversion process based on the warning. + +The following code demonstrates how to stop conversion if the input Word document has an unsupported element like SmartArt during Word to PDF conversion. + + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" %} +using (FileStream fileStream = new FileStream("Input.docx", FileMode.Open)) +{ + //Loads an existing Word document. + using (WordDocument wordDocument = new WordDocument(fileStream, Syncfusion.DocIO.FormatType.Automatic)) + { + //Creates an instance of DocIORenderer. + using (DocIORenderer renderer = new DocIORenderer()) + { + renderer.Settings.Warning = new DocumentWarning(); + //Converts Word document into a PDF document. + using (PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument)) + { + //If the IsCanceled boolean is enabled, the input document will contain an unsupported element. + if (renderer.IsCanceled) + { + Console.WriteLine("The execution stopped due to unsupported element."); + Console.ReadKey(); + } + else + { + //Saves the PDF file. + FileStream outputFile = new FileStream("Output.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite); + pdfDocument.Save(outputFile); + outputFile.Dispose(); + Console.WriteLine("Success"); + } + } + } + } +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +WordDocument wordDocument = new WordDocument("Input.docx"); +DocToPDFConverter converter = new DocToPDFConverter(); +converter.Settings.Warning = new DocumentWarning(); +PdfDocument pdfDocument = converter.ConvertToPDF(document); +//If the IsCanceled boolean is enabled, the input document will contain an unsupported element. +if (converter.IsCanceled) +{ + Console.WriteLine("The execution stopped due to unsupported element."); + Console.ReadKey(); +} +else +{ + //Saves the PDF file. + FileStream outputFile = new FileStream("Output.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite); + pdfDocument.Save(outputFile); + outputFile.Dispose(); + Console.WriteLine("Success"); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Dim wordDocument As New WordDocument("Input.docx") +Dim converter As New DocToPDFConverter() +converter.Settings.Warning = New DocumentWarning() +Dim pdfDocument As PdfDocument = converter.ConvertToPDF(document) + +' If the IsCanceled boolean is enabled, the input document will contain an unsupported element. +If converter.IsCanceled Then + Console.WriteLine("The execution stopped due to unsupported element.") + Console.ReadKey() +Else + ' Saves the PDF file. + Using outputFile As New FileStream("Output.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite) + pdfDocument.Save(outputFile) + Console.WriteLine("Success") + End Using +End If +{% endhighlight %} + +{% endtabs %} + +The following code demonstrates how to initialize the [Warning](https://help.syncfusion.com/cr/file-formats/Syncfusion.DocToPDFConverter.DocToPDFConverterSettings.html#Syncfusion_DocToPDFConverter_DocToPDFConverterSettings_Warning) API and display warning messages for all unsupported elements in the input document. Additionally, this code shows how to set a flag to stop Word to PDF conversion if an unsupported element is identified. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" %} +public class DocumentWarning : IWarning +{ + public bool ShowWarnings(List warningInfo) + { + bool isContinueConversion = true; + foreach (WarningInfo warning in warningInfo) + { + //Based on the WarningType enumeration, you can do your manipulation. + //Skip the Word to PDF conversion by setting the isContinueConversion value to false. + //To stop execution if the input document has a SmartArt. + if (warning.WarningType == WarningType.SmartArt) + isContinueConversion = false; + + //Warning messages for unsupported elements in the input document. + Console.WriteLine("The input document contains " + warning.WarningType + " unsupported element."); + } + return isContinueConversion; + } +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +public class DocumentWarning : IWarning +{ + public bool ShowWarnings(List warningInfo) + { + bool isContinueConversion = true; + foreach (WarningInfo warning in warningInfo) + { + //Based on the WarningType enumeration, you can do your manipulation. + //Skip the Word to PDF conversion by setting the isContinueConversion value to false. + //To stop execution if the input document has a SmartArt. + if (warning.WarningType == WarningType.SmartArt) + isContinueConversion = false; + + //Warning messages for unsupported elements in the input document. + Console.WriteLine("The input document contains " + warning.WarningType + " unsupported element."); + } + return isContinueConversion; + } +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Public Class DocumentWarning + Implements IWarning + + Public Function ShowWarnings(warningInfo As List(Of WarningInfo)) As Boolean Implements IWarning.ShowWarnings + Dim isContinueConversion As Boolean = True + + For Each warning As WarningInfo In warningInfo + ' Based on the WarningType enumeration, you can perform your manipulation. + ' Skip the Word to PDF conversion by setting the isContinueConversion value to false. + ' To stop execution if the input document has a SmartArt. + If warning.WarningType = WarningType.SmartArt Then + isContinueConversion = False + End If + + ' Warning messages for unsupported elements in the input document. + Console.WriteLine("The input document contains " & warning.WarningType & " unsupported element.") + Next + + Return isContinueConversion + End Function +End Class +{% endhighlight %} + +{% endtabs %} + +**Tips:** +Using the above Warning API, handle logic to identify the documents with unsupported elements and notify the end users to use supported elements for good preservation in the output PDF. + +You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Word-to-PDF-Conversion/Show-Warning-for-unsupported-elements) + + ## See Also * [How to perform font substitution in Word to PDF conversion](https://support.syncfusion.com/kb/article/7499/how-to-perform-font-substitution-in-word-to-pdf-conversion) From 8e48323d0e5d174de578d6f899cc7ebdd7696ae6 Mon Sep 17 00:00:00 2001 From: "sneha.biju" Date: Tue, 13 Feb 2024 16:55:59 +0530 Subject: [PATCH 06/11] ES_868758-Math Justification --- File-Formats/DocIO/Working-with-LaTeX.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/File-Formats/DocIO/Working-with-LaTeX.md b/File-Formats/DocIO/Working-with-LaTeX.md index a82c80f8a..52f071b97 100644 --- a/File-Formats/DocIO/Working-with-LaTeX.md +++ b/File-Formats/DocIO/Working-with-LaTeX.md @@ -1846,6 +1846,7 @@ The following code examples show how to apply the justification to equations in {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" %} +{% raw %} // Create a new Word document. using (WordDocument document = new WordDocument()) { @@ -1861,9 +1862,11 @@ using (WordDocument document = new WordDocument()) document.Save(outputFileStream, FormatType.Docx); } } +{% endraw %} {% endhighlight %} {% highlight c# tabtitle="C# [Windows-specific]" %} +{% raw %} //Create a new Word document. WordDocument document = new WordDocument(); //Add one section and one paragraph to the document. @@ -1874,9 +1877,11 @@ WMath math = document.LastParagraph.AppendMath(@"\boxed{{x}^{2}+{y}^{2}={z}^{2}} math.MathParagraph.Justification = MathJustification.Left; //Save Word document. document.Save("Output.docx", FormatType.Docx); +{% endraw %} {% endhighlight %} {% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +{% raw %} 'Create a new Word document. Dim document As New WordDocument() 'Add one section and one paragraph to the document. @@ -1887,6 +1892,7 @@ Dim math As WMath = document.LastParagraph.AppendMath("\boxed{{x}^{2}+{y}^{2}={z math.MathParagraph.Justification = MathJustification.Left 'Save Word document. document.Save("Output.docx", FormatType.Docx) +{% endraw %} {% endhighlight %} {% endtabs %} From e1feab9a2e6f1c6816f11f3b823926862981d1f2 Mon Sep 17 00:00:00 2001 From: Srihariharan Date: Wed, 13 Mar 2024 16:43:57 +0530 Subject: [PATCH 07/11] 876039: Resolve UG Documentation staging error. --- .../PDF/Working-with-OCR/Troubleshooting.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/File-Formats/PDF/Working-with-OCR/Troubleshooting.md b/File-Formats/PDF/Working-with-OCR/Troubleshooting.md index 98c7f884e..dde43980f 100644 --- a/File-Formats/PDF/Working-with-OCR/Troubleshooting.md +++ b/File-Formats/PDF/Working-with-OCR/Troubleshooting.md @@ -25,7 +25,7 @@ keywords: Assemblies Set proper tesseract binaries and tessdata folder with all files and inner folders. The tessdata folder name is case-sensitive and should not change.

    -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} //TesseractBinaries - path of the folder tesseract binaries. OCRProcessor processor = new OCRProcessor(@"TesseractBinaries/"); @@ -180,7 +180,7 @@ By using the best tessdata, we can improve the OCR results. For more information

    1.Execute the following command to install Tesserat 5.

    -{% highlight c# tabtitle="C#" %} +{% highlight %} brew install tesseract @@ -189,7 +189,7 @@ brew install tesseract

    If the "brew" is not installed on your machine, you can install it using the following command.

    -{% highlight c# tabtitle="C#" %} +{% highlight %} /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" @@ -199,7 +199,7 @@ If the "brew" is not installed on your machine, you can install it using the fol 2.Once Tesseract 5 is successfully installed, you can configure the path to the latest binaries by copying the location of the Tesseract folder and setting it as the Tesseract binaries path when setting up the OCR processor. Refer to the example code below:

    -{% highlight c# tabtitle="C#" %} +{% highlight %} //Initialize the OCR processor by providing the path of tesseract binaries. using (OCRProcessor processor = new OCRProcessor("/opt/homebrew/Cellar/tesseract/5.3.2/lib")) @@ -209,7 +209,7 @@ using (OCRProcessor processor = new OCRProcessor("/opt/homebrew/Cellar/tesseract 3.Add the TessDataPath from bin folder. Refer to the example code below:

    -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} using (OCRProcessor processor = new OCRProcessor("/opt/homebrew/Cellar/tesseract/5.3.2/lib")) { @@ -253,7 +253,7 @@ using (OCRProcessor processor = new OCRProcessor("/opt/homebrew/Cellar/tesseract

    1. Install the leptonica.
    -{% highlight c# tabtitle="C#" %} +{% highlight %} sudo apt-get install libleptonica-dev @@ -264,7 +264,7 @@ sudo apt-get install libleptonica-dev 2.Install the tesseract.
    -{% highlight c# tabtitle="C#" %} +{% highlight %} sudo apt-get install tesseract-ocr-eng @@ -280,7 +280,7 @@ cp /usr/lib/x86_64-linux-gnu/liblept.so /home/syncfusion/linuxdockersample/linux {% endhighlight %}
    -{% highlight c# tabtitle="C#" %} +{% highlight %} cp /usr/lib/x86_64-linux-gnu/libtesseract.so.4 /home/syncfusion/linuxdockersample/linuxdockersample/bin/Debug/net7.0/libSyncfusionTesseract.so From ff7ed7833a1c9462261db54c9eb485498ac2c272 Mon Sep 17 00:00:00 2001 From: Srihariharan Date: Thu, 14 Mar 2024 11:42:01 +0530 Subject: [PATCH 08/11] 876039: Resolve UG Documentation staging error. --- .../Convert-HTML-To-PDF/troubleshooting.md | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/File-Formats/PDF/Convert-HTML-To-PDF/troubleshooting.md b/File-Formats/PDF/Convert-HTML-To-PDF/troubleshooting.md index 89c10b9a1..a6476bcee 100644 --- a/File-Formats/PDF/Convert-HTML-To-PDF/troubleshooting.md +++ b/File-Formats/PDF/Convert-HTML-To-PDF/troubleshooting.md @@ -34,7 +34,7 @@ You can set the runtimes folder path explicitly in BlinkPath property in BlinkCo

    Ex path: C:\HtmlConversion\HTMl-to-PDF\HTMl-to-PDF\bin\Debug\net7.0\runtimes\win-x64\native\

    -{% highlight html %} +{% highlight c# tabtitle="C# [Cross-platform]" %} //Initialize the HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); @@ -137,7 +137,7 @@ Also, please add the following command line arguments in our converter setting. @@ -137,13 +139,15 @@ Also, please add the following command line arguments in our converter setting.
    -{% highlight c# tabtitle="C#" %} +{% highlight %} //Set command line arguments to run without sandbox. blinkConverterSettings.CommandLineArguments.Add("--no-sandbox"); @@ -247,7 +247,7 @@ blinkConverterSettings.CommandLineArguments.Add("--disable-setuid-sandbox"); To overcome the exception, you can add read, write, and execute permissions for the temporary folder. Refer to the following code sample to set the temp folder.

    -{% highlight c# tabtitle="C#" %} +{% highlight %} BlinkConverterSettings settings = new BlinkConverterSettings(); settings.TempPath = "D://MyProject//bin"; @@ -330,7 +330,7 @@ Check the HTML file or URL is rendered properly in Chrome browser's print previe

    ExcludeAssets

    -{% highlight c# tabtitle="C#" %} +{% highlight %} COPY . /app WORKDIR /app @@ -362,7 +362,7 @@ RUN chmod +x /app/runtimes/linux/native/chrome && \
    To overcome this issue, add suitable delay for the conversion using the AdditionalDelay property of the HTMLConverter.

    -{% highlight c# tabtitle="C#" %} +{% highlight %} BlinkConverterSettings settings = new BlinkConverterSettings(); settings.AdditionalDelay = 4000; @@ -431,7 +431,7 @@ Refer to this
    We can resolve this permission related failure in the Blink rendering engine using below command line arguments in our converter settings.

    -{% highlight c# tabtitle="C#" %} +{% highlight %} //Set command line arguments to run without sandbox. blinkConverterSettings.CommandLineArguments.Add("--no-sandbox"); @@ -591,7 +591,7 @@ To resolve this issue, we can install the chromium using the docker file and set Docker File:

    {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight %} FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base @@ -617,7 +617,7 @@ Docker File:

    Code snippet: -{% highlight c# tabtitle="C#" %} +{% highlight %} BlinkConverterSettings settings = new BlinkConverterSettings(); @@ -657,7 +657,7 @@ To resolve this issue, we can add inline styles in element. However, we have att {% tabs %} -{% highlight c# tabtitle="C#" %} +{% highlight c# tabtitle="C# [Cross-platform]" %} HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Initialize blink converter settings. From eba5c9090fcaf58e832e12268bcf45904cd32fe1 Mon Sep 17 00:00:00 2001 From: Srihariharan Date: Thu, 14 Mar 2024 15:41:29 +0530 Subject: [PATCH 09/11] 876039: Resolve UG Documentation staging error. --- .../Convert-HTML-To-PDF/troubleshooting.md | 39 ++++++++---- .../PDF/Working-with-OCR/Troubleshooting.md | 63 ++++++++++++------- 2 files changed, 67 insertions(+), 35 deletions(-) diff --git a/File-Formats/PDF/Convert-HTML-To-PDF/troubleshooting.md b/File-Formats/PDF/Convert-HTML-To-PDF/troubleshooting.md index a6476bcee..fd2bcbfeb 100644 --- a/File-Formats/PDF/Convert-HTML-To-PDF/troubleshooting.md +++ b/File-Formats/PDF/Convert-HTML-To-PDF/troubleshooting.md @@ -34,7 +34,8 @@ You can set the runtimes folder path explicitly in BlinkPath property in BlinkCo

    Ex path: C:\HtmlConversion\HTMl-to-PDF\HTMl-to-PDF\bin\Debug\net7.0\runtimes\win-x64\native\

    -{% highlight c# tabtitle="C# [Cross-platform]" %} +{% tabs %} +{% highlight C# %} //Initialize the HTML to PDF converter. HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); @@ -52,6 +53,7 @@ document.Save(fileStream); document.Close(true); {% endhighlight %} +{% endtabs %}
    -{% highlight %} +{% tabs %} +{% highlight C# tabtitle="C#" %} //Set command line arguments to run without sandbox. blinkConverterSettings.CommandLineArguments.Add("--no-sandbox"); blinkConverterSettings.CommandLineArguments.Add("--disable-setuid-sandbox"); {% endhighlight %} +{% endtabs %}
    @@ -247,12 +251,14 @@ blinkConverterSettings.CommandLineArguments.Add("--disable-setuid-sandbox"); To overcome the exception, you can add read, write, and execute permissions for the temporary folder. Refer to the following code sample to set the temp folder.

    -{% highlight %} +{% tabs %} +{% highlight C# tabtitle="C#" %} BlinkConverterSettings settings = new BlinkConverterSettings(); settings.TempPath = "D://MyProject//bin"; {% endhighlight %} +{% endtabs %} @@ -330,7 +336,8 @@ Check the HTML file or URL is rendered properly in Chrome browser's print previe

    ExcludeAssets

    -{% highlight %} +{% tabs %} +{% highlight C# tabtitle="C#" %} COPY . /app WORKDIR /app @@ -339,6 +346,7 @@ RUN chmod +x /app/runtimes/linux/native/chrome && \ chmod +x /app/runtimes/linux/native/chrome-wrapper {% endhighlight %} +{% endtabs %} @@ -362,12 +370,14 @@ RUN chmod +x /app/runtimes/linux/native/chrome && \ To overcome this issue, add suitable delay for the conversion using the AdditionalDelay property of the HTMLConverter.

    -{% highlight %} +{% tabs %} +{% highlight C# tabtitle="C#" %} BlinkConverterSettings settings = new BlinkConverterSettings(); settings.AdditionalDelay = 4000; {% endhighlight %} +{% endtabs %} @@ -431,12 +441,14 @@ Refer to this @@ -461,13 +473,15 @@ settings.CommandLineArguments.Add("--ignore-certificate-errors"); We can resolve this permission related failure in the Blink rendering engine using below command line arguments in our converter settings.

    -{% highlight %} +{% tabs %} +{% highlight C# tabtitle="C#" %} //Set command line arguments to run without sandbox. blinkConverterSettings.CommandLineArguments.Add("--no-sandbox"); blinkConverterSettings.CommandLineArguments.Add("--disable-setuid-sandbox"); {% endhighlight %} +{% endtabs %} @@ -591,7 +605,7 @@ To resolve this issue, we can install the chromium using the docker file and set Docker File:

    {% tabs %} -{% highlight %} +{% highlight C# tabtitle="C#" %} FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base @@ -615,9 +629,12 @@ Docker File:

    {% endhighlight %} +{% endtabs %} + Code snippet: +{% tabs %} -{% highlight %} +{% highlight C# tabtitle="C#" %} BlinkConverterSettings settings = new BlinkConverterSettings(); @@ -657,7 +674,7 @@ To resolve this issue, we can add inline styles in element. However, we have att {% tabs %} -{% highlight c# tabtitle="C# [Cross-platform]" %} +{% highlight C# tabtitle="C#" %} HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); //Initialize blink converter settings. @@ -698,7 +715,7 @@ You can downloaded a complete working sample from [GitHub](https://github.com/Sy {% tabs %} -{% highlight %} +{% highlight C# %} //Set command line arguments to run without the sandbox. diff --git a/File-Formats/PDF/Working-with-OCR/Troubleshooting.md b/File-Formats/PDF/Working-with-OCR/Troubleshooting.md index dde43980f..3fad7b8a1 100644 --- a/File-Formats/PDF/Working-with-OCR/Troubleshooting.md +++ b/File-Formats/PDF/Working-with-OCR/Troubleshooting.md @@ -25,7 +25,8 @@ keywords: Assemblies Set proper tesseract binaries and tessdata folder with all files and inner folders. The tessdata folder name is case-sensitive and should not change.

    -{% highlight c# tabtitle="C# [Cross-platform]" %} +{% tabs %} +{% highlight C# tabtitle="C# [Cross-platform]" %} //TesseractBinaries - path of the folder tesseract binaries. OCRProcessor processor = new OCRProcessor(@"TesseractBinaries/"); @@ -34,6 +35,7 @@ OCRProcessor processor = new OCRProcessor(@"TesseractBinaries/"); processor.PerformOCR(lDoc, @"TessData/"); {% endhighlight %} +{% endtabs %} @@ -180,36 +182,41 @@ By using the best tessdata, we can improve the OCR results. For more information

    1.Execute the following command to install Tesserat 5.

    -{% highlight %} +{% tabs %} +{% highlight C# %} brew install tesseract {% endhighlight %} - +{% endtabs %}

    If the "brew" is not installed on your machine, you can install it using the following command.

    -{% highlight %} +{% tabs %} +{% highlight C# %} /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" {% endhighlight %} - +{% endtabs %}

    2.Once Tesseract 5 is successfully installed, you can configure the path to the latest binaries by copying the location of the Tesseract folder and setting it as the Tesseract binaries path when setting up the OCR processor. Refer to the example code below:

    -{% highlight %} +{% tabs %} +{% highlight C# %} //Initialize the OCR processor by providing the path of tesseract binaries. using (OCRProcessor processor = new OCRProcessor("/opt/homebrew/Cellar/tesseract/5.3.2/lib")) {% endhighlight %} +{% endtabs %}

    3.Add the TessDataPath from bin folder. Refer to the example code below:

    -{% highlight c# tabtitle="C# [Cross-platform]" %} +{% tabs %} +{% highlight C# tabtitle="C# [Cross-platform]" %} using (OCRProcessor processor = new OCRProcessor("/opt/homebrew/Cellar/tesseract/5.3.2/lib")) { @@ -232,6 +239,7 @@ using (OCRProcessor processor = new OCRProcessor("/opt/homebrew/Cellar/tesseract } {% endhighlight %} +{% endtabs %} @@ -253,38 +261,45 @@ using (OCRProcessor processor = new OCRProcessor("/opt/homebrew/Cellar/tesseract

    1. Install the leptonica.
    -{% highlight %} +{% tabs %} +{% highlight C# %} sudo apt-get install libleptonica-dev {% endhighlight %} +{% endtabs %}



    2.Install the tesseract.
    - -{% highlight %} +{% tabs %} +{% highlight C# %} sudo apt-get install tesseract-ocr-eng {% endhighlight %} +{% endtabs %}



    3. Copy the binaries (liblept.so and libtesseract.so) to the missing files exception folder in the project location.
    -{% highlight c# tabtitle="C#" %} +{% tabs %} +{% highlight C# %} cp /usr/lib/x86_64-linux-gnu/liblept.so /home/syncfusion/linuxdockersample/linuxdockersample/bin/Debug/net7.0/liblept1753.so {% endhighlight %} +{% endtabs %}
    -{% highlight %} +{% tabs %} +{% highlight C# %} cp /usr/lib/x86_64-linux-gnu/libtesseract.so.4 /home/syncfusion/linuxdockersample/linuxdockersample/bin/Debug/net7.0/libSyncfusionTesseract.so {% endhighlight %} +{% endtabs %}
    @@ -308,39 +323,39 @@ cp /usr/lib/x86_64-linux-gnu/libtesseract.so.4 /home/syncfusion/linuxdockersampl To resolve this problem, you should install all required dependencies in your Linux machine. Refer to the following steps to installing the missing dependencies. Step 1: Execute the following command in terminal window to check dependencies are installed properly. - -{% highlight %} +{% tabs %} +{% highlight C# %} ldd liblept1753.so ldd libSyncfusionTesseract.so {% endhighlight %} - +{% endtabs %} Run the following commands in terminal Step 1: - -{% highlight %} +{% tabs %} +{% highlight C# %} sudo apt-get install libleptonica-dev libjpeg62 {% endhighlight %} - +{% endtabs %} Step 2: - -{% highlight %} +{% tabs %} +{% highlight C# %} ln -s /usr/lib/x86_64-linux-gnu/libtiff.so.6 /usr/lib/x86_64-linux-gnu/libtiff.so.5 {% endhighlight %} - +{% endtabs %} Step 3: - -{% highlight %} +{% tabs %} +{% highlight C# %} ln -s /lib/x86_64-linux-gnu/libdl.so.2 /usr/lib/x86_64-linux-gnu/libdl.so {% endhighlight %} - +{% endtabs %} \ No newline at end of file From 5ffd8d028e0c98127a7fc429a9b9e7c48a74a5bb Mon Sep 17 00:00:00 2001 From: Srihariharan Date: Fri, 15 Mar 2024 10:11:35 +0530 Subject: [PATCH 10/11] 876039: Resolve UG Documentation staging error. --- ...-AWS-Lambda-with-NET-6-container-image.md} | 368 +++++++++--------- 1 file changed, 184 insertions(+), 184 deletions(-) rename File-Formats/PDF/Convert-HTML-To-PDF/{Convert-HTML-to-PDF-in-AWS-Lambda-with-NET 6-container-image.md => Convert-HTML-to-PDF-in-AWS-Lambda-with-NET-6-container-image.md} (97%) diff --git a/File-Formats/PDF/Convert-HTML-To-PDF/Convert-HTML-to-PDF-in-AWS-Lambda-with-NET 6-container-image.md b/File-Formats/PDF/Convert-HTML-To-PDF/Convert-HTML-to-PDF-in-AWS-Lambda-with-NET-6-container-image.md similarity index 97% rename from File-Formats/PDF/Convert-HTML-To-PDF/Convert-HTML-to-PDF-in-AWS-Lambda-with-NET 6-container-image.md rename to File-Formats/PDF/Convert-HTML-To-PDF/Convert-HTML-to-PDF-in-AWS-Lambda-with-NET-6-container-image.md index d9ce2b1a5..31ff553d1 100644 --- a/File-Formats/PDF/Convert-HTML-To-PDF/Convert-HTML-to-PDF-in-AWS-Lambda-with-NET 6-container-image.md +++ b/File-Formats/PDF/Convert-HTML-To-PDF/Convert-HTML-to-PDF-in-AWS-Lambda-with-NET-6-container-image.md @@ -1,184 +1,184 @@ ---- -title: Convert HTML to PDF in AWS Lambda with NET 6 container image | Syncfusion -description: Convert HTML to PDF in AWS Lambda with NET 6 container image using Syncfusion .NET HTML converter library. -platform: file-formats -control: PDF -documentation: UG ---- - -# Convert HTML to PDF file in AWS Lambda with NET 6 container image - -The Syncfusion [HTML to PDF converter](https://www.syncfusion.com/pdf-framework/net/html-to-pdf) is a .NET library for converting webpages, SVG, MHTML, and HTML to PDF using C#. Using this library, **convert HTML to PDF document in AWS Lambda with NET 6 container image**. - -## Steps to convert HTML to PDF in AWS Lambda with NET 6 container image - -Step 1: Create a new AWS Lambda project with Tests as follows. -![Convert HTMLToPDF AWS Lambda Step1](htmlconversion_images/awslambda1.png) - -Step 2: In configuration window, name the project and select Create. -![Convert HTMLToPDF AWS Lambda Step2](htmlconversion_images/awslambda2.png) - -Step 3: Select Blueprint as .NET 6 (Container Image) Function and click Finish. -![Convert HTMLToPDF AWS Lambda Step3](htmlconversion_images/awslambda3.png) - -Step 4: Install the [Syncfusion.HtmlToPdfConverter.Net.Aws](https://www.nuget.org/packages/Syncfusion.HtmlToPdfConverter.Net.Aws/) and [AWSSDK.Lambda](https://www.nuget.org/packages/AWSSDK.Lambda) NuGet package as a reference to your AWS lambda project from [NuGet.org](https://www.nuget.org/). -![NuGet package installation](htmlconversion_images/awslambda4.png) - -N> Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, you also have to add "Syncfusion.Licensing" assembly reference and include a license key in your projects. Please refer to this [link](https://help.syncfusion.com/common/essential-studio/licensing/overview) to know about registering Syncfusion license key in your application to use our components. - -Step 5: Using the following namespaces in the Function.cs file. - -{% highlight c# tabtitle="C#" %} - -using Syncfusion.HtmlConverter; -using Syncfusion.Pdf; -using System.IO; - -{% endhighlight %} - -Step 6: Add the following code sample in the Function.cs to convert HTML to PDF document using [Convert](https://help.syncfusion.com/cr/file-formats/Syncfusion.HtmlConverter.HtmlToPdfConverter.html#Syncfusion_HtmlConverter_HtmlToPdfConverter_Convert_System_String_) method in [HtmlToPdfConverter](https://help.syncfusion.com/cr/file-formats/Syncfusion.HtmlConverter.HtmlToPdfConverter.html) class. The Blink command line arguments based on the given [CommandLineArguments](https://help.syncfusion.com/cr/file-formats/Syncfusion.HtmlConverter.BlinkConverterSettings.html#Syncfusion_HtmlConverter_BlinkConverterSettings_CommandLineArguments) property of [BlinkConverterSettings](https://help.syncfusion.com/cr/file-formats/Syncfusion.HtmlConverter.BlinkConverterSettings.html) class. - -{% highlight c# tabtitle="C#" %} - -public string FunctionHandler(string input, ILambdaContext context) -{ - //Initialize HTML to a PDF converter with the Blink rendering engine. - HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink); - - BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); - blinkConverterSettings.BlinkPath = Path.GetFullPath("BlinkBinariesAws"); - blinkConverterSettings.CommandLineArguments.Add("--no-sandbox"); - blinkConverterSettings.CommandLineArguments.Add("--disable-setuid-sandbox"); - blinkConverterSettings.AdditionalDelay = 3000; - htmlConverter.ConverterSettings = blinkConverterSettings; - - //Convert the HTML string to PDF. - PdfDocument document = htmlConverter.Convert(input, PathToFile()); - - //Save the document into a stream. - MemoryStream memoryStream = new MemoryStream(); - //Save and close the PDFDocument. - document.Save(memoryStream); - document.Close(true); - string base64 = Convert.ToBase64String(memoryStream.ToArray()); - memoryStream.Close(); - memoryStream.Dispose(); - - return base64; -} - -public static string PathToFile() -{ - string? path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); - if (string.IsNullOrEmpty(path)) - { - path = Environment.OSVersion.Platform == PlatformID.Unix ? @"/" : @"\"; - } - return Environment.OSVersion.Platform == PlatformID.Unix ? string.Concat(path.Substring(5), @"/") : string.Concat(path.Substring(6), @"\"); -} - -{% endhighlight %} - -Step 7: Create a new folder as Helper and add a class file as AWSHelper.cs. Add the following namespaces and code samples in the AWSHelper class to invoke the published AWS Lambda function using the function name and access keys. - -{% highlight c# tabtitle="C#" %} - -Using Amazon.Lambda; -using Amazon.Lambda.Model; -using Newtonsoft.Json; - -public class AWSHelper -{ - public static async Task RunLambdaFunction(string html) - { - try - { - var AwsAccessKeyId = "awsaccessKeyID"; - var AwsSecretAccessKey = "awsSecretAccessKey"; - - AmazonLambdaClient client = new AmazonLambdaClient(AwsAccessKeyId, AwsSecretAccessKey, Amazon.RegionEndpoint.USEast1); - InvokeRequest invoke = new InvokeRequest - { - FunctionName = "AWSLambdaDockerContainer", - InvocationType = InvocationType.RequestResponse, - Payload = Newtonsoft.Json.JsonConvert.SerializeObject(html) - }; - //Get the InvokeResponse from the client InvokeRequest. - InvokeResponse response = await client.InvokeAsync(invoke); - - //Read the response stream. - Console.WriteLine($"Response: {response.LogResult}"); - Console.WriteLine($"Response: {response.StatusCode}"); - Console.WriteLine($"Response: {response.FunctionError}"); - var stream = new StreamReader(response.Payload); - JsonReader reader = new JsonTextReader(stream); - var serilizer = new JsonSerializer(); - var responseText = serilizer.Deserialize(reader); - - //Convert Base64String into a PDF document. - return Convert.FromBase64String(responseText.ToString()); - } - catch (Exception ex) - { - Console.WriteLine($"Exception Occured HTMLToPDFHelper: {ex}"); - } - return Convert.FromBase64String(""); - } -} - -{% endhighlight %} - -Step 8: Right-click the project and select **Publish to AWS Lambda**. - -![Convert HTMLToPDF AWS Lambda Step5](htmlconversion_images/awslambda5.png) - -Step 9: Create a new AWS profile in the Upload Lambda Function Window. After creating the profile, add a name for the Lambda function to publish. Then, click **Next**. - -![Convert HTMLToPDF AWS Lambda Step6](htmlconversion_images/awslambda6.png) - -Step 10: In the Advanced Function Details window, specify the **Role Name** as based on AWS Managed policy. After selecting the role, click the Upload button to deploy your application. - -![Convert HTMLToPDF AWS Lambda Step7](htmlconversion_images/awslambda7.png) -![Convert HTMLToPDF AWS Lambda Step8](htmlconversion_images/awslambda8.png) - -Step 11: After deploying the application, Sign in to your AWS account, and you can see the published Lambda function in the AWS console. - -![Convert HTMLToPDF AWS Lambda Step9](htmlconversion_images/awslambda9.png) - -## Steps to invoke the AWS Lambda function from the Test application - -Step 12: Add the following code to invoke the AWS lambda function with the HTML string from the Function Test. - -{% highlight c# tabtitle="C#" %} - -public class FunctionTest -{ - [Fact] - public void HtmlToPDFFunction() - { - string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); - string filePath = Environment.OSVersion.Platform == PlatformID.Unix ? string.Concat(path.Substring(5), @"/") : string.Concat(path.Substring(6), @"\"); - - var html = File.ReadAllText($"{filePath}/HtmlSample.html"); - byte[] base64 = null; - base64 = AWSHelper.RunLambdaFunction(html).Result; - - FileStream file = new FileStream($"{filePath}/file{DateTime.Now.Ticks}.pdf", FileMode.Create, FileAccess.Write); - var ms = new MemoryStream(base64); - ms.WriteTo(file); - file.Close(); - ms.Close(); - } -} - -{% endhighlight %} - -Step 13: Right click the test application and select **Run Tests**. - -![Convert HTMLToPDF AWS Lambda Step10](htmlconversion_images/awslambda10.png) - -Step 14: By executing the program, you will get the PDF document as follows. - -![Convert HTMLToPDF AWS Lambda Step11](htmlconversion_images/awslambda11.png) - -A complete working sample can be downloaded from [Github](https://github.com/SyncfusionExamples/html-to-pdf-csharp-examples/tree/master/AWS/HTML_to_PDF_Lambda_Docker_Container). +--- +title: Convert HTML to PDF in AWS Lambda with NET 6 container image | Syncfusion +description: Convert HTML to PDF in AWS Lambda with NET 6 container image using Syncfusion .NET HTML converter library. +platform: file-formats +control: PDF +documentation: UG +--- + +# Convert HTML to PDF file in AWS Lambda with NET 6 container image + +The Syncfusion [HTML to PDF converter](https://www.syncfusion.com/pdf-framework/net/html-to-pdf) is a .NET library for converting webpages, SVG, MHTML, and HTML to PDF using C#. Using this library, **convert HTML to PDF document in AWS Lambda with NET 6 container image**. + +## Steps to convert HTML to PDF in AWS Lambda with NET 6 container image + +Step 1: Create a new AWS Lambda project with Tests as follows. +![Convert HTMLToPDF AWS Lambda Step1](htmlconversion_images/awslambda1.png) + +Step 2: In configuration window, name the project and select Create. +![Convert HTMLToPDF AWS Lambda Step2](htmlconversion_images/awslambda2.png) + +Step 3: Select Blueprint as .NET 6 (Container Image) Function and click Finish. +![Convert HTMLToPDF AWS Lambda Step3](htmlconversion_images/awslambda3.png) + +Step 4: Install the [Syncfusion.HtmlToPdfConverter.Net.Aws](https://www.nuget.org/packages/Syncfusion.HtmlToPdfConverter.Net.Aws/) and [AWSSDK.Lambda](https://www.nuget.org/packages/AWSSDK.Lambda) NuGet package as a reference to your AWS lambda project from [NuGet.org](https://www.nuget.org/). +![NuGet package installation](htmlconversion_images/awslambda4.png) + +N> Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, you also have to add "Syncfusion.Licensing" assembly reference and include a license key in your projects. Please refer to this [link](https://help.syncfusion.com/common/essential-studio/licensing/overview) to know about registering Syncfusion license key in your application to use our components. + +Step 5: Using the following namespaces in the Function.cs file. + +{% highlight c# tabtitle="C#" %} + +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; +using System.IO; + +{% endhighlight %} + +Step 6: Add the following code sample in the Function.cs to convert HTML to PDF document using [Convert](https://help.syncfusion.com/cr/file-formats/Syncfusion.HtmlConverter.HtmlToPdfConverter.html#Syncfusion_HtmlConverter_HtmlToPdfConverter_Convert_System_String_) method in [HtmlToPdfConverter](https://help.syncfusion.com/cr/file-formats/Syncfusion.HtmlConverter.HtmlToPdfConverter.html) class. The Blink command line arguments based on the given [CommandLineArguments](https://help.syncfusion.com/cr/file-formats/Syncfusion.HtmlConverter.BlinkConverterSettings.html#Syncfusion_HtmlConverter_BlinkConverterSettings_CommandLineArguments) property of [BlinkConverterSettings](https://help.syncfusion.com/cr/file-formats/Syncfusion.HtmlConverter.BlinkConverterSettings.html) class. + +{% highlight c# tabtitle="C#" %} + +public string FunctionHandler(string input, ILambdaContext context) +{ + //Initialize HTML to a PDF converter with the Blink rendering engine. + HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink); + + BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); + blinkConverterSettings.BlinkPath = Path.GetFullPath("BlinkBinariesAws"); + blinkConverterSettings.CommandLineArguments.Add("--no-sandbox"); + blinkConverterSettings.CommandLineArguments.Add("--disable-setuid-sandbox"); + blinkConverterSettings.AdditionalDelay = 3000; + htmlConverter.ConverterSettings = blinkConverterSettings; + + //Convert the HTML string to PDF. + PdfDocument document = htmlConverter.Convert(input, PathToFile()); + + //Save the document into a stream. + MemoryStream memoryStream = new MemoryStream(); + //Save and close the PDFDocument. + document.Save(memoryStream); + document.Close(true); + string base64 = Convert.ToBase64String(memoryStream.ToArray()); + memoryStream.Close(); + memoryStream.Dispose(); + + return base64; +} + +public static string PathToFile() +{ + string? path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); + if (string.IsNullOrEmpty(path)) + { + path = Environment.OSVersion.Platform == PlatformID.Unix ? @"/" : @"\"; + } + return Environment.OSVersion.Platform == PlatformID.Unix ? string.Concat(path.Substring(5), @"/") : string.Concat(path.Substring(6), @"\"); +} + +{% endhighlight %} + +Step 7: Create a new folder as Helper and add a class file as AWSHelper.cs. Add the following namespaces and code samples in the AWSHelper class to invoke the published AWS Lambda function using the function name and access keys. + +{% highlight c# tabtitle="C#" %} + +Using Amazon.Lambda; +using Amazon.Lambda.Model; +using Newtonsoft.Json; + +public class AWSHelper +{ + public static async Task RunLambdaFunction(string html) + { + try + { + var AwsAccessKeyId = "awsaccessKeyID"; + var AwsSecretAccessKey = "awsSecretAccessKey"; + + AmazonLambdaClient client = new AmazonLambdaClient(AwsAccessKeyId, AwsSecretAccessKey, Amazon.RegionEndpoint.USEast1); + InvokeRequest invoke = new InvokeRequest + { + FunctionName = "AWSLambdaDockerContainer", + InvocationType = InvocationType.RequestResponse, + Payload = Newtonsoft.Json.JsonConvert.SerializeObject(html) + }; + //Get the InvokeResponse from the client InvokeRequest. + InvokeResponse response = await client.InvokeAsync(invoke); + + //Read the response stream. + Console.WriteLine($"Response: {response.LogResult}"); + Console.WriteLine($"Response: {response.StatusCode}"); + Console.WriteLine($"Response: {response.FunctionError}"); + var stream = new StreamReader(response.Payload); + JsonReader reader = new JsonTextReader(stream); + var serilizer = new JsonSerializer(); + var responseText = serilizer.Deserialize(reader); + + //Convert Base64String into a PDF document. + return Convert.FromBase64String(responseText.ToString()); + } + catch (Exception ex) + { + Console.WriteLine($"Exception Occured HTMLToPDFHelper: {ex}"); + } + return Convert.FromBase64String(""); + } +} + +{% endhighlight %} + +Step 8: Right-click the project and select **Publish to AWS Lambda**. + +![Convert HTMLToPDF AWS Lambda Step5](htmlconversion_images/awslambda5.png) + +Step 9: Create a new AWS profile in the Upload Lambda Function Window. After creating the profile, add a name for the Lambda function to publish. Then, click **Next**. + +![Convert HTMLToPDF AWS Lambda Step6](htmlconversion_images/awslambda6.png) + +Step 10: In the Advanced Function Details window, specify the **Role Name** as based on AWS Managed policy. After selecting the role, click the Upload button to deploy your application. + +![Convert HTMLToPDF AWS Lambda Step7](htmlconversion_images/awslambda7.png) +![Convert HTMLToPDF AWS Lambda Step8](htmlconversion_images/awslambda8.png) + +Step 11: After deploying the application, Sign in to your AWS account, and you can see the published Lambda function in the AWS console. + +![Convert HTMLToPDF AWS Lambda Step9](htmlconversion_images/awslambda9.png) + +## Steps to invoke the AWS Lambda function from the Test application + +Step 12: Add the following code to invoke the AWS lambda function with the HTML string from the Function Test. + +{% highlight c# tabtitle="C#" %} + +public class FunctionTest +{ + [Fact] + public void HtmlToPDFFunction() + { + string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); + string filePath = Environment.OSVersion.Platform == PlatformID.Unix ? string.Concat(path.Substring(5), @"/") : string.Concat(path.Substring(6), @"\"); + + var html = File.ReadAllText($"{filePath}/HtmlSample.html"); + byte[] base64 = null; + base64 = AWSHelper.RunLambdaFunction(html).Result; + + FileStream file = new FileStream($"{filePath}/file{DateTime.Now.Ticks}.pdf", FileMode.Create, FileAccess.Write); + var ms = new MemoryStream(base64); + ms.WriteTo(file); + file.Close(); + ms.Close(); + } +} + +{% endhighlight %} + +Step 13: Right click the test application and select **Run Tests**. + +![Convert HTMLToPDF AWS Lambda Step10](htmlconversion_images/awslambda10.png) + +Step 14: By executing the program, you will get the PDF document as follows. + +![Convert HTMLToPDF AWS Lambda Step11](htmlconversion_images/awslambda11.png) + +A complete working sample can be downloaded from [Github](https://github.com/SyncfusionExamples/html-to-pdf-csharp-examples/tree/master/AWS/HTML_to_PDF_Lambda_Docker_Container). From 6866c5c35e13cb2cf546cbe5618851f6d39bf8b4 Mon Sep 17 00:00:00 2001 From: Srihariharan Date: Fri, 15 Mar 2024 10:37:02 +0530 Subject: [PATCH 11/11] 876039: Resolved the UG Documentation staging error --- File-Formats-toc.html | 2 +- ...vert-HTML-to-PDF-in-AWS-Lambda-with-NET-6-container-image.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/File-Formats-toc.html b/File-Formats-toc.html index 54145e257..39226c48f 100644 --- a/File-Formats-toc.html +++ b/File-Formats-toc.html @@ -907,7 +907,7 @@
    AWS Lambda
  • - AWS Lambda with NET 6 container image + AWS Lambda with NET 6 container image
  • AWS Elastic Beanstalk diff --git a/File-Formats/PDF/Convert-HTML-To-PDF/Convert-HTML-to-PDF-in-AWS-Lambda-with-NET-6-container-image.md b/File-Formats/PDF/Convert-HTML-To-PDF/Convert-HTML-to-PDF-in-AWS-Lambda-with-NET-6-container-image.md index 31ff553d1..fb887cfa5 100644 --- a/File-Formats/PDF/Convert-HTML-To-PDF/Convert-HTML-to-PDF-in-AWS-Lambda-with-NET-6-container-image.md +++ b/File-Formats/PDF/Convert-HTML-To-PDF/Convert-HTML-to-PDF-in-AWS-Lambda-with-NET-6-container-image.md @@ -1,5 +1,5 @@ --- -title: Convert HTML to PDF in AWS Lambda with NET 6 container image | Syncfusion +title: Convert HTML to PDF in AWS Lambda with NET 6 container | Syncfusion description: Convert HTML to PDF in AWS Lambda with NET 6 container image using Syncfusion .NET HTML converter library. platform: file-formats control: PDF