Powershell 使用 itext.html2pdf 将 html 文件转换为 pdf
Powershell Convert html file to pdf using itext.html2pdf
如何使用 itext 在 Powershell 中将 html 转换为 pdf 文件。html2pdf?
我只想获取我的 input.html 文件并获得一个 output.pdf 文件
我正在使用 iText 7 pdfHTML 版本 2.1.3
这里是itext网站上的一段C#代码,但是如何把它转换成Powershell呢?
static void Main(string[] args)
{
using (FileStream htmlSource = File.Open("input.html", FileMode.Open))
using (FileStream pdfDest = File.Open("output.pdf", FileMode.OpenOrCreate))
{
ConverterProperties converterProperties = new ConverterProperties();
HtmlConverter.ConvertToPdf(htmlSource, pdfDest, converterProperties);
}
}
预先感谢您的帮助。
确保将 .NET 环境的以下依赖项中的二进制文件解压缩到工作目录中:
https://www.nuget.org/packages/BouncyCastle/1.8.1
https://www.nuget.org/packages/itext7.pdfhtml/
https://www.nuget.org/packages/itext7/
https://www.nuget.org/packages/Common.Logging/
https://www.nuget.org/packages/Common.Logging.Core/
然后,使用以下 PowerShell 代码:
Add-Type -Path "D:\temp\BouncyCastle.Crypto.dll"
Add-Type -Path "D:\temp\Common.Logging.Core.dll"
Add-Type -Path "D:\temp\Common.Logging.dll"
Add-Type -Path "D:\temp\itext.io.dll"
Add-Type -Path "D:\temp\itext.kernel.dll"
Add-Type -Path "D:\temp\itext.forms.dll"
Add-Type -Path "D:\temp\itext.layout.dll"
Add-Type -Path "D:\temp\itext.styledxmlparser.dll"
Add-Type -Path "D:\temp\itext.svg.dll"
Add-Type -Path "D:\temp\itext.html2pdf.dll"
$source = [System.IO.FileInfo]::new("D:\temp\input.html")
$dest = [System.IO.FileInfo]::new("D:\temp\output.pdf")
[iText.Html2Pdf.HtmlConverter]::ConvertToPdf($source, $dest)
如何使用 itext 在 Powershell 中将 html 转换为 pdf 文件。html2pdf?
我只想获取我的 input.html 文件并获得一个 output.pdf 文件
我正在使用 iText 7 pdfHTML 版本 2.1.3
这里是itext网站上的一段C#代码,但是如何把它转换成Powershell呢?
static void Main(string[] args)
{
using (FileStream htmlSource = File.Open("input.html", FileMode.Open))
using (FileStream pdfDest = File.Open("output.pdf", FileMode.OpenOrCreate))
{
ConverterProperties converterProperties = new ConverterProperties();
HtmlConverter.ConvertToPdf(htmlSource, pdfDest, converterProperties);
}
}
预先感谢您的帮助。
确保将 .NET 环境的以下依赖项中的二进制文件解压缩到工作目录中:
https://www.nuget.org/packages/BouncyCastle/1.8.1 https://www.nuget.org/packages/itext7.pdfhtml/ https://www.nuget.org/packages/itext7/ https://www.nuget.org/packages/Common.Logging/ https://www.nuget.org/packages/Common.Logging.Core/
然后,使用以下 PowerShell 代码:
Add-Type -Path "D:\temp\BouncyCastle.Crypto.dll"
Add-Type -Path "D:\temp\Common.Logging.Core.dll"
Add-Type -Path "D:\temp\Common.Logging.dll"
Add-Type -Path "D:\temp\itext.io.dll"
Add-Type -Path "D:\temp\itext.kernel.dll"
Add-Type -Path "D:\temp\itext.forms.dll"
Add-Type -Path "D:\temp\itext.layout.dll"
Add-Type -Path "D:\temp\itext.styledxmlparser.dll"
Add-Type -Path "D:\temp\itext.svg.dll"
Add-Type -Path "D:\temp\itext.html2pdf.dll"
$source = [System.IO.FileInfo]::new("D:\temp\input.html")
$dest = [System.IO.FileInfo]::new("D:\temp\output.pdf")
[iText.Html2Pdf.HtmlConverter]::ConvertToPdf($source, $dest)