Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Mar 07, 2024 9:18 am

Hi..


Assume that have converted a Word file to a PDF file using `Spire.word`.
There are 6 to 10 photos in the Word file, and I want to specify one specific photo and replace it in the PDF file using `spire.pdf`.

Previously, this work was done in Word, and alternative text was specified for each image.
This alternative text identifies what the image is in Spire.Word.

However, this task now has to be done in PDF rather than Word.
When converting a Word file to PDF with alternative text entered,
Is it possible to separate photos in `Spire.PDF` and change only those photos?

Sungkyu_min
 
Posts: 36
Joined: Fri Jan 07, 2022 5:53 am

Thu Mar 07, 2024 10:12 am

Hello,

Thank you for your inquiry.
Please find attached the code snippet that demonstrates how to replace images with text.
If you have any questions or need further clarification on the code provided, please feel free to reach out.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Fri Mar 08, 2024 12:58 am

thank you for the reply.

However, I cannot find the `ResourceName` properties in the `PdfImageInfo` class.
Additionally, I also cannot find the `DeleteImage` method in the `PdfImageHelper` class.
Can you tell me what the problem is?


Code: Select all
using Spire.Pdf;
using Spire.Pdf.Graphics;
using Spire.Pdf.Utilities;
using Spire.Pdf.Exporting;
...
if (imagesInfos[i].ResourceName != "") { //Cna't find ResourceName
   ....
    //Remove the image
    pdfImageHelper.DeleteImage(imagesInfos[i]);   // Can't find DeleteImage
   ...
}

Sungkyu_min
 
Posts: 36
Joined: Fri Jan 07, 2022 5:53 am

Fri Mar 08, 2024 1:35 am

Hello,

Thank you for your feedback.
The code I provided to you is based on the latest version of Spire.PDF (Spire.PDF Pack (Hot Fix) Version: 10.2.2). Kindly upgrade the version of Spire.PDF in your project to this version before testing the code again.
Should you encounter any issues during the upgrade process or while testing the code, please do not hesitate to contact me for assistance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Fri Mar 08, 2024 2:20 am

Hi..

After updating from version 8.9.3 to 9.2 of Spire.Office, the issue has been resolved.

However, I believe I may have miscommunicated initially.
I had expected that the ResourceName would be entered as alternate text for the Word document, but in reality, it was not the case.

Previously, using Spire.Word, I was able to select a specific image as alternate text as follows:
Code: Select all
foreach (Paragraph docin in paragraphs) {
    foreach (DocumentObject obj in docin.ChildObjects) {
        if (obj.DocumentObjectType == DocumentObjectType.Picture) {
            DocPicture picture = obj as DocPicture;
            if (picture.AlternativeText == altTextName) {
                ... //My work
            }
        }
    }
}


Now, I want to work with Spire.Pdf instead of Spire.Word.
Assuming have a Word file with images containing specified alternate text and I converted it to PDF using Spire.Word,
Is it possible to identify specific images in a converted PDF file by their alt text that existed in Word?

Sungkyu_min
 
Posts: 36
Joined: Fri Jan 07, 2022 5:53 am

Fri Mar 08, 2024 9:51 am

Hello,

Thank you for your feedback.
We regret to inform you that Spire.PDF does not support the specific functionality you mentioned. Additionally, after converting a Word document to PDF, the PDF file will not retain the "AlternativeText" property from the Word document.
If you have any further questions or require assistance with any other features, please feel free to let us know.
Thank you for your understanding.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF