Hi,
I have a pdf file which has some text like “HYPER_Google_1”(attached input.png file), I would like to replace this text with “Google”. However I dont want to display the anchor tag in the pdf file. My required output should be something like the attached output(expected_output file) pdf file.
Could you please help me with this requirement.
I tried with below sample code.
String key = “http://www.google.com/”;
key = “"”+key+“"”;
key = “Google”;
pdfContentEditor.replaceText(“HYPER_Google_1”, key);
//save output PDF
pdfContentEditor.save(“D:/Dharma/Aspose/word-hypderlink-issue/ReplaceTextOnAllPages.pdf”);
createHyperlink();
System.out.println(“Text replaced successfully!”);
Hi Dharmender,
//open document<o:p></o:p>
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("C:\\pdftest\\output.pdf");
//create TextAbsorber object to find all instances of the input search phrase
com.aspose.pdf.TextFragmentAbsorber textFragmentAbsorber = new com.aspose.pdf.TextFragmentAbsorber("Google");
//accept the absorber for first page of document
pdfDocument.getPages().accept(textFragmentAbsorber);
//get the extracted text fragments into collection
com.aspose.pdf.TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
//get first occurrence of text and replace
com.aspose.pdf.TextFragment textFragment = textFragmentCollection.get_Item(1);
//update text and other properties
textFragment.setText("GOOGLE");
textFragment.getTextState().setFont(com.aspose.pdf.FontRepository.findFont("Verdana"));
textFragment.getTextState().setFontSize(12);
// save updated PDF file
pdfDocument.save(“C:\pdftest\output_Text_Updated.pdf”);
Hi,
When I tried from my side, I am getting the same issue. The hyperlink from the text is getting disapppear.
I have attached both input and output snapshots.
Also is there any method for creating new hyperlinks in the existing pdf documents.
Hi Dharmender,
the sake of correction, I have logged it in our issue tracking system as PDFNEWJAVA-34365. We will
investigate this issue in details and will keep you updated on the status of a
correction. We
apologize for your inconvenience.
Hi,
Even i am using the environment what you are using. but still dont know how i am not able to achieve the output.
Please find the attached files.
Hi Dharmender,
//open
document<o:p></o:p>
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("C:\\pdftest\\output_pdf_from_word.pdf");
//create TextAbsorber object to find all instances of the input search phrase
com.aspose.pdf.TextFragmentAbsorber textFragmentAbsorber = new com.aspose.pdf.TextFragmentAbsorber("Google");
//accept the absorber for first page of document
pdfDocument.getPages().accept(textFragmentAbsorber);
//get the extracted text fragments into collection
com.aspose.pdf.TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
//get first occurrence of text and replace
com.aspose.pdf.TextFragment textFragment = textFragmentCollection.get_Item(1);
//update text and other properties
textFragment.setText("GOOGLE");
textFragment.getTextState().setFontSize(12);
//Create Link annotation object over same position where replaced text is inserted
com.aspose.pdf.LinkAnnotation link = new com.aspose.pdf.LinkAnnotation(pdfDocument.getPages().get_Item(1), new com.aspose.pdf.Rectangle(textFragment.getRectangle().getLLX(), textFragment.getRectangle().getLLY(), textFragment.getRectangle().getURX(), textFragment.getRectangle().getURY()));
//Create border object for LinkAnnotation
com.aspose.pdf.Border border = new com.aspose.pdf.Border(link);
//Set the border width value as 0
border.setWidth(0);
//Set the border for LinkAnnotation
link.setBorder(border);
//Specify the link type as remote URI
link.setAction(new com.aspose.pdf.GoToURIAction("www.google.com"));
//Add link annotation to annotations collection of first page of PDF file
pdfDocument.getPages().get_Item(1).getAnnotations().add(link);
//save updated PDF file
pdfDocument.save("C:\\pdftest\\output_Updated.pdf");
Hi,
Thanx for your respone.
I have used the above code sample and tested on my standalone program it is working. But when i integrate the same code into application, it is giving Null pointer exception at pdfDoc.getPages().accept(textFragmentAbsorber);
Could you please help me in troubleshooting the issue.
adding to the above post, I would like to know if is there any method to change the font colour and font size of the hyperlink text using the above code sample.
reddydharmender:Hi,
Thanx for your respone.
I have used the above code sample and tested on my standalone program it is working. But when i integrate the same code into application, it is giving Null pointer exception at pdfDoc.getPages().accept(textFragmentAbsorber);
Could you please help me in troubleshooting the issue.
reddydharmender:adding to the above post, I would like to know if is there any method to change the font colour and font size of the hyperlink text using the above code sample.
//update
text and other properties<o:p></o:p>
textFragment.setText("GOOGLE");
textFragment.getTextState().setFontSize(22);
textFragment.getTextState().setForegroundColor(com.aspose.pdf.Color.getYellowGreen());
Hi,
I am using the same pdf which i attached to the post. when I debugged furthur I observed that the textFragmentCollection is getting as zero, even where there is content in the pdf.
I am again attaching the same pdf for your reference.
is there any alternate approach to achieve this requirement.
Hi,
I am using the same pdf which i attached to the post. when I
debugged furthur I observed that the textFragmentCollection is getting
as zero, even where there is content in the pdf.
I am again attaching the same pdf for your reference.
is there any alternate approach to achieve this requirement.
I am facing this issue on Unix machine but not facing this on windows machine.
i am using the latest aspose-pdf-9.3.1-jdk16 jar file for this.
Hi Dharmender,
as PDFNEWJAVA-34373 in our issue tracking system. We will further
investigate this problem and will keep you updated on the status
of correction. Please be patient and spare us little time. We are sorry for
this inconvenience.
Hi Team,
Could you please update me on the status of the ticket PDFNEWJAVA-34373 as I need to update the same to my client.
Regards,
Dharmender`
Hi Dharmender,
Thanks for your inquiry. I am afraid your issue is not resolved as we have noticed it recently. It is pending for investigation in the queue with other priority task. As soon as its investigation is completed then we will share our findings or ETA with you.
We are sorry for the inconvenience caused.
Best Regards,
The issues you have found earlier (filed as PDFNEWJAVA-34365) have been fixed in Aspose.Pdf for Java 10.3.0.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
The issues you have found earlier (filed as PDFNEWJAVA-34373) have been fixed in Aspose.Pdf for Java 12.0.0.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.