Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon Mar 07, 2022 4:50 am

Hi Team

Please let me know 1. how to check paragraph has icon ,image or shapes
2.If paragraph has these contents ,then how to fetch it from paragraph (need to extract only icons or images).
3.in another case I have to extract only text(exclude image ,shapes or icons)


I have attached screenshot for your reference

Thanks in advance
Last edited by pr20080798 on Wed Mar 09, 2022 6:12 am, edited 1 time in total.

pr20080798
 
Posts: 146
Joined: Wed Jan 20, 2021 1:15 pm

Mon Mar 07, 2022 8:20 am

Hello,

Thank you for your inquiry.
Please refer to the attached code to achieve your needs. If the code does not meet your needs, please provide your sample Word file so that we can better provide sample code that meets your needs. You could attach it here or send it to us via email (support@e-iceblue.com). Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

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

Wed Mar 09, 2022 7:06 am

Hi Team ,

Thank you for your response.

After Extracting the image from paragraph I will generate the URL of extracted image in my code .My requirement is I need to replace URL in the place of image(in exact location of image) . Image should be removed.
In final output only text should be there(paragraph text + URL of images).

Please let me know the solution for this requirement.

Thanks in advance.

pr20080798
 
Posts: 146
Joined: Wed Jan 20, 2021 1:15 pm

Wed Mar 09, 2022 9:01 am

Hello,

Thanks for your feedback.
Please refer to the attached code to achieve your needs. If the code does not meet your needs, please provide your input Word file and your expected result file so that we can better provide sample code that meets your needs. You could attach them here or send them to us via email (support@e-iceblue.com). Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

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

Mon Mar 28, 2022 5:48 pm

Hi Team

//MyCode
StringBuilder input = new StringBuilder(paragraph.getText());
for(int k = 0;k<paragraph.getChildObjects().getCount();k++) {
if(paragraph.getChildObjects().get(k).getDocumentObjectType() == DocumentObjectType.Picture) {
DocumentObject imageObj = paragraph.getChildObjects().get(k);

String imageUrl = handleImage(imageObj, tempFilePath, imageIndex, attachId, accountId, mongoJdaoImpl);

int imageIndex = paragraph.getChildObjects().indexOf(imageObj);}

After getting an index of imageObject from the Paragraph object,I have to insert imageUrl in the input Variable at Particular position( same position i refer in paragraph object).I tried to insert imageurl in input variable based on the imageIndex value but image is not inserting at right position as paragraph.getChildObjects().indexOf(imageObj) and input.insert(imageIndex) are not matching.

Is it possible to convert string into Paragraph Object to insert imageURL at right Place?


OR

int imageIndex = paragraph.getChildObjects().indexOf(imageObj);

how to get the preString and PostString of image Object

Tried with the below code .Unfortunately I am getting single character instead of complete text

int imageIndex = paragraph.getChildObjects().indexOf(imageObj);
DocumentObject documentObject = paragraph.getChildObjects().get(imageIndex);
Paragraph preText = (Paragraph)documentObject// getting Single character
DocumentObject documentObject = paragraph.getChildObjects().get(imageIndex);
Paragraph preText = (Paragraph)documentObject//

pr20080798
 
Posts: 146
Joined: Wed Jan 20, 2021 1:15 pm

Tue Mar 29, 2022 3:21 am

Hello,

Thanks for your feedback.
I simulated a word file and did an initial test with the code you provided, but didn't reproduce the issue you mentioned. I have attached my test project (see attachment). Please download and test it on your side. If the issue still exists after testing, please provide the following information for further investigation. You could attach them here or send them to us via email (support@e-iceblue.com). Thanks in advance.
1) Your input word file.
2) The result file you expect.
3) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).
4) The JDK version you use, such as JDK jdk1.8.0.

Sincerely,
Annika
E-iceblue support team
User avatar

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

Return to Spire.Doc