1

I am trying to replace text on a specific page to upper case using Aspose.PDF for .Net. If anyone can provide any help that would be great. Thank you.

NYTom
  • 524
  • 2
  • 14

1 Answers1

3

My name is Tilal Ahmad and I am a developer evangelist at Aspose.

You may use the documentation link for searching and replacing text on a specific page of the PDF document. You should call the Accept method for specific page index as suggested at the bottom of the documentation. Furthermore, for replacing text with uppercase you can use ToUpper() method of String object as follows.

....
textFragment.Text = textFragment.Text.ToUpper();
....

Edit: A sample code to change text case on a specific PDF page

//open document
Document pdfDocument = new Document(myDir + "testAspose.pdf");
//create TextAbsorber object to find all instances of the input search    phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("");
//accept the absorber for all the pages
pdfDocument.Pages[2].Accept(textFragmentAbsorber);
//get the extracted text fragments
TextFragmentCollection textFragmentCollection =   textFragmentAbsorber.TextFragments;
//loop through the fragments
foreach (TextFragment textFragment in textFragmentCollection)
{
    //update text and other properties
    textFragment.Text = textFragment.Text.ToUpper();

}

pdfDocument.Save(myDir+"replacetext_output.pdf");
Rajan Mishra
  • 1,178
  • 2
  • 14
  • 30
Tilal Ahmad
  • 940
  • 5
  • 9
  • This will not work for two reasons, your assumption is I know the text to replace but I dont. I just know the page and want to convert it to upper case. Also your suggesting to use the textFragment class, but that class doesn't support multi line strings which of course would exist on a page, so that won't work either. – NYTom Mar 29 '16 at 11:01
  • @NYTom, please note if we do not pass a search string to TextFragmentAbsorber object then it will search complete text of the specified page as TextFragmentCollection and we can iterate through the collection to change the case of Textfragment. – Tilal Ahmad Mar 29 '16 at 15:54
  • But what about the multi line issue using that class? – NYTom Mar 29 '16 at 16:46
  • @NYTom, sorry for delayed response. As stated above TextFragmentAbsorber will get all the text(multine) of the page as TextFragmentCollection. So there would not be any multi line issue. However if you are facing any issue then please share your sample PDF document in your related post in Aspose.Pdf forum, we will look into it and will guide you accordingly. – Tilal Ahmad Apr 04 '16 at 08:41
  • I am trying to replace a large text in pdf using aspose but after line ending rest of the text is missing. – Rajan Mishra Oct 23 '18 at 12:33
  • @RajanMishra, would you please share source and generated files along with narrowed down sample code, as a single ZIP file by uploading it to Google Drive, Dropbox etc. So that we may try to reproduce and investigate it in our environment. PS: I work with Aspose as Developer Evangelist. – Farhan Raza Oct 26 '18 at 10:12