Skip to content

File comression

Arun Kumar Radhakrishnan

Asked Aug 27, 2014, 6:21 AM EDT1 answer
Share
LinkedInX
hai friends,
I want compress a PDF file of size 30.9MB to few 100KB, by using codes in C#.NET
Java
FileStream sourceFileStream = File.OpenRead(@"D:\CMS\newsample.pdf");
            FileStream destFileStream = File.Create(@"D:\ newsample_new.pdf");
            GZipStream compressingStream = new GZipStream(destFileStream, CompressionMode.Compress);
            byte[] bytes = new byte[2800];
            int bytesRead;
            while ((bytesRead = sourceFileStream.Read(bytes, 0, bytes.Length)) != 0)
            {
                compressingStream.Write(bytes, 0, bytesRead);
            }
            sourceFileStream.Close();
            compressingStream.Close();

destFileStream.Close();

 I use this code to compress the file but the compressed file size is 30.1MB only. Please tell me what is the change that I want to do in these code to get the above size or if there is any other option to done this compress process, please tell me 
thanks in advance 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Depending on the PDF contents, if the source is an image that's already compressed (such as JPEG or CCITT G4), re-compressing it will not reduce the size in most cases.
    However, if the source contains images (pictures) of text, it can be reduced significantly if you convert the images to actual text and save it without the original images.
    To do the conversion from images to text, you will need to perform optical character recognition (OCR) using a good OCR engine such as Leadtools.
    0