Page 1 of 1

HTMLsettings setting images dir

PostPosted: Thu Apr 14, 2011 4:41 pm
by nhanus09
Hi all. Having a small issue with docx to html. while conversion is very cclean I am having trouble setting the images dir in case the docx file contains images.
I CAN set it, the issue is that in the html src it uses a relative url not absolute.

my dir struct is:

ClientAccess
|_Doc viewer.jsp -- this is the page the displays the html
|_file_images -- this folder contains the folders that contain the images

file_images
|_1381_files -- in here are the files for doc 1381
|_2353_files -- in here files for 2352
etc....

in the html source the path to the image looks like src=1381_files\image1.jpg .... etc...
i need it to say this: file_images\1381_files\image1.jpg etc...

http://dev.plutext.org/trac/docx4j/brow ... a?rev=1096

the class is just taking the last / and using that to start the path

my jsp page is here: http://67.76.184.81/ClientAccess/ajax_p ... idnum=1382

NOTE: i cannot move the page that renders the html inside the file_images folder, I am sending the output directly to the output stream so there
is no physical html file on the server.

i jsut need to append file_images to the htmlSettings.setImageDirPath(file_images_path);
but my guess this is not currently supported, as the exporter uses a relative path
mabey i can just modify the XSLT?

--- code snippet ---
if(document_rs.next())
{
// get the file
input_file = new File(input_file_path + document_rs.getString("FULL_FILE_NAME"));
file_images_path += document_rs.getString("DOC_N_VOCGID") + "_files";

// Exporter Settings
htmlSettings.setImageDirPath(file_images_path);
//htmlSettings.setUserBodyTop("<H1>TOP!</H1>");
//htmlSettings.setUserBodyTail("<H1>TAIL!</H1>");

// check that the file exists
if(input_file.exists())
{
// Set the headers
OutputStream http_os = response.getOutputStream();

// load the template document
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(input_file);

// the HTML converter
AbstractHtmlExporter exporter = new HtmlExporterNG2();

// string writer
StreamResult result = new StreamResult(http_os);

// send the html data to output stream
exporter.html(wordMLPackage, result, htmlSettings);

// setup the responce
response.setHeader("Pragma","no-cache"); // HTTP 1.0
response.setDateHeader ("Expires", 0); // prevents caching
response.setContentType("text/html; charset=UTF-8"); // content type
response.setCharacterEncoding("UTF-8"); // encoding

// send the data
http_os.flush();
http_os.close();
}
else
{
out.print("There was an error generating the preview...");
}
}
else
{
out.print("There was an error generating the preview...");
}

thanks

Re: HTMLsettings setting images dir

PostPosted: Fri Apr 15, 2011 4:53 am
by nhanus09
so in further research.. i found these lines in the XSLT
calling either org.docx4j.model.images.WordXmlPictureE20.createHtmlImgE20()
or org.docx4j.model.images.WordXmlPictureE20.createHtmlImgE10()
im thinking abt modifying these methods to allow 2 paths
1. the file_sys_path currently implemented
2. the html_src_path -> path from webroot or absolute path to image dir

suggestions ?

<xsl:choose>
<!-- sanity check -->
<xsl:when test="./a:graphic/a:graphicData/pic:pic">

<xsl:copy-of select="java:org.docx4j.model.images.WordXmlPictureE20.createHtmlImgE20(
$wmlPackage,
string($imageDirPath),
$wpinline)" />
</xsl:when>
<xsl:otherwise>

<xsl:copy-of select="java:org.docx4j.convert.out.html.NtmlExporterNG2.notImplemented(., ' without pic:pic ' )" />
</xsl:otherwise>
</xsl:choose>