Hi everyone!
I’m trying to convert a tif file with multiple pages. However, I always get this error when invoking the code. I’m using VB here.
Invoke Code: Exception has been thrown by the target of an invocation.
Below is the complete error message
RemoteException wrapping System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> RemoteException wrapping System.NotSupportedException: No data is available for encoding 1252. For information on defining a custom encoding,
see the documentation for the Encoding.RegisterProvider method.
at System.Text.Encoding.GetEncoding(Int32 codepage)
at PdfSharp.Pdf.Internal.PdfEncoders.get_WinAnsiEncoding()
at PdfSharp.Pdf.Internal.DocEncoding.GetByteCount(Char chars,
Int32 index,
Int32 count)
at System.Text.Encoding.GetByteCount(String s)
at System.Text.Encoding.GetBytes(String s)
at PdfSharp.Pdf.IO.PdfWriter.WriteDocString(String text)
at PdfSharp.Pdf.PdfDate.WriteObject(PdfWriter writer)
at PdfSharp.Pdf.PdfDictionary.WriteDictionaryElement(PdfWriter writer,
PdfName key)
at PdfSharp.Pdf.PdfDictionary.WriteObject(PdfWriter writer)
at PdfSharp.Pdf.PdfDocument.DoSave(PdfWriter writer)
at PdfSharp.Pdf.PdfDocument.Save(Stream stream,
Boolean closeStream)
at PdfSharp.Pdf.PdfDocument.Save(Stream stream)
at PdfSharp.Pdf.PdfDocument.Save(String path)
at UiPathCodeRunner_b37dc930bab84f9aa04c1e9b2488df23.Run()
— End of inner exception stack trace —
at System.RuntimeMethodHandle.InvokeMethod(Object target,
Span1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) 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 System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args) at UiPath.Activities.System.Utilities.InvokeCode.CompilerRunner.Run(Object[] args) at UiPath.Activities.System.Utilities.InvokeCode.NetCodeInvoker.Run(String userCode, List
1 inArgs,
IEnumerable`1 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)
Here’s my code inside the invoke activity
Dim tifFilePath As String = "C:\Users\folder\sometif.tif" Dim tifBitmap As New Bitmap(tifFilePath) 'Create a PDF document Dim pdfDocument As New Pdf.PdfDocument() 'Get the GUID for the frame dimension of pages Dim frameDimensionGuid As System.Drawing.Imaging.FrameDimension = System.Drawing.Imaging.FrameDimension.Page For pageIndex As Integer = 0 To tifBitmap.GetFrameCount(frameDimensionGuid) - 1 tifBitmap.SelectActiveFrame(frameDimensionGuid, pageIndex) Dim memoryStream As New MemoryStream() tifBitmap.Save(memoryStream, ImageFormat.Tiff) Dim pdfPage As Pdf.PdfPage = pdfDocument.AddPage() Dim gfx As XGraphics = XGraphics.FromPdfPage(pdfPage) Dim xImage As XImage = XImage.FromStream(memoryStream) gfx.DrawImage(xImage, 0, 0, pdfPage.Width, pdfPage.Height) Next ' Save the PDF file Dim outputPdfPath As String = "C:\Users\outputfolder\newpdf.pdf" pdfDocument.Save(outputPdfPath)
My Imports
PDfSharp
PdfSharp.Drawing
PdfSharp.Pdf
System.Drawing
The package I installed
Now, what’s weird is that I have the same code using Visual Studio and I did not encounter any error.
The code in VS studio works and I was able to convert tif with multiple pages into 1 pdf file. I ran out of ideas or solutions why in UiPath invoke code did not work.
Does any one encounter this?