PDF files in single HTML with stream

Dear Aspose Team,

As far as I see there is an option to save PDF files in single HTML.
But I need to convert PDF files in single HTML (all resources embedded) with stream.
Is there any examples how to do this?

Thanks

Hi Lai,


Thanks for your inquiry. You can convert PDF document to HTML with embedded resources in a single stream using Aspose.Pdf for Java. Please check following documentation link for reference, it will help you to accomplish the task.


Please feel free to contact us for any further assistance.

Best Regards,

Hello Tilal,
Thank you for your response. I tried to use this example, but without success.

I got the following exception:

Inconsistent saving options detected : 'CustomStrategyOfCssUrlCreation','CustomCssSavingStrategy','CustomResourceSavingStrategy' may not be null when requested saving to stream!

And here is my code:
HtmlSaveOptions htmlSaveOps = new HtmlSaveOptions();
htmlSaveOps.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
htmlSaveOps.FontSavingMode = HtmlSaveOptions.FontSavingModes.AlwaysSaveAsWOFF;
htmlSaveOps.PartsEmbeddingMode = HtmlSaveOptions.PartsEmbeddingModes.EmbedAllIntoHtml;
htmlSaveOps.LettersPositioningMethod = LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;
htmlSaveOps.setSplitIntoPages(false);
htmlSaveOps.CustomHtmlSavingStrategy = new HtmlSaveOptions.HtmlPageMarkupSavingStrategy() {
@Override
public void invoke(com.aspose.pdf.HtmlSaveOptions.HtmlPageMarkupSavingInfo htmlSavingInfo) {
// TODO Auto-generated method stub
byte[] resultHtmlAsBytes = new byte[(int) htmlSavingInfo.ContentStream.getLength()];
htmlSavingInfo.ContentStream.read(resultHtmlAsBytes, 0, resultHtmlAsBytes.length);
// here You can use any writable stream, file stream is taken
// just as example
ByteArrayOutputStream fos;
try {
fos = new ByteArrayOutputStream();
fos.write(resultHtmlAsBytes);
fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
pdf.save(outputStream, htmlSaveOps);

==================================================================

Please help me solve this problem, thanks.

Hi Lai,


Thanks for your feedback. Please pay attention when saving PDF to HTML with embedded resources in a single stream you need to pass a non-existing HTML file name in save method instead stream, original saving to stream will be done in CustomHtmlSavingStrategy as stated at the end of code snippet in documentation link.

//all real saving will be done in
CustomHtmlSavingStrategy
<o:p></o:p>

//ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

//pdf.save(outputStream, htmlSaveOps);

String outHtmlFile = "SomeUnexistingFile.html";

doc.save(outHtmlFile, newOptions);


Please feel free to contact us for any further assistance.

Best Regards,