Is it possible to convert .txt to .pdf in windows compatibility without any scope?

Hi…

  1. I have used Read pdf with OCR activity and read the OCRPDF
    and stored in a variable in OUTPUT STRING
  2. I use that variable as INPUT TEXT in WRITE TEXT FILE, Encoding as “UTF-8” and save it as “EditableText.pdf” in file name .

It creates a pdf file, but it is unable to open.
Is there any other way to do the same without using any scope.

Hi @Shanmathi

1 Like

Hi @sangeethaneelavannan1
Here in this thread they have used Word Application scope. My requirement is not to use any scope. Thanks.

Does the machine has Word installed?

1 Like

Hi @Shanmathi

You can use the following code inside C# Invoke Code to output your string to PDF. Just need to install iText 7 Community package and import the following namespaces:

  • iText.Kernel.Pdf
  • iText.Layout
  • iText.Layout.Element
var text="Hello World!";
var filePath = "output.pdf";

PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filePath));
Document doc = new Document(pdfDoc);

doc.Add(new Paragraph(text));
doc.Close();
1 Like

Thanks @kaydine ,
After running the process, I could not find the file. Where can I find the .pdf file.
If I mention a path, it shows error.

Hi @Balaji_Murugan ,
I don’t have word application.

Can you try specifying the full path here?

1 Like

Hi @Balaji_Murugan @kaydine
I have specified the full path, even then I can’t find the file there.
Is there any other solution?

@Shanmathi may I know how you’re specifying the PDF file path? And what is the error message you’re getting?

1 Like

Sure @kaydine ,
Here is the full code,

void main(string Output1)
{
	var text=Output1;
	string filePath = @"C:\Users\shanmathi\Documents\UiPath\ocrPdfToPDF\EditPDF.pdf";
	
	PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filePath));
	Document doc = new Document(pdfDoc);

	doc.Add(new Paragraph(text));
	doc.Close();
}

The process runs successfully and there is no error message. I could not find the pdf in the path that I have mentioned.

Are you running this from UiPath? I don’t think function definition is supported in Invoke Code

1 Like

Yeah from UiPath Studio.
If when I don’t use the function, No compile code to run error occurs.@kaydine .

Not seeing any error might be a bug in UiPath Studio.
Please try to set your parameter Output1 in the arguments of Invoke Code instead of defining the code as a function, then set the code as-is.

image

Don’t forget to set the Language to CSharp

1 Like

Hi @Shanmathi ,

Could you provide us with Screenshot of the Error that you are receiving ? Also let us know if you are using the Windows Compatibility and not Windows-Legacy.

1 Like

I had made a mistake in defining the arguments and assigning it.
It works now. Thanks @kaydine .

1 Like

That’s great! Glad I could help :grinning:

1 Like

Hy @supermanPunch, Thanks for the reply.
I had made a mistake in defining the arguments and assigning it inside the invoke code. After defining it right as @kaydine said, it works well.

1 Like

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