Why we need Codedworkflows.cs file

I created one exe file to add sign image to pdf using c#,It works well in other new process but when i use that exe file in my actual process it throws this error.I’m using start process activity to call exe file. Unexpected error has occurred during the library compilation process:
Could not find file ‘C:\Users\Uipathuser\OneDrive - xxxxxxxxxxxxxxxxxx_SignForm.local\install\CodedWorkflow.cs’.


@Anil_G @supermanPunch @Sudharsan_Ka @Kaviyarasu_N ya do you have any idea? I also installed UiPath.codedworkflows package

@pravin_bindage ,
The error says that it couldn’t find the file path.
Can you please mannually check whether the particular mentioned file exist in the below location?

Regards,

Yes i checked that file is missing from that folder, but i dont understand how can i fix this

i dont find it anywhere. from where should i download it?

HI @pravin_bindage

Can you try this ?

Restart your system and try again

Regards
Sudharsan

its an virtual machine. i tried disconnect reconnect ,but still same problem

Then signout and open again @pravin_bindage

i tried but still same problem @Sudharsan_Ka

@Anil_G @Aakash_Singh_Rawat @Kalpesh_Chaudhari @Gokul_Jayakumar
@Yoichi @mohiniganesh15 @vishnuvarthanp @Gokul001 @Rahul_Unnikrishnan do you have any idea about this error?

@pravin_bindage

As you say its working in other new processes can you try copying your workflow there and check

cheers

I tried but when i start publishing that new process then again this problem occurs

@pravin_bindage

So you dont have an issue running it in studio?

Is it possible to share the workflow

cheers

Hi @pravin_bindage ,

Did you try invoking the new process into main process instead of using same activities?

sent in personnel message

TestPdf.zip (8.5 MB)
this is a code

Is there any other option to exe file? I tried with invoke code activity but it need itextsharp package installed in project & itextsharp is not compatible with windows projects @Anil_G @Sudharsan_Ka
This is the code

using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;

namespace PdfManipulate
{
    class PdfImageAdder
    {
        static void Main(string[] args)
        {
            if (args.Length != 4)
            {
                Console.WriteLine("Usage: PdfImageAdder <inputFilePath> <outputFilePath> <imagePath> <text>");
                return;
            }

            string inputFilePath = args[0]; // Existing file
            string outputFilePath = args[1]; // New file
            string imagePath = args[2]; // Image to be added
            string text = args[3]; // Text to be added

            using (FileStream fos = new FileStream(outputFilePath, FileMode.Create))
            {
                PdfReader pdfReader = new PdfReader(inputFilePath);
                PdfStamper pdfStamper = new PdfStamper(pdfReader, fos);

                //Image to be added in existing pdf file.
                Image image = Image.GetInstance(imagePath);
                image.ScaleAbsolute(70, 50); //Scale image's width and height

                // Font for text
                Font font = FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.NORMAL, BaseColor.BLACK);
                Font font1 = FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.BLACK);
                // Date to be added in existing pdf file
                DateTime date = DateTime.Now;
                string formattedDate = date.ToString("dd MMM yyyy");
                
                if(pdfReader.NumberOfPages > 3){
                    pdfReader.SelectPages("4-6");
                }

                // loop on all the PDF pages
                // i is the pdfPageNumber
                for (int i = 1; i <= pdfReader.NumberOfPages; i++)
                {
                    //getOverContent() allows you to write pdfContentByte on TOP of existing pdf pdfContentByte.
                    //getUnderContent() allows you to write pdfContentByte on BELOW of existing pdf pdfContentByte.
                    PdfContentByte pdfContentByte = pdfStamper.GetOverContent(i);

                    if (i == 1)
                    {
                        // add image
                        image.SetAbsolutePosition(130, 35); //Set position for image in PDF
                        pdfContentByte.AddImage(image);

                        // add text
                        ColumnText.ShowTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase(text, font), 80, 40, 0);

                        // add date
                        ColumnText.ShowTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase(formattedDate, font1), 60, 60, 0);
                    }
                    else
                    {
                        // add image
                        image.SetAbsolutePosition(230, 35); //Set position for image in PDF
                        pdfContentByte.AddImage(image);

                        // add text
                        ColumnText.ShowTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase(text, font), 90, 36, 0);

