How do I optimize and compress PDF?

Q: I want compress pdf with 'PDFNet SDK' in c#.

Simple requirement:
1. Use in ASP.NET web site
2. Compress PDFs user uploaded with big image
3. How to import the component in my project?
----------------------

A: The simplest way to optimize and compress PDF is using
‘pdftron.PDF.Optimizer’ class from PDFNet SDK (http://www.pdftron.com/
pdfnet).

As a starting point you may want to take a look at PDF Optimizer
sample project: http://www.pdftron.com/pdfnet/samplecode.html#Optimizer

In context of ASP.NET you can use PDF Optimizer as follows:

In your application solution, add a reference to 'PDFNet.DLL' (located
in 'PDFNet/Lib' folder). Then add the following code you your ASP.NET
page:

using pdftron;
using pdftron.Common;
using pdftron.SDF;
using pdftron.PDF;

...
PDFNet.Initialize(); // you can call this method one time - in your
application start function.

try {
  using (PDFDoc doc = new PDFDoc("input.pdf")) {
    doc.InitSecurityHandler();
    Optimizer.ImageSettings color_image_settings = new
Optimizer.ImageSettings();
    Optimizer.ImageSettings grayscale_image_settings = new
Optimizer.ImageSettings();
    Optimizer.MonoImageSettings mono_image_settings = new
Optimizer.MonoImageSettings();

mono_image_settings.SetCompressionMode(Optimizer.MonoImageSettings.CompressionMode.e_jbig2);
    mono_image_settings.ForceChanges(true);
    mono_image_settings.ForceRecompression(true);
     // ... etc.

    Optimizer.Optimize(doc, color_image_settings,
grayscale_image_settings, mono_image_settings);

    doc.Save("my.pdf", SDFDoc.SaveOptions.e_linearized);
   }
}
catch (PDFNetException e){
  Console.WriteLine(e.Message);
}

Please note that some optimization options (such as image resolution)
can affect the image quality in processed documents.

The optimizer is licensed as an optional add-on to PDFNet Core
(similat to PDF/A, Convert, and Silverlight add-on).

Q: I just saw this post about PDF Optimization.

We have implemented our own optimizer using PDFNet but it does not
work perfectly on all files so we want to try your "Optimizer"-class
instead.

I downloaded the Java 64 bit Linux file but the file is from
08-10-2010, and do not contain the Optimizer class. When will a Java
64 bit linux version be available?
-------

A: Because 5.2 was a short interim release we are planning update the
'official' Linux version as part of 5.5 which is planned for early
January.

In case you would like to get a hold of Optimizer and 5.2 in the Linux
version you can use the following (unofficial) build:
http://www.pdftron.com/IDR49Z9-B31B/PDFNetC64.tar.gz

On Dec 16, 2:59 pm, Support <supp...@pdftron.com> wrote:

Q: I want compress pdf with 'PDFNet SDK' in c#.

Simple requirement:
1. Use in ASP.NET web site
2. Compress PDFs user uploaded with big image
3. How to import the component in my project?

----------------------

A: The simplest way to optimize and compress PDF is using
‘pdftron.PDF.Optimizer’ class from PDFNet SDK (http://www.pdftron.com/
pdfnet).

As a starting point you may want to take a look at PDF Optimizer
sample project:http://www.pdftron.com/pdfnet/samplecode.html#Optimizer

In context of ASP.NET you can use PDF Optimizer as follows:

In your application solution, add a reference to 'PDFNet.DLL' (located
in 'PDFNet/Lib' folder). Then add the following code you your ASP.NET
page:

using pdftron;
using pdftron.Common;
using pdftron.SDF;
using pdftron.PDF;

...
PDFNet.Initialize(); // you can call this method one time - in your
application start function.

try {
using (PDFDoc doc = new PDFDoc("input.pdf")) {
doc.InitSecurityHandler();
Optimizer.ImageSettings color_image_settings = new
Optimizer.ImageSettings();
Optimizer.ImageSettings grayscale_image_settings = new
Optimizer.ImageSettings();
Optimizer.MonoImageSettings mono_image_settings = new
Optimizer.MonoImageSettings();

mono_image_settings.SetCompressionMode(Optimizer.MonoImageSettings.Compress­ionMode.e_jbig2);
mono_image_settings.ForceChanges(true);
mono_image_settings.ForceRecompression(true);
// ... etc.

Optimizer\.Optimize\(doc, color\_image\_settings,

grayscale_image_settings, mono_image_settings);

doc\.Save\(&quot;my\.pdf&quot;, SDFDoc\.SaveOptions\.e\_linearized\);

}}

catch (PDFNetException e){
Console.WriteLine(e.Message);

}

Please note that some optimization options (such as image resolution)
can affect the image quality in processed documents.

The optimizer is licensed as an optional add-on to PDFNet Core
(similat to PDF/A, Convert, and Silverlight add-on).