Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to replace text in all pages of pdf? #56

Open
anyspa opened this issue Dec 29, 2022 · 1 comment
Open

how to replace text in all pages of pdf? #56

anyspa opened this issue Dec 29, 2022 · 1 comment

Comments

@anyspa
Copy link

anyspa commented Dec 29, 2022

here is the sample code for replace text in pdf use aspose-pdf.jar, it can only replace the first page of pdf.

public static void replaceTextOnAllPages() { // Open document Document pdfDocument = new Document("source.pdf"); // Create TextAbsorber object to find all instances of the input search phrase TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("sample"); // Accept the absorber for first page of document pdfDocument.getPages().accept(textFragmentAbsorber); // Get the extracted text fragments into collection TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments(); // Loop through the fragments for (TextFragment textFragment : (Iterable<TextFragment>) textFragmentCollection) { textFragment.setText("New Pharase"); } pdfDocument.save("Updated_Text.pdf"); }

now I want to replace the text for all pages in pdf, how can I do?

@asadalikhan90
Copy link
Collaborator

@anyspa

The below line in the above code snippet is supposed to work for all pages:

pdfDocument.getPages().accept(textFragmentAbsorber);

Are you using the latest version and with a valid license? Can you please create a post in our official support forum along with your sample file so that we can test the scenario in our environment and address it accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants