I am using aspose PDF version 19. and i am facing problem with generating PDF using HtmlFragment. In Our application , we are using external css and images, but external css styles are not apply on generated PDF. is there any solution for the same.
below is my code snippet.
or any other solution with Aspose Html or aspose Words.
com.aspose.pdf.Document doc = new com.aspose.pdf.Document();
PageInfo pageInfo = new PageInfo();
HtmlLoadOptions options = new HtmlLoadOptions(baspath);
options.CustomLoaderOfExternalResources = new LoadOptions.ResourceLoadingStrategy() {
@Override
public LoadOptions.ResourceLoadingResult invoke(String resourceURI) {
LoadOptions.ResourceLoadingResult res = new LoadOptions.ResourceLoadingResult(new byte[] {});
// Return empty byte array in case i.imgur.com server
res.LoadingCancelled = true;
return res;
}
};
pageInfo.setHeight(PageSize.getA4().getHeight());
pageInfo.setWidth(PageSize.getA4().getWidth());
com.aspose.pdf.Page page = doc.getPages().add();
options.setPageInfo(pageInfo);
HtmlFragment htmlFragment = new HtmlFragment(file);
htmlFragment.setHtmlLoadOptions(options);
htmlFragment.setHorizontalAlignment(HorizontalAlignment.Left);
page.getParagraphs().add(htmlFragment);
doc.save("report.pdf");