Hi,
I am converting html to PDF using Aspose word. The image is not displayed in the pdf when convert the html to PDF. We can see the same image in the html preview just before the conversion so I can verify that the image is getting rendered.
Below is the sample code that I use to get the image
One more point is that we are not able to reproduce this problem in the non- SSL environment.
Kashif
Hi Kashif ,
Thanks for your query. It would be great if you please share your HTML file for investigation purposes.
Please find attached the sample zip file
Hi Kashif ,
Thanks for sharing the document. I am unable to access the following image URL in browser. Please share the html file to which you can see the image.
I will not be able to provide you with that, as this URL is not accessible outside the company network
Hi Kashif ,
Thanks for sharing the information. Please use the following configuration settings in your application. Hope this helps you. Let us know if you have any more queries.
<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
</configuration>
HttpWebRequestElement webRequestSettings = new HttpWebRequestElement();
webRequestSettings.UseUnsafeHeaderParsing = true;
I don’t think that this will work for me as I am using Java
Hi Kashif,
Please accept my apologies for your inconvenience.
It would be great if you please share your complete scenario along with working enviornment like Operating System, JDK version etc. Are you accessing image URL over local network?
Hi,
I am using Java 1.6, Windows 7 and the application is deployed on apache Tomcat. We are using Aspose.Words to convert some html content to PDF.
With aspose version 10.6 I used to get a small cross instead of the email, but since the time we have upgraded the to aspose 11.6 we are getting NullPointerException when doc.getPageCount() is called. I have also verified that the doc is not null. This is happening only when I have the img tag in the html.
I have also noticed that with aspose words 11.6 this is working with the images that are accessible over the internet, but it is throwing NullPointerException with the images that the accessible in the local network. I dont know why it should happen because I am very sure that even these images are accessible from the application server.
Kashif
Hi Kashif,
Thanks for sharing the information. We are working over you query and will update you asap.
Hi Kashif,
I have tested the scenario and have not found any issue while using latest version of Aspose.Words for Java. Please see the attached input and output files.
I have modified the IMG tag as follow and can access image over local network.*
Can you please explain details of html preview at your side?
We can see the same image in the html preview just before the conversion so I can verify that the image is getting rendered.
I think that the only difference that I can see it that the link that I am using is SSL
Regarding the preview I can see the preview before conversion to PDF in a Rich text Editor. It is similar to the one you guys are using for this response
Hi Kashif,
I have tested the scenario for SSL and have not found any issue. Please find the sample.html and output PDF/Docx in attachment. It seems that the image is blocked by Firewall in your local network.
Hope this answers your query. Please let us know if you have any more queries.
I am not sure why it is happening for me then. I have attached the sample HTML for which I am getting and error.
Please let me know it this still works for you
Hi Kashif,
Thanks for sharing the details. It would be great if you please create a sample Java application with following code snippet and share the output file with us. I have attached the output file generated at my end with this post.
Document doc = new Document(MYDir + "sample.html");
doc.save(MYDir + "AsposeOut-Java.docx");
I am using the code that is somewhat different. Below is the code, Please let me know if there is something wrong with this.
InputStream inputStream = null;
ByteArrayOutputStream outputStream = null;
try
{
inputStream = new ByteArrayInputStream(html.getBytes()); //Read the string into bytes.
initializeAspose(); // Initialize the Aspose library license.
LoadOptions loadOptions = new LoadOptions();
loadOptions.setLoadFormat(LoadFormat.HTML);
Document doc = new Document(inputStream, loadOptions); //Get the document instantiated.
// TrueTypeFontsFolder should contain fonts, which are using
// in your document. At least this folder should contain one
// valid TrueType font(Arial and Times New
// Roman, for example) and specify this folder as
// TrueTypeFontsFolder.This is needed otherwise conversion on UNIX platform fails
FontSettings.setFontsFolder(getFontsFolder(), false);
int startPage = 0;
int endPageNumber = doc.getPageCount();
outputStream = new ByteArrayOutputStream();
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setPageCount(endPageNumber);
saveOptions.setPageIndex(startPage);
doc.save(outputStream, saveOptions);
return outputStream.toByteArray(); //Return byte array from output stream.
}
catch (Exception e)
{
logger.error("Error in creating the document: %s, threw exception %s", html, e);
}
finally
{
JavaUtils.closeWithoutException(inputStream);
try
{
outputStream.flush();
}
catch (IOException e)
{
outputStream = null;
}
}
Hi Kashif,
Thanks for sharing the code. I have tested the same code at following enviornment. Please find the output PDF in attachment. I have also attached the JSP file code with this post.
Windows 7
Java 1.6
Apache Tomcat 7.0.11
Please execute the following code at your end and share your findings with us.
Document doc = new Document(MYDir + "sample.html");
doc.save(MYDir + "AsposeOut-Java.pdf");