Skip to content

Commit 2abc3b5

Browse files
Merge pull request #1534 from syncfusion-content/Task-642687-LinuxHtmltoPDF
Task-642687-Need to add the complete Linux dependencies details and troubleshooting steps in UG
2 parents a4e042e + 6aa31da commit 2abc3b5

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

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

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,62 @@ 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 bash tabtitle="Shell" %}
35+
36+
echo "Starting dependencies installation script..."
37+
38+
39+
if ! command -v rsync &> /dev/null; then
40+
echo "rsync could not be found, installing..."
41+
apt-get update && apt-get install -yq rsync
42+
fi
43+
44+
FILE_PATH="/home/site/wwwroot/Package/usr/lib/x86_64-linux-gnu/libnss3.so"
45+
if [ -f "$FILE_PATH" ]; then
46+
echo "Dependencies file exists."
47+
PACKAGE_USR="/home/site/wwwroot/Package/usr/lib/x86_64-linux-gnu"
48+
if [ -d "$PACKAGE_USR" ]; then
49+
echo "Copying user libraries..."
50+
rsync -av --update /home/site/wwwroot/Package/usr/lib/ /usr/lib/
51+
echo "Copied successfully..."
52+
fi
53+
else
54+
echo "Package directory does not exist. Installing dependencies..."
55+
apt-get update && apt-get install -yq --no-install-recommends \
56+
libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 \
57+
libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 \
58+
libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 \
59+
libx11-6 libx11-xcb1 libxcb1 libxcursor1 libxdamage1 libxext6 \
60+
libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 libnss3 libgbm1
61+
62+
mkdir -p /home/site/wwwroot/Package/usr/lib/x86_64-linux-gnu
63+
mkdir -p /home/site/wwwroot/Package/lib/x86_64-linux-gnu
64+
65+
PACKAGE_USR="/home/site/wwwroot/Package/usr/lib/x86_64-linux-gnu"
66+
if [ -d "$PACKAGE_USR" ]; then
67+
echo "Copying user libraries to package..."
68+
rsync -av /usr/lib/x86_64-linux-gnu/ /home/site/wwwroot/Package/usr/lib/x86_64-linux-gnu
69+
fi
70+
fi
71+
72+
echo "Dependencies installation script completed."
73+
74+
{% endhighlight %}
75+
76+
![Convert HTMLToPDF Azure Functions Step5](htmlconversion_images\ShellCommand.png)
77+
78+
Step 6: Set Copy to Output Directory as “Copy if newer” to the dependenciesInstall.sh file.
79+
80+
![Convert HTMLToPDF Azure Functions Step6](htmlconversion_images\CopyToNewer.png)
81+
82+
Step 7: Include the following namespaces in Function1.cs file.
3283

3384
{% highlight c# tabtitle="C#" %}
3485

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

4091
{% endhighlight %}
4192

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.
93+
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.
4394

4495
{% highlight c# tabtitle="C#" %}
4596

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

68119
{% endhighlight %}
69120

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.
121+
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.
71122

72123
{% highlight c# tabtitle="C#" %}
73124

@@ -99,6 +150,7 @@ public byte[] HtmlToPdfConvert(string htmlText)
99150
Bottom = 20
100151
}
101152
};
153+
102154
htmlConverter.ConverterSettings = settings;
103155

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

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.
182+
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.
131183

132184
{% highlight c# tabtitle="C#" %}
133185

@@ -195,7 +247,7 @@ private static void InstallLinuxPackages()
195247
{% endhighlight %}
196248

197249

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

200252
{% highlight c# tabtitle="C#" %}
201253

@@ -257,7 +309,7 @@ private static void SetExecutablePermission(string tempBlinkDir)
257309

258310
{% endhighlight %}
259311

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

262314
{% highlight c# tabtitle="C#" %}
263315

@@ -318,4 +370,5 @@ An online sample link to [convert HTML to PDF document](https://ej2.syncfusion.c
318370

319371
Click [here](https://www.syncfusion.com/document-processing/pdf-framework/net-core/html-to-pdf) to explore the rich set of Syncfusion<sup>&reg;</sup> HTML to PDF converter library features.
320372

321-
An online sample link to [convert HTML to PDF document](https://ej2.syncfusion.com/aspnetcore/PDF/HtmltoPDF#/material3) in ASP.NET Core.
373+
374+
An online sample link to [convert HTML to PDF document](https://ej2.syncfusion.com/aspnetcore/PDF/HtmltoPDF#/material3) in ASP.NET Core.
52.5 KB
Loading
36.4 KB
Loading

0 commit comments

Comments
 (0)