cancel
Showing results for 
Search instead for 
Did you mean: 

Reg:Convert DOCX to HTML

former_member222013
Participant
0 Kudos

Hi,

I want to convert a microsoft word document(docx) to html using code. Can anyone help me in this context ... The doc which I am trying to convert will have Bullets,bold,italic,Images etc ...

I am able to get the text but not the images and bullets ..

And also I need to convert the Whole Document whichj includes pictures,images,......etc.. to HTML as I need to embed that HTML while sending an EMAIL.

Please help me in this context

Thanks

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member761357
Discoverer
0 Kudos

Thank you for the excellent blog post on DOCX - HTML Converter. Keep it up.

former_member222013
Participant
0 Kudos

Im closing the thread as I did not get any relevant solution to the problem..

Thanks for the guys who has answered to my question.

Thanks..

.

vijay_kumar49
Active Contributor
0 Kudos
former_member222013
Participant
0 Kudos

Hi Vijay,

Thanks for the info.

I am using DOCX4J to convert the DOCX to HTML .I have successfully done the conversion and got the html format.I will be using the html format to embed it as EMAIL body to send an email.But I have some issues which are listed below....

  1. Unable to display Images in EMAIL Body
  2. Losing the Spaces and Bullets

Please find the code I used below,

WordprocessingMLPackage wordMLPackage;
wordMLPackage
= Docx4J.load(new java.io.File(resourcePath2));
HTMLSettings htmlSettings = Docx4J.createHTMLSettings();
htmlSettings
.setImageDirPath(imageFolder + resourcePath2 + "_files");
htmlSettings
.setImageTargetUri(imageFolder +resourcePath2.substring(resourcePath2.lastIndexOf("/")+1) + "_files");
htmlSettings
.setWmlPackage(wordMLPackage);

OutputStream os;
os
= new ByteArrayOutputStream();
Docx4jProperties.setProperty("docx4j.Convert.Out.HTML.OutputMethodXML", true);
Docx4J.toHTML(htmlSettings, os, Docx4J.FLAG_SAVE_FLAT_XML);
DOCX
= ((ByteArrayOutputStream)os).toString();



Please help me in this as this is very urgent.


Thanks..


govardan_raj
Contributor
0 Kudos

hi sap nw user,

htmlSettings.setImageDirPath(imageFolder + resourcePath2 + "_files");
htmlSettings
.setImageTargetUri(imageFolder +resourcePath2.substring(resourcePath2.lastIndexOf("/")+1) + "_files");

in the above code image dir(path) here the path refers to folder at your server .

for exm your server is unix based then path should be like this

/usr/sap/EPD/jc00/tmp/image/AAA_Files

if server is windows based , check with your basis team to give suitable location where you can keep your images and refer to that path

i.e at runtime your EAR is running at server, and image path or file path , it always refers to the server on which it is running. so please check that . once it is rectified then your images will appear in the HTML page .

Please go through the below link

http://stackoverflow.com/questions/9942575/sending-image-to-mail-by-java-program-without-attaching

hope it helps and sorts out your problem.

Regards

Govardan Raj

former_member222013
Participant
0 Kudos

Hi Godvardhan,

Thanks for the answer.

I got you ,but how to save the image in the j2EE server or File server ??? .Because without saving we cannot read the image ,,,\

Can you help me in saving the image at certain path and again retrieve it back from there using DOCX4j ?

Thanks you..

junwu
Active Contributor
0 Kudos

you can save it in memory.....it is basic java knowledge

former_member222013
Participant
0 Kudos

Thanks wu, I am basically not a java guy,I am an Abaper...

Can anyone please help on this..

Thanks...

govardan_raj
Contributor
0 Kudos

Hi ,

File uploadFile = new File(/usr/sap/tmp/folder +System.getProperty("file.separator")+wdContext.currentFileUploadElement().getFileName());

          

          if(!uploadFile.exists())

         {

          FileOutputStream fos = new FileOutputStream(uploadFile);

          BufferedInputStream bis = null;

          if(wdContext.currentFileUploadElement().getResource()!=null)

          {

           bis = new BufferedInputStream(wdContext.currentFileUploadElement().getResource().read(false)); 

           byte [] byteArr = new byte[bis.available()];

           bis.read(byteArr);

           fos.write(byteArr);

           fos.flush();

           fos.close();

          }

          }

here you have to create a node with attribute as Resource of type resource ... in ui element definitions you can find this.

and data attribute of type string.

insert Upload file UI element , and bind the correspoding attributes at necessary points.

Now above code you can use for uploading the image at a particular folder.

Other way is manually you can ask your basis team or if you are having the access to your server, keep the file at a suitable location and access this location as specified above...

ie.

htmlSettings.setImageDirPath(imageFolder + resourcePath2 + "_files");
htmlSettings
.setImageTargetUri(imageFolder +resourcePath2.substring(resourcePath2.lastIndexOf("/")+1) + "_files");

Regards

Govardan Raj

former_member222013
Participant
0 Kudos

Hi Govardhan,

Thnaks for the inputs.

My requirement is different.... Users will upload a DOCX ....

1.I need to save it at some place

2.Need to retireve images from DOCX and again retrieve them to use when I convert DOCX to HTML and use that HTML to send a mail as DOCX(including images) in body...

CAn you please help me in this context as this very urgent.

Thanks for your support.

junwu
Active Contributor
0 Kudos

better google

nothing to do with sap