                        // add date
                        ColumnText.ShowTextAligned(pdfContentByte, Element.ALIGN_LEFT, new Phrase(formattedDate, font1), 65, 67, 0);
                    }

                    Console.WriteLine("Image, Date and Text added in page " + i + " of " + outputFilePath);
                }

                pdfStamper.Close();
                Console.WriteLine("Modified PDF created in >> " + outputFilePath);
            }
        }
    }
}`

Get a backup of your project file and open the project file again and then remove that UiPath.CodedWorkflow package and then reinstall the package
image

Regards
Sudharsan

Before reinstalling i get this error
Compilation failed or was cancelled.

Error: System.InvalidOperationException: In order for projects containing coded workflows to be compiled, the UiPath.CodedWorkflows package must be referenced explicitly if none of the imported packages already depend on it., HResult -2146233079

After reinstalling i get this

@pravin_bindage

PDF sharp is available in Windows Compatibility Try the below equivalent code

image

using System;
using System.IO;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;

namespace PdfManipulate
{
    class PdfImageAdder
    {
        static void Main(string[] args)
        {
            if (args.Length != 4)
            {
                Console.WriteLine("Usage: PdfImageAdder <inputFilePath> <outputFilePath> <imagePath> <text>");
                return;
            }

            string inputFilePath = args[0]; // Existing file
            string outputFilePath = args[1]; // New file
            string imagePath = args[2]; // Image to be added
            string text = args[3]; // Text to be added

            using (PdfDocument pdfDocument = PdfReader.Open(inputFilePath, PdfDocumentOpenMode.Modify))
            {
                //Image to be added in existing pdf file.
                using (XImage image = XImage.FromFile(imagePath))
                {
                    image.Interpolate = false;

                    // Font for text
                    XFont font = new XFont("Helvetica", 12, XFontStyle.Regular);
                    XFont font1 = new XFont("Helvetica", 8, XFontStyle.Regular);

                    // Date to be added in existing pdf file
                    DateTime date = DateTime.Now;
                    string formattedDate = date.ToString("dd MMM yyyy");

                    if (pdfDocument.PageCount > 3)
                    {
                        pdfDocument.Pages.RemoveAt(3);
                    }

                    // loop on all the PDF pages
                    for (int i = 0; i < pdfDocument.PageCount; i++)
                    {
                        PdfPage page = pdfDocument.Pages[i];
                        using (XGraphics gfx = XGraphics.FromPdfPage(page))
                        {
                            if (i == 0)
                            {
                                // add image
                                gfx.DrawImage(image, 130, 35, 70, 50); //Set position and size for image in PDF

                                // add text
                                gfx.DrawString(text, font, XBrushes.Black, new XRect(80, 40, page.Width, page.Height), XStringFormats.TopLeft);

                                // add date
                                gfx.DrawString(formattedDate, font1, XBrushes.Black, new XRect(60, 60, page.Width, page.Height), XStringFormats.TopLeft);
                            }
                            else
                            {
                                // add image
                                gfx.DrawImage(image, 230, 35, 70, 50); //Set position and size for image in PDF

                                // add text
                                gfx.DrawString(text, font, XBrushes.Black, new XRect(90, 36, page.Width, page.Height), XStringFormats.TopLeft);

                                // add date
                                gfx.DrawString(formattedDate, font1, XBrushes.Black, new XRect(65, 67, page.Width, page.Height), XStringFormats.TopLeft);
                            }

                            Console.WriteLine("Image, Date and Text added in page " + (i + 1) + " of " + outputFilePath);
                        }
                    }
                }

                pdfDocument.Save(outputFilePath);
                Console.WriteLine("Modified PDF created in >> " + outputFilePath);
            }
        }
    }
}

I did not compile fully…Should be good…check once

cheers