Hi,
I’am using aspose to convert html to a pdf. What I like to have is that I get information on missing resources during the conversion of the html. For example when a image is not available I like to have a notification that the image is not available. Via for example a callback or an exception. Is that possible?
With kind regards,
Gerard
package test.aspose;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import com.aspose.pdf.Document;
import com.aspose.pdf.HtmlLoadOptions;
import com.aspose.pdf.SaveFormat;
public class AsposeHtmlConvertorMain {
public static void main(String[] args) throws IOException {
File fileExistingImage = create(“C:/temp/resultExistingImage.pdf”);
File fileNoneExistingImage = create(“C:/temp/resultNotExistingImage.pdf”);
convert(“test
test
<img src=“http://www.ohra.nl/images/logo-ohra_tcm66-219852.jpg”>”, fileExistingImage);
// I like to have an exception or some callback to inform me that a mentioned file in the html is not available.
convert(“test
test
<img src=“http://www.ohra.nl/images/logo-ohra_xx_tcm66-219852.jpg”>”, fileNoneExistingImage);
}
private static void convert(String inputHtml, File pdfOutputFile) throws IOException {
InputStream htmlInputStream = new ByteArrayInputStream(inputHtml.getBytes());
convert(htmlInputStream, pdfOutputFile);
htmlInputStream.close();
}
private static void convert(InputStream htmlInputStream, File pdfOutputFile) {
Document doc = new Document(htmlInputStream, new HtmlLoadOptions());
doc.save(pdfOutputFile.getAbsolutePath(), SaveFormat.Pdf);
}
private static File create(String name) {
File result = new File(name);
if (result.exists()) {
result.delete();
}
return result;
}
}