Viewer preferences

Tags: viewer preferencesprint preferencesiText 5
Files: 
package sandbox.stamper;
 
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfName;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
 
import sandbox.WrapToTest;
 
@WrapToTest
public class ChangeViewerPreference {
 
    public static final String SRC = "resources/pdfs/united_states.pdf";
    public static final String DEST = "results/stamper/us_duplex.pdf";
 
    public static void main(String[] args) throws IOException, DocumentException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new ChangeViewerPreference().manipulatePdf(SRC, DEST);
    }
 
 
    public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
        PdfReader reader = new PdfReader(src);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
        stamper.addViewerPreference(PdfName.DUPLEX, PdfName.DUPLEXFLIPLONGEDGE);
        stamper.close();
        reader.close();
    }
}
File nameRaw URLUpdated
ChangeViewerPreference.javaChangeViewerPreference.java2015-11-08 3:51 pm
Resources: 
File nameRaw URLUpdated
united_states.pdfunited_states.pdf2015-10-30 6:41 pm
Results: 
File nameRaw URLUpdated
cmp_us_duplex.pdfcmp_us_duplex.pdf2015-11-08 3:52 pm