Aspose Pdf uses two ways to optimize PDF file size

@sumeetm

We regret to inform that no update is available at the moment regarding ticket(s) resolution. As shared earlier, we will surely inform you once they are completely investigated and rectified. We highly appreciate your patience and cooperation in this matter. Please give us some time.

We really apologize for the inconvenience and delay.

Hi @asad.ali,

Can you please check engineering team and provide us an update on this issue?

Thanks

@sumeetm

We would like to share with you that both tickets have been scheduled for fix in 21.4 version of the API which will be released in April 2021. We will post a notification in this thread as soon as the fixed-in version is available.

We apologize for the delay and inconvenience faced.

@rnara

We have investigated the logged ticket PDFJAVA-39802. Regretfully, we do not have a way to convert a CFF font with a negative glyph width from PDF to a Subset TrueType font at the moment.
The same problem was tested for the same input file in another issue PDFJAVA-39405. Please do not use the following option if document uses CFF font with a negative glyph width:

optimizationOptions.setSubsetFonts(true); 

Hi @asad.ali,

Do we have any update on this?

@rnara

We are afraid that the ticket PDFJAVA-39801 is not yet resolved. It is under the phase of investigation and as soon as we have additional updates regarding its resolution, we will share with you. Please give us some time.

We are sorry for the inconvenience.

Hi @asad.ali,

We are implementing the shared code now with exposing option to enable/disable the functionalities like SetSubsetFonts, SetRemoveUnusedStream, RemoveUnusedObjects.

Earlier I raised a query asking about functionality of each of the mentioned parameters. As it was mentioned by you earlier that OptimizeFileSize and OptimizationOptions.SubsetFonts has same functionality i.e applying font subsets to fonts used in the doc.
So, I tried testing the shared code, once with only PdfFormatConversionOptions.optimizeFileSize(true) and got this result :OptimizeFileSize.pdf (1.1 MB) where texts are scattered and are not in actual place.

for second time I tried with enabling only OptimizationOptions.setSubsetFont(true) and output was fine. SetSubsetFonts.pdf (1.1 MB)

Also, Output file sizes are different for both of them.

  1. Can you please explain the reason behind the difference?
  2. And, is there any dependency of one on the another?

Thanks,
Avinash.

@rnara

Can you please also share the respective source PDF document with us so that we can test the scenario in our environment and address it accordingly.

Please find the input pdf file below:
T-PVS-DE(2018)11.pdf (1.2 MB)
Respective input docx file as well
T-PVS-DE(2018)11.docx (175.7 KB)

Thanks,
Avinash.

@rnara

We tested the scenario while using 21.5 version of the API and did not notice any issue in output PDF documents. However, the size of the output PDF was 14MB in both cases. We will further investigate and address this issue. Please confirm if you are using the same code as shared below? Please also test with 21.5v before sharing your feedback.

Document doc = new Document(dataDir + "T-PVS-DE(2018)11.pdf");
PdfFormatConversionOptions options = new PdfFormatConversionOptions(PdfFormat.PDF_A_1A, ConvertErrorAction.Delete);
options.setOptimizeFileSize(true);
doc.convert(options);

doc.save(dataDir + "optimizefilesize.pdf");

doc = new Document(dataDir + "T-PVS-DE(2018)11.pdf");
PdfFormatConversionOptions opts = new PdfFormatConversionOptions("logFile.Txt", PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);
doc.convert(opts);
com.aspose.pdf.optimization.OptimizationOptions optimizationOptions = new com.aspose.pdf.optimization.OptimizationOptions();
optimizationOptions.setSubsetFonts(true);
doc.optimizeResources(optimizationOptions);
doc.save(dataDir + "subsetfonts.pdf");

Hi @asad.ali,

Looks like there is some misunderstanding from your end, My query is totally different.

As you have explained here,

In our existing code we have used optimizeFileSize for Optimization purpose. Now we are implementing the new code with class OptimizationOptions.
So, While testing the code, as per your mention:

“OptimizeFileSize is applying font subsets to fonts used in the document.I.e. this is the same as OptimizationOptions.SubsetFonts”

I was using OptimizefileSize instead of OptimizationOptions.SubsetFonts and got this output OptimizeFileSize.pdf (1.1 MB) where texts are scattered.

Code:

