We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Loop through all pdf elements

Loop through all pdf elements.

How to do that ?


4 Replies

MN Meikanda Nayanar Syncfusion Team April 9, 2019 12:57 PM UTC

Hi John, 
 
According to the structure of the PDF documents, we cannot loop through the PDF elements inside a PDF page. The Syncfusion PDF library allows you to loop through the Annotations and images in a PDF page. Please find the code snippet for the same as below 
 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("../../Data/Sample.pdf"); 
 
//Gets the collection of annotations in the PDF page 
foreach (var item in loadedDocument.Pages[0].Annotations) 
{ 
 
} 
 
//Gets the information about the extracted images from PDF page 
foreach (var item in loadedDocument.Pages[0].ImagesInfo) 
{ 
 
} 
 
Please let us know if you need any further assistance in this. 
 
Thanks 
Meikandan 
 
       


JO John replied to John April 9, 2019 01:44 PM UTC


Loop through all pdf elements.

How to do that ?

I need to replace certain text like all "abc" to "ghj" in pdf document and fill certain rectangles with other contents.



JO John replied to Meikanda Nayanar April 9, 2019 01:45 PM UTC

Hi John, 
 
According to the structure of the PDF documents, we cannot loop through the PDF elements inside a PDF page. The Syncfusion PDF library allows you to loop through the Annotations and images in a PDF page. Please find the code snippet for the same as below   
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("../../Data/Sample.pdf"); 
 
//Gets the collection of annotations in the PDF page 
foreach (var item in loadedDocument.Pages[0].Annotations) 
{ 
 
} 
 
//Gets the information about the extracted images from PDF page 
foreach (var item in loadedDocument.Pages[0].ImagesInfo) 
{ 
 
} 
  Please let us know if you need any further assistance in this.    Thanks  Meikandan           

I need to replace certain texts. Like all "abc" to "ghj" in pdf document and fill certain rectangles with other contents.

MN Meikanda Nayanar Syncfusion Team April 10, 2019 08:58 AM UTC

Hi John, 
We cannot retrieve the bounds of a shape within a PDF document.  
Functionality 
Possibilities 
Replace text 
Possible with a workaround (Please find the details below) 
Replace the content in rectangles  
Not possible 

We can retrieve the position of a text in a PDF document. Please find the below article for replacing a text in a PDF document with Syncfusion PDF library, 
But, still it is workaround and this workaround has its limitations.  
1.       Background color of the replaced text may be different in some cases.  
2.       Font, style and size of the newly added text will not be same as the other text in the paragraph.  
3.       The replaced text should occupy the same space occupied by the older text, if it occupies more space it might lead to text overlap. 
Please let us know if you need any further assistance in this. 
Thanks 
Meikandan 


Loader.
Live Chat Icon For mobile
Up arrow icon