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

Free Support Forum - aspose.com

Embed Images and CSS into HTML with Aspose PDF Java


I am trying to create an HTML with embedded images and styles with Aspose PDF Java.

I found a solution to my problem in #NET:

However, still struggling to reproduce this in Java. Is there a similar solution to my problem in Java?


Please check the below code snippet in Java to achieve similar results:

// Instantiate HTML Save options object
com.aspose.pdf.HtmlSaveOptions newOptions = new com.aspose.pdf.HtmlSaveOptions();
// Enable option to embed all resources inside the HTML
newOptions.PartsEmbeddingMode = com.aspose.pdf.HtmlSaveOptions.PartsEmbeddingModes.EmbedAllIntoHtml;

// This is just optimization for IE and can be omitted
newOptions.LettersPositioningMethod = com.aspose.pdf.LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;
newOptions.RasterImagesSavingMode = com.aspose.pdf.HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
newOptions.FontSavingMode = com.aspose.pdf.HtmlSaveOptions.FontSavingModes.SaveInAllFormats;
// Output file path
//newOptions.CssClassNamesPrefix = "p";
Document doc = new Document(dataDir + "Aspose_test_pdf.pdf");
doc.save(dataDir + "output.html", newOptions);

Thank you, this worked indeed!

1 Like