We are facing issue if the image path contains (secure) https protocol .
Just an FYI …same code works fine with http protocol.
Here is a part of code:-
doc.getMailMerge().execute(new String[] {“userImage”},
new Object[] {“https://a.imeetbeta.net/san/users/000/000/032/521/user_avatar.jpg”});
// Save the document in Word format.
// }
outputStream=new java.io.ByteArrayOutputStream();
doc.save(outputStream, com.aspose.words.SaveFormat.RTF);
end = System.currentTimeMillis();
The following error we are getting:-
Error …Cannot load image from field ‘userImage’. The field contains data in unsupported format. sun.security.validator.
ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: basic constraints check
failed: pathLenConstraint violated - this cert must be the last cert in the certification path
Please let me know if any thing we need to set to support https to avoid this error.
Need urgent help on this…please advice us…
Hello
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thanks for your request. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved. This issue does not occur in NET version of Aspose.Words. Once we finish synchronization Java and .NET versions of Aspose.Words, all functionality which is supported in, NET version will be supported in Java version, including the fix of this issue. Hopefully it will be somewhere at the end of this month or at the beginning of the next month. You will be notified.
Best regards,
The issues you have found earlier (filed as 19534) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.
We are happy to inform you that the first auto-ported version of Aspose.Words for Java is ready. This version supports converting documents to PDF. You can get it from here.
Best regards,
Aspose.Words team
(61)
I’m moving an app from Aspose.Words for Java v4.0.2 to v10.1.0. I was having a problem with converting an HTML documents with https image URLs to Word document with v4.0.2. Would this same fix likely apply to my problem?
Hi Matt,
Thanks for your request. Both issues you have reported earlier are resolved. So please try using the latest version of Aspose.Words for Java and let us know in case of any issues.
Best regards,
Thanks Andrey. I’ll try it out in the next few days.
Sadly, that didn’t help. I have a simple HTML page with an https image reference and when Aspose builds a Word doc, the image is missing. Should I post stuff here or start a new post/thread?
Hi Matt,
Thank you for additional information. I suppose this is not Aspose.Words issue but permissions issue. Aspose.Words just does not have rights to download the images and that is why the problem occurs. However, since, Aspose.Words supports base64 as image source, you can create your own method to get images and replace image path in src attribute with base64 representation of the image. Here is a very simple code that demonstrates the technique:
[Test]
public void Test001()
{
// Get Html string.
string html = File.ReadAllText(@"Test001\in.html");
// Create a regular expression that will help us to find image SRCs.
Regex urlRegex = new Regex("src\\s*=\\s*[\"']+(http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?)[\"']+");
// Serch for SRCs.
MatchCollection matchs = urlRegex.Matches(html);
foreach (Match match in matchs)
{
// Replace urls with embedded base64 images.
html = html.Replace(match.Groups[1].Value, GetBase64(match.Groups[1].Value));
}
// Now you can insert HTML into the document. All images are embedded into the HTML string.
DocumentBuilder builder = new DocumentBuilder();
builder.InsertHtml(html);
builder.Document.Save(@"Test001\out.doc");
}
private string GetBase64(string imageUrl)
{
string base64Data = "";
try
{
// Prepare the web page we will be asking for
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(imageUrl);
request.Method = "GET";
request.ContentType = "image/jpeg";
request.UserAgent = "Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0";
// Execute the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//We will read data via the response stream
Stream resStream = response.GetResponseStream();
//Write content into the MemoryStream
BinaryReader resReader = new BinaryReader(resStream);
// Build base64 string.
base64Data = string.Format("data:image/jpeg;base64,{0}",
Convert.ToBase64String(resReader.ReadBytes((int)response.ContentLength)));
}
catch (Exception)
{
}
return base64Data;
}
I hope such approach could help you to achieve what you need.
Best regards,
Hi
Thank you for additional information. There must be something on your side. I can successfully insert an image from HTTPS location. For example, see the following code:
DocumentBuilder builder = new DocumentBuilder();
builder.insertHtml("<img src='https://encrypted.google.com/images/logos/ssl_logo_lg.gif' />");
builder.getDocument().save("C:\\Temp\\out.doc");
Could you please try running this code on your side? Do you see the image in the output document?
Best regards,
Hi Matt,
Thanks for your inquiry.
Have you tried opening the image locally to see if it works? Perhaps the image itself cannot be viewed by the browser. It would be a good bet to try a different browser to see if this is case as well.
Thanks,
Reasonable questions. Yup, it works fine if I just paste the image URL into a browser, even when it’s a separate one in which I’ve never logged into the webapp. I access our app in Firefox but tested the image URL in Chrome.
Hi Matt,
Thank you for additional information. Will I be able to view these image on my side? If so could you please provide one or few urls to the images? I will check on my side and provide you more information.
Best regards,
Hi Alexey,
Hi
Thank you for additional information. Have you tried using code like the following to get the image from url:
// Here you should put an url to your image.
String imageUrl = "https://encrypted.google.com/images/logos/ssl_logo_lg.gif";
String outFileName = "C:\\Temp\\out.png";
BufferedImage image = ImageIO.read(new URL(imageUrl));
ImageIO.write(image, "png", new File(outFileName));
Can this code get an images form your urls?
Best regards,
Hi Matt,
Thank you for additional information. It is perfect that the code suggested you a place where the reason of the problem lies. Please feel free to ask in case of any issues, we are always glad to help you.
Best regards,
I did a Google search for “PKIX path building failed” and found out that it might work to add the self-signed cert used for HTTPS to the JVM’s trust store, but several people hadn’t had much luck with that approach. Fortunately, in my case, I was able to figure out an acceptable way to use HTTP instead of HTTPs, rather than addressing the underlying problem. In contrast, a different library we use to convert HTML to PDF is able to access the same images with no issues. Although I don’t need a fix in Aspose.Words at this time, it might be worth further investigation at some point.