com.aspose.pdf.Document doc = new com.aspose.pdf.Document("C:\\Users\\Administrator\\Desktop\\New folder\\AsposePDFATest\\Test5.pdf");
PdfFormatConversionOptions opts = new PdfFormatConversionOptions("C:\\Users\\Administrator\\Desktop\\New folder\\AsposePDFATest\\logFile.Txt", PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);
opts.setConvertSoftMaskAction(ConvertSoftMaskAction.ConvertToStencilMask);
opts.setOptimizeFileSize(true);
doc.convert(opts);

OptimizationOptions optimizationOptions = new OptimizationOptions();
//optimizationOptions.setSubsetFonts(true);
optimizationOptions.setRemoveUnusedStreams(true);
optimizationOptions.setRemoveUnusedObjects(true);
doc.optimizeResources(optimizationOptions);

doc.save("C:\\Users\\Administrator\\Desktop\\New folder\\AsposePDFATest\\OutputPDFA.pdf");

But on using OptimizationOptions.SubsetFonts, It worked fine: SetSubsetFonts.pdf (1.1 MB)

Code Used:

com.aspose.pdf.Document doc = new com.aspose.pdf.Document("C:\\Users\\Administrator\\Desktop\\New folder\\AsposePDFATest\\Test5.pdf");
PdfFormatConversionOptions opts = new PdfFormatConversionOptions("C:\\Users\\Administrator\\Desktop\\New folder\\AsposePDFATest\\logFile.Txt", PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);
opts.setConvertSoftMaskAction(ConvertSoftMaskAction.ConvertToStencilMask);
//opts.setOptimizeFileSize(true);
doc.convert(opts);

OptimizationOptions optimizationOptions = new OptimizationOptions();
optimizationOptions.setSubsetFonts(true);
optimizationOptions.setRemoveUnusedStreams(true);
optimizationOptions.setRemoveUnusedObjects(true);
doc.optimizeResources(optimizationOptions);

doc.save("C:\\Users\\Administrator\\Desktop\\New folder\\AsposePDFATest\\OutputPDFA.pdf");

So, My queries are:

  1. Can you please explain the reason behind the difference?
  2. And, is there any dependency of one on the another?

Thanks,
avinash.

@rnara

We totally understood your query and had tested the scenario in our environment using both ways i.e.:

  • used OptimizefileSize instead of OptimizationOptions
  • used only OptimizationOptions.SubsetFonts

However, at our end, we obtained similar output PDFs for both cases. Text was not scattered in any of the obtained output PDF. Please also note that there was no other dependency which was added at our end.

The only difference we noticed was that the size of PDF outputs (in both cases) was bigger than the source PDF. Hence, we requested you to test the case using 21.5 version and confirm if you are also noticing the same behavior as we did so that we can further proceed to assist you accordingly. In case we still missed something, please let us know.

Hi @asad.ali ,

Please try with the shared code from here, you will find the issues as i mentioned:

You have just tried with

optimizationOptions.setSubsetFonts(true);

Or

opts.setOptimizeFileSize(true);

Please add optimizationOptions.
> setRemoveUnusedStreams(true);
> optimizationOptions.setRemoveUnusedObjects(true);
as well and test. setOptimizeFileSize.pdf (1.1 MB)

I have tested it wit Aspose.PDF 21.5.

Thanks,
avinash.

@rnara

We were now able to reproduce the similar behavior which you mentioned by using Aspose.PDF for Java 21.5. Therefore, an investigation ticket as PDFJAVA-40575 has been logged in our issue tracking system for the sake of correction. We will let you know once the ticket is resolved. Please give us some time.

We are sorry for the inconvenience.

Hi @asad.ali,

Did you get any information from developers on this?

@rnara

The ticket has just been logged and an initial investigation is not yet performed against it. As soon as the ticket is investigated, we will be able to share some details about why API is showing this behavior. Please give us some time.

This issue has been opened for quite so long and customer is not at all satisfied with the resolution given. Please share the required information as early as possible. We cant keep them on hold for so long.

Thanks,
Avinash.

@rnara

Please accept our humble apology for the inconvenience being faced due to this issue. We have recorded your concerns and will surely consider them during investigation. We will schedule and resolve the ticket on first come first serve basis and let you know once an update is available about its resolution.

Hi @asad.ali,

Any update now?

@rnara

The earlier logged ticket is under the phase of investigation at the moment. As we shared earlier, it will surely be resolved on a first come first serve basis. As soon as the investigation of the ticket is done, we will be updating you in this forum thread regarding its fix ETA. We highly appreciate your patience and comprehension in this regard.

We apologize for the inconvenience.