HtmlToPdfOptionsChromiumBaseDirectory Property |
Gets and sets a custom directory where will be placed portable Chromium browser. Default value depends of platform (win-x64, win-86, linux-x64 or osx-x64)Current directory\runtimes\win-x64\native\.
Namespace: SautinSoft.PdfVisionAssembly: SautinSoft.PdfVision (in SautinSoft.PdfVision.dll) Version: 2024.12.6
Syntax public string ChromiumBaseDirectory { get; set; }
Public Property ChromiumBaseDirectory As String
Get
Set
Property Value
StringRemarks
Before start the converting the component will always try find the portable Chromium browser in this directory.
In case of Chromium browser is missing in this directory, the component will try to download Chromium browser from Internet (https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html).
To unpack the portable Chromium browser without Internet connection:
1. Add reference into your App to one of these assemblies depending of deploying platform:
https://www.nuget.org/packages/SautinSoft.PdfVision.Chromium.Windows
https://www.nuget.org/packages/SautinSoft.PdfVision.Chromium.Linux
https://www.nuget.org/packages/SautinSoft.PdfVision.Chromium.MacOs
2. Launch this code:
ChromiumEngine.Unpack(ChromiumBaseDirectory);
Thus you can always be sure that you deploy SautinSoft.PdfVision with portable Chromium browser on client's machine without Internet connection.
Example How to convert multiple HTML files to single PDF file using C#
using System;
using System.IO;
using System.Collections.Generic;
using SautinSoft.PdfVision;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
ConvertMultipleHtmlToPdfFile();
}
public static void ConvertMultipleHtmlToPdfFile()
{
string[] inpFiles = new string[]
{
Path.GetFullPath(@"..\..\..\1.html"),
Path.GetFullPath(@"..\..\..\2.html")
};
string outFile = new FileInfo("Result.pdf").FullName;
PdfVision v = new PdfVision();
HtmlToPdfOptions options = new HtmlToPdfOptions()
{
PageSetup = new PageSetup()
{
PaperType = PaperType.Letter,
Orientation = Orientation.Portrait,
PageMargins = new PageMargins()
{
Left = LengthUnitConverter.ToPoint(5, LengthUnit.Millimeter),
Top = LengthUnitConverter.ToPoint(5, LengthUnit.Millimeter),
Right = LengthUnitConverter.ToPoint(5, LengthUnit.Millimeter),
Bottom = LengthUnitConverter.ToPoint(5, LengthUnit.Millimeter)
}
},
PrintBackground = true,
Scale = 1,
ChromiumBaseDirectory = Path.GetFullPath(@"..\..\..\..\..\..\Chromium\")
};
try
{
List<byte[]> pdfCollection = new List<byte[]>();
foreach (string inpFile in inpFiles)
{
Console.WriteLine($"Converting {Path.GetFileName(inpFile)} ...");
byte[] pdfData = v.ConvertHtmlToPdf(inpFile, options);
pdfCollection.Add(pdfData);
}
byte[] singlePdfData = v.MergePdf(pdfCollection);
File.WriteAllBytes(outFile, singlePdfData);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
Console.ReadLine();
}
}
}
}
How to convert multiple HTML files to single PDF file using VB.Net
Imports System
Imports System.IO
Imports System.Collections.Generic
Imports SautinSoft.PdfVision
Namespace Sample
Friend Class Program
Shared Sub Main(ByVal args() As String)
ConvertMultipleHtmlToPdfFile()
End Sub
Public Shared Sub ConvertMultipleHtmlToPdfFile()
Dim inpFiles() As String = {Path.GetFullPath("..\..\..\1.html"), Path.GetFullPath("..\..\..\2.html")}
Dim outFile As String = (New FileInfo("Result.pdf")).FullName
Dim v As New PdfVision()
Dim options As New HtmlToPdfOptions() With {
.PageSetup = New PageSetup() With {
.PaperType = PaperType.Letter,
.Orientation = Orientation.Portrait,
.PageMargins = New PageMargins() With {
.Left = LengthUnitConverter.ToPoint(5, LengthUnit.Millimeter),
.Top = LengthUnitConverter.ToPoint(5, LengthUnit.Millimeter),
.Right = LengthUnitConverter.ToPoint(5, LengthUnit.Millimeter),
.Bottom = LengthUnitConverter.ToPoint(5, LengthUnit.Millimeter)
}
},
.PrintBackground = True,
.Scale = 1,
.ChromiumBaseDirectory = Path.GetFullPath("..\..\..\..\..\..\Chromium\")
}
Try
Dim pdfCollection As New List(Of Byte())()
For Each inpFile As String In inpFiles
Console.WriteLine($"Converting {Path.GetFileName(inpFile)} ...")
Dim pdfData() As Byte = v.ConvertHtmlToPdf(inpFile, options)
pdfCollection.Add(pdfData)
Next inpFile
Dim singlePdfData() As Byte = v.MergePdf(pdfCollection)
File.WriteAllBytes(outFile, singlePdfData)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
Catch ex As Exception
Console.WriteLine($"Error: {ex.Message}")
Console.ReadLine()
End Try
End Sub
End Class
End Namespace
See Also