Name/identify an image in a PDF file

1 Answer 69 Views
PdfProcessing
Eric
Top achievements
Rank 1
Eric asked on 28 Nov 2023, 12:53 AM

I am writing an application that that generates a pdf presentation based on a pdf "template" file.  The template file contains one or more images. The application replaces the images in the template file with other images the user has called out. 

How can I name or "tag" the placeholder images in the template file in order to identify what goes where?   

I thought of using the accessibility/alternative text field of each image but I understand that is not currently accessible via the Telerik library.

Are there other fields I could use to place identifiers assocated with the images?

I want to use Adobe acrobat to edit the template file and add the tags if possible.

Thanks. 

1 Answer, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 30 Nov 2023, 02:26 PM

Hi Eric,

Please accept my apologies for the inconvenience but currently, there is no way to mark a specific image in order to identify it later by that specific property. The only possible property that can come close to this requirement is the Size, but one would need to know the size of each image placeholder in order to be able to identify it later through code (which I believe will be quite troublesome).

That said, if it fits your scenario it is possible to achieve the desired results by using TextFragment as a placeholder instead. You can see how this can be achieved in the Replace Text Content With Image | Telerik Document Processing example.

Regards,
Yoan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Eric
Top achievements
Rank 1
commented on 30 Nov 2023, 03:26 PM

Thank you for your response.

The use of a place-holder image provides me information on the location and size of the replacement image (among other attributes) thus I would like to keep it as part of the approach.  Possibly I could search for the place-holder text and assume the image "directly" behind it is the image to be replaced (along with removing the place-holder text). 

Not sure how easy this is as I am new to this depth of PDF processing.  

Do I replace an image similar to the approach in the reference article?

Yoan
Telerik team
commented on 05 Dec 2023, 11:12 AM

Hello Eric,

The approach you are suggesting is indeed achievable and I have created a sample project that demonstrates how it can be done. Feel free to use it for your own purposes and don't hesitate to ask questions if any arise.

The initial document has a single image with a text placeholder behind it (see attached "placeholderPosition.png"). We obtain the placeholder instance and its position through the Search functionality of PdfProcessing and start iterating all pages and their content. If we come across an image, through some manual calculations we determine whether or not the placeholder is behind that image. If so, then the new image is created and replaced with the old one, and the placeholder is also deleted.

In the Replace Image in PDF Document example you can see how an image is replaced along with its properties.

I hope this helps.

Regards,

Yoan

Eric
Top achievements
Rank 1
commented on 05 Dec 2023, 03:19 PM

Wow!

Very much appreciate the thought and time you spent to help me.

I will take a look at it and get back to you.

Eric

Yoan
Telerik team
commented on 08 Dec 2023, 08:35 AM

Hello Eric,

Please take your time. We remain at your disposal in case anything comes up in the meantime.

Regards,

Yoan

Eric
Top achievements
Rank 1
commented on 08 Dec 2023, 11:36 PM

Yoan,

Sorry, working on several projects simultaneously...

Thanks. I reviewed what you did. 

Looks like I need to fine tune it a bit to make sure the image that is being replaced is on the same page as the placeholder text. Maybe I do the search & replacement, page by page.  Or, does the "SearchResult" tell me or reference the page? Maybe you have some ideas on this.  

It is a good start. 

Thanks for helping me with some of the basic understanding of finding text and replacing images. 

Take care.  Eric 

Yoan
Telerik team
commented on 12 Dec 2023, 08:12 AM

Hi Eric,

I am glad to hear your are finding our assistance helpful.

As for your requirement, each SearchResult instance has an out-of-the-box GetResultPage method that can help you with that.

Regards,

Yoan

Eric
Top achievements
Rank 1
commented on 12 Dec 2023, 03:10 PM

Perfect!  Thanks.
Tags
PdfProcessing
Asked by
Eric
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Share this question
or