Free Support Forum - aspose.com

PDF Size Not Getting Reduced using Aspose.PDF dll (20.1.0.0)

private void btnOptimizePDFCompressImages_Click(object sender, EventArgs e)
{
//open document
Document pdfDocument = new Document(txtOriginalPDFName.Text + “”);

        pdfDocument.ProcessParagraphs();

        //initialize OptimizationOptions
        var optOptions = new Aspose.Pdf.Optimization.OptimizationOptions();
        optOptions.LinkDuplcateStreams = true;
        optOptions.RemoveUnusedObjects = true;
        optOptions.RemoveUnusedStreams = true;
        optOptions.UnembedFonts = false;
        optOptions.ImageCompressionOptions.CompressImages = true;
        optOptions.ImageCompressionOptions.ImageQuality = 50;
        optOptions.ImageCompressionOptions.ResizeImages = true;
        //optOptions.ImageCompressionOptions.MaxResolution = 300;
        optOptions.ImageCompressionOptions.Version = Aspose.Pdf.Optimization.ImageCompressionVersion.Standard;
        

        Cursor.Current = Cursors.WaitCursor;

        //optimize pdf document.
        pdfDocument.OptimizeResources(optOptions);
        pdfDocument.Optimize();

        string dirName = "";
        string[] fileNames;

        if (txtOriginalPDFName.Text != null)
        {
            dirName = Path.GetDirectoryName(txtOriginalPDFName.Text + "");
        }

        fileNames = Directory.GetFiles(dirName);

        foreach (string fileName in fileNames)
        {

            //dirName = fileName; 
            string fname = Path.GetFileName(fileName);

            if (fileName == txtOriginalPDFName.Text)
            {
                fname = "new_" + fname;

                string newDirName = dirName + "\\" + fname;

                //save output document
                pdfDocument.Save(newDirName);
            }
        }

        Cursor.Current = Cursors.Default;
    }

@ADIL_MIAN

Thanks for contacting support.

Would you kindly share your sample source PDF document for our reference. We will test the scenario in our environment and address it accordingly.