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

Free Support Forum - aspose.com

Compression setting has no effect - v4.2.0.0

Hi,


Does this setting only work in certain circumstances? I am concatenating a group of memory streams using the following simple code.

PdfFileEditor pdfEditor = new PdfFileEditor();
pdfEditor.Concatenate(inStreams.ToArray(), outStream);
outStream.Position = 0;

I have tried setting Settings.CompressionLevel from 0 to 9 but I get no difference in file size or display for any value.

Regards,
Paul.

I’d like to expand on a previous post about the PdfFileStamp trick that worked in Aspose.Pdf.Kit v2.0.0.0 that resulted in nearly 40% compression. I can’t reproduce this in v4.2.0.0 and therefore am stuck on an old version of the dll that cannot process new files.


Using this code to get MemoryStreams and then concatenate them (this method is used rather than the filename concatenation because some files are static pdf files, some are generated via the PdfForm class, and others are generated through Aspose.Words saved as a Pdf stream).

public override MemoryStream GetStream()
{
byte[] buffer = File.ReadAllBytes(Source);
MemoryStream inStream = new MemoryStream(buffer);
inStream.Position = 0;

MemoryStream outStream = new MemoryStream();
PdfFileStamp pdfStamp = new PdfFileStamp(inStream, outStream);
pdfStamp.Close();
outStream.Position = 0;
return outStream;
}

PdfFileEditor pdfEditor = new PdfFileEditor();
pdfEditor.Concatenate(inStreams.ToArray(), outStream);
outStream.Position = 0;

I have attached examples of documents created using this method. As you can see, the v4.2.0.0 is over 2Mb larger but looks identical to the naked eye.

Not using PdfFileStamp in v2.0.0.0 results in a file slightly larger than the version produced by v4.2.0.0 (6332Kb).
Is it possible to reproduce this behaviour in a new version of the dll?

Hi Paul,

I would like to share with you that in order to compress the PDF file, it needs to be completely recreated. As in Concatenate method, one file is added to the other one but the output is not recreated so the compression level has no effect. In order to compress the output file you need to recreate it, and you can try the following code snippet for that matter:


Settings.CompressionLevel = 3;

PdfFileEditor editor = new PdfFileEditor();

editor.Concatenate(new string[] { “first.pdf”, “second.pdf” }, “result.pdf”);

PdfFileStamp stamp = new PdfFileStamp(“result.pdf”, “compressed.pdf”);

stamp.Close();


In this code snippet, once the files are concatenated to one result.pdf file, the output file is opened with PdfFileStamp and then closed; nothing added or removed from file but the file is just recreated to put CompressionLevel to work.

I would also like to add that it might not work in all scenarios; for example, if the files contain only images then the CompressionLevel will not have any effect because images can’t be compressed with this property. You can find further details on this link.

Please try it at your end. If it still doesn’t resolve your issue, then please share the input PDF files with us, so we would be able to test the issue at our end.

We’re sorry for the inconvenience.
Regards,

Thanks for the reply.


This has no effect on the size of the resulting pdf.

Can you not reimplement whatever compressed the files in version 2.0.0.0? As you can see, the pdf produced in v2.0.0.0 is 3.8Mb whereas the pdf produced in v4.2.0.0 is 6.2Mb. These are produced with exactly the same code just changing the Aspose.Pdf.Kit dll referenced.

Hi Paul,

We’re sorry for the inconvenience.

We’re looking into this issue at our end. However, can you please share the source PDF files as well, so we could test the issue with those files and update you accordingly.

We appreciate your patience and cooperation.
Regards,