ImageGear Java PDF
Save a PDF Document

To save a loaded PDF file to a different PDF file use the saveDocument method of the Document class:

 
Copy Code
void saveDocument(string fileName, SaveOptions options);

After a PDF file is loaded, you can save it or save to a different PDF file.

  1. Use the openDocument method to load a PDF file.
  2. Use the saveDocument method to save the PDF file. The saveDocument method has two parameters:
    • The fileName parameter represents an output PDF filename.
    • The options parameter specifies control over some aspects of how the document is saved.

The following is an illustration of how to save a previously loaded PDF document to a PDF file:

 
Copy Code
import com.accusoft.imagegearpdf.*;
 
class PdfDemo
{
       private PDF pdf;
       private Document document;
 
       // Save PDF document to a file.
       public boolean saveDocument(String filename)
       {
              try
              {
                     // Create a SaveOptions and populate its members.
                     SaveOptions options = new SaveOptions();
                     options.setLinearized(true);
 
                     // Try to save PDF document to a file.
                     document.saveDocument(filename, options);
 
                     return true;
              }
              catch (Throwable ex)
              {
                      // Failed to save PDF file.
                      System.err.println("Exception: " + ex.toString());
 
                      return false;
               }
       }
}

The SaveOptions class contains the following methods:

 
Copy Code
boolean getLinearized();
void setLinearized(boolean newValue);

They are used to get and set the flag indicating whether to write the file linearized for page serving over remote connections (false by default).

About Linearized PDF Files

A linearized PDF file makes viewing a PDF over the web faster. It is structured to allow the first page of the PDF file to display in the browser before the entire file is downloaded from the web server. As a result, linear PDF documents open almost instantly. A linearized PDF file contains information that allows a byte-streaming server to download the PDF file one page at a time. If byte-streaming is disabled on the server or if the PDF file is not linearized, the entire PDF file must be downloaded before it can be viewed.

See Also

 

 


©2016. Accusoft Corporation. All Rights Reserved.

Send Feedback