Skip to content

Commit e5daaa0

Browse files
committed
Task-642687-Updated the Html To Pdf in linux UG
1 parent a7f379e commit e5daaa0

File tree

1 file changed

+58
-7
lines changed

1 file changed

+58
-7
lines changed

Document-Processing/PDF/Conversions/HTML-To-PDF/NET/Convert-HTML-to-PDF-in-Azure-Functions-Linux.md

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,57 @@ Step 3: Select the function worker as .NET 8.0 isolated (Long-term support), and
2424
![Convert HTMLToPDF Azure Functions Step3](Azure_images\Azure-function-linux\AzureFunctions3.png)
2525

2626
Step 4: Install the [Syncfusion.HtmlToPdfConverter.Net.Linux](https://www.nuget.org/packages/Syncfusion.HtmlToPdfConverter.Net.Linux/) NuGet package as a reference to your .NET Core application [NuGet.org](https://www.nuget.org/).
27-
![Convert HTMLToPDF Azure Functions Step3](Azure_images\Azure-function-linux\Nuget-package.png)
27+
![Convert HTMLToPDF Azure Functions Step4](Azure_images\Azure-function-linux\Nuget-package.png)
2828

2929
N> Starting with v16.2.0.x, if you reference Syncfusion<sup>&reg;</sup> 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<sup>&reg;</sup> license key in your application to use our components.
3030

31-
Step 5: Include the following namespaces in Function1.cs file.
31+
32+
Step 5: Create a shell file with the below commands in the project and name it as dependenciesInstall.sh. In this article, these steps have been followed to install dependencies packages.
33+
34+
{% highlight c# tabtitle="C#" %}
35+
36+
DIR="/home/site/wwwroot/Package"
37+
if [ -d "$DIR" ]; then
38+
echo "'$DIR' found and now copying files, please wait ..."
39+
PACKAGE_USR="/home/site/wwwroot/Package/usr"
40+
if [ -d "$PACKAGE_USR" ]; then
41+
cp -r /home/site/wwwroot/Package/usr/lib/x86_64-linux-gnu/ /usr/lib/
42+
fi
43+
PACKAGE_LIB="/home/site/wwwroot/Package/lib"
44+
if [ -d "$PACKAGE_LIB" ]; then
45+
rm /home/site/wwwroot/Package/lib/x86_64-linux-gnu/libc.so.6;
46+
rm /home/site/wwwroot/Package/lib/x86_64-linux-gnu/libc-2.28.so;
47+
rm /home/site/wwwroot/Package/lib/x86_64-linux-gnu/libselinux.so.1;
48+
cp -r /home/site/wwwroot/Package/lib/x86_64-linux-gnu/ /lib/;
49+
ldconfig;
50+
fi
51+
else
52+
apt-get update && apt-get install -yq --no-install-recommends libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 libnss3 libgbm1;
53+
mkdir /home/site/wwwroot/Package;
54+
mkdir /home/site/wwwroot/Package/usr;
55+
mkdir /home/site/wwwroot/Package/usr/lib;
56+
mkdir /home/site/wwwroot/Package/usr/lib/x86_64-linux-gnu;
57+
mkdir /home/site/wwwroot/Package/lib;
58+
mkdir /home/site/wwwroot/Package/lib/x86_64-linux-gnu;
59+
PACKAGE_USR="/home/site/wwwroot/Package/usr"
60+
if [ -d "$PACKAGE_USR" ]; then
61+
cp -r /usr/lib/x86_64-linux-gnu/ /home/site/wwwroot/Package/usr/lib/
62+
fi
63+
PACKAGE_LIB="/home/site/wwwroot/Package/lib"
64+
if [ -d "$PACKAGE_LIB" ]; then
65+
cp -r /lib/x86_64-linux-gnu/ /home/site/wwwroot/Package/lib/
66+
fi
67+
fi
68+
69+
{% endhighlight %}
70+
71+
![Convert HTMLToPDF Azure Functions Step5](htmlconversion_images\ShellCommand.png)
72+
73+
Step 6: Set Copy to Output Directory as “Copy if newer” to the dependenciesInstall.sh file.
74+
75+
![Convert HTMLToPDF Azure Functions Step6](htmlconversion_images\CopyToNewwer.png)
76+
77+
Step 7: Include the following namespaces in Function1.cs file.
3278

3379
{% highlight c# tabtitle="C#" %}
3480

@@ -39,7 +85,7 @@ Step 5: Include the following namespaces in Function1.cs file.
3985

4086
{% endhighlight %}
4187

42-
Step 6: This Azure Function converts HTML to PDF using HTTP triggers. It handles GET/POST requests, processes the HTML, and returns a PDF response.
88+
Step 8: This Azure Function converts HTML to PDF using HTTP triggers. It handles GET/POST requests, processes the HTML, and returns a PDF response.
4389

4490
{% highlight c# tabtitle="C#" %}
4591

@@ -67,7 +113,7 @@ Step 6: This Azure Function converts HTML to PDF using HTTP triggers. It handles
67113

68114
{% endhighlight %}
69115

70-
step 7: Use the following code example in the HtmlToPdfConvert method to convert HTML to a PDF document using the [Convert](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.HtmlToPdfConverter.html#Syncfusion_HtmlConverter_HtmlToPdfConverter_Convert_System_String_) method in the [HtmlToPdfConverter](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.HtmlToPdfConverter.html) class. The Blink command line arguments are configured based on the given [CommandLineArguments](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.BlinkConverterSettings.html#Syncfusion_HtmlConverter_BlinkConverterSettings_CommandLineArguments) property of the [BlinkConverterSettings](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.BlinkConverterSettings.html) class.
116+
step 9: Use the following code example in the HtmlToPdfConvert method to convert HTML to a PDF document using the [Convert](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.HtmlToPdfConverter.html#Syncfusion_HtmlConverter_HtmlToPdfConverter_Convert_System_String_) method in the [HtmlToPdfConverter](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.HtmlToPdfConverter.html) class. The Blink command line arguments are configured based on the given [CommandLineArguments](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.BlinkConverterSettings.html#Syncfusion_HtmlConverter_BlinkConverterSettings_CommandLineArguments) property of the [BlinkConverterSettings](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.BlinkConverterSettings.html) class.
71117

72118
{% highlight c# tabtitle="C#" %}
73119

@@ -99,6 +145,11 @@ public byte[] HtmlToPdfConvert(string htmlText)
99145
Bottom = 20
100146
}
101147
};
148+
//Set command line arguments to run without sandbox.
149+
settings.CommandLineArguments.Add("--no-sandbox");
150+
settings.CommandLineArguments.Add("--disable-setuid-sandbox");
151+
152+
102153
htmlConverter.ConverterSettings = settings;
103154

104155
// Convert HTML to PDF
@@ -127,7 +178,7 @@ N> settings.CommandLineArguments.Add("--disable-setuid-sandbox");
127178
N> ```
128179
N> These arguments are only required when using **older versions** of the library that depend on Blink in sandbox-restricted environments.
129180

130-
Step 8: This code is designed to ensure that the necessary Linux packages for HTML to PDF conversion are installed if the operating system is Linux. It adjusts file permissions and executes a shell script to carry out the installation.
181+
Step 10: This code is designed to ensure that the necessary Linux packages for HTML to PDF conversion are installed if the operating system is Linux. It adjusts file permissions and executes a shell script to carry out the installation.
131182

132183
{% highlight c# tabtitle="C#" %}
133184

@@ -195,7 +246,7 @@ private static void InstallLinuxPackages()
195246
{% endhighlight %}
196247

197248

198-
Step 9: Add the following helper methods to copy and set permission to the BlinkBinariesLinux folder.
249+
Step 11: Add the following helper methods to copy and set permission to the BlinkBinariesLinux folder.
199250

200251
{% highlight c# tabtitle="C#" %}
201252

@@ -257,7 +308,7 @@ private static void SetExecutablePermission(string tempBlinkDir)
257308

258309
{% endhighlight %}
259310

260-
Step 10: Include the below enum in the Function1.cs file.
311+
Step 12: Include the below enum in the Function1.cs file.
261312

262313
{% highlight c# tabtitle="C#" %}
263314

0 commit comments

Comments
 (0)