我是Powershell的新手。我有一个htlm文件,我想转换成pdf文件使用powershell脚本。
有这个错误。
Unable to find type [iText.Html2Pdf.HtmlConverter].
At C:\Users\Z004APNA\Desktop\Htms_to_Pdf\Generate-HTML_to_PDF.ps1:32 char:1
+ [iText.Html2Pdf.HtmlConverter]::ConvertToPdf($source, $dest)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (iText.Html2Pdf.HtmlConverter:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound我正在使用这个代码。
$InputLocation = "C:\Users\Z004APNA\Desktop\Htms_to_Pdf"
$htmls = get-childitem -filter *.htm? -path $InputLocation
#$htmls = Get-ChildItem -Path $InputLocation -Include *.html -Recurse
foreach($html in $htmls)
{
$filename = $html.FullName
$basepath = "$($_.DirectoryName)"
$pdf = $html.FullName.split('.')[0] + '.pdf'
}
Add-Type -Path ($InputLocation+"\BouncyCastle.Crypto.dll")
Add-Type -Path ($InputLocation+"\Common.Logging.Core.dll")
Add-Type -Path ($InputLocation+"\Common.Logging.dll")
Add-Type -Path ($InputLocation+"\itext.io.dll")
Add-Type -Path ($InputLocation+"\itext.kernel.dll")
Add-Type -Path ($InputLocation+"\itext.forms.dll")
Add-Type -Path ($InputLocation+"\itext.layout.dll")
Add-Type -Path ($InputLocation+"\itext.styledxmlparser.dll")
Add-Type -Path ($InputLocation+"\itext.svg.dll")
Add-Type -Path ($InputLocation+"\itext.html2pdf.dll")
$source = [System.IO.FileInfo]::new($filename)
$dest = [System.IO.FileInfo]::new($pdf)
[iText.Html2Pdf.HtmlConverter]::ConvertToPdf($source, $dest)发布于 2021-07-13 21:30:13
将comment作为答案发布:
到处寻找,iText是你购买/下载的
/C#库,对吗?您可能需要研究一下如何使用C#/.NET assemblies in PowerShell
其中最常用的两个答案是:
[Reflection.Assembly]::LoadFile("c:\temp\tempLib.dll")或者使用内置的Cmdlet Add-Type:
Add-Type -Path foo.dllhttps://stackoverflow.com/questions/68347872
复制相似问题