Html file to pdf file conversion

Hi,
I want to convert html file to pdf file , there is a activity but it doesn’t work properly
image
Please let me know another method which converts from html file to pdf file
it may be vb.net code where i can invoke vb code(vb.net)
Thanks
Rounak

1 Like

@Rounak_Kumar1

You can try opening the html file in browser using use application/browser activity and then print using ctrl+p

Cheers

Thanks Sir for your reply
Please let me know any other method which works in background.

@Rounak_Kumar1

You can do it using itext7 and boucy castle library…first install the dependency…and then use the code
Dependencies
image
image

Code


itext.Html2pdf.HtmlConverter.ConvertToPdf(htmlInput,New FileStream(FileLoc,FileMode.Create))

cheers

1 Like

Hi @Anil_G,
Getting error
“Invoke Code: Exception has been thrown by the target of an invocation.”

@Rounak_Kumar1

Did you install both the libraries?

If yes please open exception details from locals panel and please show that

Cheers

Hi @Anil_G
This below exception i am getting
RemoteException wrapping System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> RemoteException wrapping iText.Kernel.Exceptions.PdfException: Unknown PdfException. —> RemoteException wrapping System.TypeInitializationException: The type initializer for ‘iText.Bouncycastleconnector.BouncyCastleFactoryCreator’ threw an exception. —> RemoteException wrapping System.IO.FileLoadException: Could not load file or assembly ‘bc-fips-1.0.2,
Version=1.0.2.0,
Culture=neutral,
PublicKeyToken=null’ or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)
at iText.Bouncycastlefips.BouncyCastleFipsFactory…ctor()
at iText.Bouncycastleconnector.BouncyCastleFactoryCreator.<>c.b__10_1()
at iText.Bouncycastleconnector.BouncyCastleFactoryCreator.CreateFactory(Func1 factoryCreator) at iText.Bouncycastleconnector.BouncyCastleFactoryCreator.TryCreateFactory(Func1 factoryCreator)
at iText.Bouncycastleconnector.BouncyCastleFactoryCreator…cctor()
— End of inner exception stack trace —
at iText.Kernel.Pdf.SmartModePdfObjectsSerializer…ctor()
— End of inner exception stack trace —
at iText.Kernel.Pdf.SmartModePdfObjectsSerializer…ctor()
at iText.Kernel.Pdf.PdfWriter…ctor(Stream os,
WriterProperties properties)
at iText.Kernel.Pdf.PdfWriter…ctor(Stream os)
at UiPathCodeRunner_30db6a4f12bb4817bb595b450d619d26.Run(String htmlInput,
String FileLoc)
— End of inner exception stack trace —
at System.RuntimeMethodHandle.InvokeMethod(Object target,
Object arguments,
Signature sig,
Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,
Object parameters,
Object arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,
BindingFlags invokeAttr,
Binder binder,
Object parameters,
CultureInfo culture)
at System.RuntimeType.InvokeMember(String name,
BindingFlags bindingFlags,
Binder binder,
Object target,
Object providedArgs,
ParameterModifier modifiers,
CultureInfo culture,
String namedParams)
at UiPath.Activities.System.Utilities.InvokeCode.CompilerRunner.Run(Object args)
at UiPath.Activities.System.Utilities.InvokeCode.NetCodeInvoker.Run(String userCode,
List1 inArgs, IEnumerable1 imps,
Object args)
at UiPath.Core.Activities.InvokeCode.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance,
ActivityExecutor executor,
BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor,
BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor,
BookmarkManager bookmarkManager,
Location resultLocation)

Yes i have installed both the package
image

Thanks

@Rounak_Kumar1

Looks like dependency is not downloaded properly…try to uninstall them…go to %userprofile%/.nuger/packages and then delete the itext and bouncy castle package folders …and redownload them

Cheers

Hi @Yoichi ,
do you have any idea about this query, please let me know

Regards
Rounak

@Rounak_Kumar1

Did you try redownload?

Did it not work?

Cheers

yes i have redownloaded
but It didn’t work

Thanks

@Rounak_Kumar1

You deleted the only one and tried?

Try unpacking this and place it in the packages folder under .nuget
itext7.bouncy-castle-fips-adapter.zip (1.7 MB)

You can delete the existing folder with same name

cheers

1 Like

Hi,

How about to use WordApplicationScope to read HTML then use SaveDocumentAsPDF
OR use UseExcelFile to read HTML then use SaveExcelFileAsPDF?

image

Sample20230529-1aL.zip (4.0 KB)

Regards,

2 Likes

Thank you so much @Yoichi
it works for me

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.