I am new to Powershell. I have one htlm file and I want to convert that into pdf file using powershell script.
having this error.
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
I am using this code.
$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)