We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Missing fonts during Pdf to Html conversion

Hi there,


I’am using aspose in a JEE environment on linux to convert several different file types to a pdf. Which is working fine. We also generate a preview of the pdf to html which is shown to the user in its browser.

The number of fonts are limited on our linux server. When converting the pdf to html we get a exception stating that the font is missing (e.g. Courier New). Is there a possibility to not include fonts in the generated html so these fonts are not necessary on the linux server (in the browser these fonts are available)? I expect they are not necessary because when I convert documents to pdf and pdf’s to an image I do not get errors. (The fontsavingmode does not contain a mode to leave the fonts out).


Conversion code:

public String convertPdfToHtml(File pdfFile) {
// Open document
Document doc = new Document(new BufferedInputStream(new FileInputStream(pdfFile)));
//tune conversion parameters
HtmlSaveOptions newOptions = new HtmlSaveOptions();
newOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
newOptions.FontSavingMode = HtmlSaveOptions.FontSavingModes.SaveInAllFormats;
newOptions.PartsEmbeddingMode = HtmlSaveOptions.PartsEmbeddingModes.EmbedCssOnly;
newOptions.LettersPositioningMethod = LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;
newOptions.setSplitIntoPages(false);// force write HTMLs of all pages into one output document
newOptions.CustomHtmlSavingStrategy = new HtmlSaveOptions.HtmlPageMarkupSavingStrategy() {

@Override
public void invoke(com.aspose.pdf.HtmlSaveOptions.HtmlPageMarkupSavingInfo htmlSavingInfo) {
byte[] resultHtmlAsBytes = new byte[(int) htmlSavingInfo.ContentStream.getLength()];
htmlSavingInfo.ContentStream.read(resultHtmlAsBytes, 0, resultHtmlAsBytes.length);
try {
resultPdfToHtml = new String(resultHtmlAsBytes, “UTF-8”);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
};
};
//we can use some non-existing file name -
// all real saving will be done in CustomerHtmlSavingStrategy
String outHtmlFile = “SomeUnexistingFile.html”;
doc.save(outHtmlFile, newOptions);
return resultPdfToHtml;
}

Hi Gerard,


Thanks for your inquiry. We have logged an enhancement ticket PDFNEWJAVA-35745 for your requirement to not include fonts in PDF to HTML conversion in our issue tracking system. We will keep you updated about the issue resolution progress within this forum thread.

We are sorry for the inconvenience.

Best Regards,

The issues you have found earlier (filed as PDFJAVA-35745) have been fixed in Aspose.PDF for Java 18.7.