It didn’t work out the way you told me.
File size different.same save results
We tested it in two ways, but all failed
#. Test 1
Document doc = new Document();
Page page = doc.getPages().add();
PageInfo pageInfo = new PageInfo();
pageInfo.setMargin(new MarginInfo(10, 10, 10, 10));
page.setPageInfo(pageInfo);
HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions();
HtmlFragment htmlFragment = new HtmlFragment(“…”);
htmlFragment.setHtmlLoadOptions(htmlLoadOptions);
// Set the font from the project
TextState textState = new TextState();
Font font = FontRepository.openFont(“font file”);
textState.setFont(font); // Use the font name if it’s in the project resources
htmlFragment.setTextState(textState);
page.getParagraphs().add(htmlFragment);
/*
- I configured the page to put html of PDF 1 page content,
- I’m going to generate a total of three page html
*/
PdfSaveOptions options = new PdfSaveOptions();
doc.optimize();
doc.save(“C:/A.pdf”, options);
#. Test 2
Document doc = new Document();
Page page = doc.getPages().add();
PageInfo pageInfo = new PageInfo();
pageInfo.setMargin(new MarginInfo(10, 10, 10, 10));
page.setPageInfo(pageInfo);
HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions();
HtmlFragment htmlFragment = new HtmlFragment(“…”);
htmlFragment.setHtmlLoadOptions(htmlLoadOptions);
// Set the font from the project
TextState textState = new TextState();
Font font = FontRepository.openFont(“font file”);
textState.setFont(font); // Use the font name if it’s in the project resources
htmlFragment.setTextState(textState);
page.getParagraphs().add(htmlFragment);
/*
- I configured the page to put html of PDF 1 page content,
- I’m going to generate a total of three page html
*/
PdfSaveOptions options = new PdfSaveOptions();
OptimizationOptions optimizationOptions = new OptimizationOptions();
optimizationOptions.setAllowReusePageContent(true);
optimizationOptions.setLinkDuplcateStreams(true);
optimizationOptions.setRemoveUnusedObjects(true);
optimizationOptions.setRemoveUnusedStreams(true);
ImageCompressionOptions imageCompressionOptions = new ImageCompressionOptions();
imageCompressionOptions.setCompressImages(true);
imageCompressionOptions.setImageQuality(10);
optimizationOptions.setImageCompressionOptions(imageCompressionOptions);
doc.optimizeResources(optimizationOptions);
doc.save(“C:/A.pdf”, options);