ImageGear Java PDF > How to... > 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.
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).
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.