简体   繁体   中英

.net compressing pdf generated with crystal reports

As of now, we are generating PDFs programmatically using crystal reports and saving it to database. The PDF document has barcode image in it. Each file is of size 120-150 KB.

Everything is running fine but lately we are facing problem with huge growth in database size and storage requirements. This is due to 100 - 1000 records being generated each day.

Is there any way to compress the PDF files and then store it. Any API/tools available that perform these without creating issue to the barcode.Can we gain much reduction in size after compression?

Or any alternative way of storing the data will be good?

Any suggestions on this would be highly appreciated.

Thanks, Sveerap

不幸的是,压缩PDF会因为已经压缩而无法获得太多收益。

Many compressed PDF files can be compressed further.

Size of a PDF file can usually be decreased by:

  • removing unused objects (if any)
  • removing extra whitespace characters from the file (not from the visual content)
  • using object streams (a PDF 1.5 feature)

I do not know how well Crystal Report compresses PDFs but you might want to try Docotic.Pdf library and the following code and see if your files can be compressed better.

public static void CompressExistingDocument(string original, string output)
{
    using (PdfDocument pdf = new PdfDocument(original))
    {
        pdf.SaveOptions.Compression = PdfCompression.Flate;
        pdf.SaveOptions.UseObjectStreams = true;
        pdf.SaveOptions.RemoveUnusedObjects = true;
        pdf.SaveOptions.WriteWithoutFormatting = true;

        pdf.Save(output);
    }

    FileInfo originalFileInfo = new FileInfo(original);
    FileInfo compressedFileInfo = new FileInfo(output);
    MessageBox.Show(
        String.Format("Original file size: {0} bytes;\r\nCompressed file size: {1} bytes",
        originalFileInfo.Length, compressedFileInfo.Length));

    System.Diagnostics.Process.Start(output);
}

Disclaimer: I work for the vendor of the library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM