Save html to pdf issue not fixed.
I’m using the Html Fragment to save the Html sentence as pdf.
The HTML body contains data in a table format.
The problem is that the file size stored on the server is different.
I distributed it from 2 servers with the same source.
I have two development environments.
Local : Windows OS > Tomcat Server
Servers: Linux OS > JEUS Server
The test results are as follows
- local: pdf file size = 528kb
- server : pdf file size = 31mb
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);
doc.optimizeResources(optimizationOptions);
doc.save(“C:/A.pdf”, options);
@OH_JUNG_EUN
The issue you’re experiencing with the significant difference in PDF file sizes between your local Windows environment and the Linux server could be attributed to several factors. Here are some potential reasons and solutions to consider:
-
Font Handling: Ensure that the font you are using is available and correctly configured on both environments. If the font is not found on the Linux server, Aspose might be substituting it with a default font, which can lead to increased file size. Verify that the font file is accessible and correctly referenced in your code.
-
HTML Content: The complexity of the HTML content being converted can also affect the file size. If the HTML contains large images or complex styles, it may result in larger PDF files. Check if there are any differences in the HTML content being processed on both environments.
-
Optimization Settings: You are already using optimization options in your code. Ensure that these settings are applied correctly on the Linux server. You might want to experiment with different optimization settings to see if they have an impact on the file size.
-
Library Version: Ensure that both environments are using the same version of the Aspose.PDF library. Differences in library versions can lead to variations in how content is processed and saved.
-
Server Configuration: The configuration of the JEUS server on Linux might differ from your local Tomcat server. Check for any server-specific settings that could affect the PDF generation process.
Here’s a snippet of your code with the optimization options highlighted:
PdfSaveOptions options = new PdfSaveOptions();
OptimizationOptions optimizationOptions = new OptimizationOptions();
optimizationOptions.setAllowReusePageContent(true);
optimizationOptions.setLinkDuplcateStreams(true);
optimizationOptions.setRemoveUnusedObjects(true);
optimizationOptions.setRemoveUnusedStreams(true);
doc.optimizeResources(optimizationOptions);
doc.save("C:/A.pdf", options);
Make sure that the optimization options are being applied correctly in both environments. You may also want to log the size of the generated PDF files at different stages of the process to identify where the size increase occurs.
If the problem persists, consider reaching out to Aspose support with detailed information about your environments and the specific HTML content being processed. This will help them provide more targeted assistance.
If you have any further questions or need additional help, feel free to ask!