Example usage for com.lowagie.text.pdf PdfName DISPLAYDOCTITLE

List of usage examples for com.lowagie.text.pdf PdfName DISPLAYDOCTITLE

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfName DISPLAYDOCTITLE.

Prototype

PdfName DISPLAYDOCTITLE

To view the source code for com.lowagie.text.pdf PdfName DISPLAYDOCTITLE.

Click Source Link

Document

A name

Usage

From source file:jPDFmelange.MelangeJFrame.java

License:Open Source License

/** 
 *  Main save method./*from ww  w. j  a v  a 2s.  c o m*/
 *  <p> 
 *  Saves all elements of the main list represented with its {@link MelangeJFrame#listContentMain content} 
 *  to the specified file.
 *  
 *   @param fileName name of file to save.
 *   @throws IOException on File IO error.
 *   @throws DocumentException on itext PDF error. 
 */
private void saveFile(String fileName) throws IOException, DocumentException {
    File file = new File(fileName);
    File tmpfile = File.createTempFile("Mixer", null, file.getParentFile());
    String bakFileName = fileName.substring(0, fileName.lastIndexOf('.')).concat(".bak");
    File bakfile = new File(bakFileName);

    //
    // prevent writing to a PDF that is blocked by the renderer.
    //
    jPanePreview.closePdfFile();

    // itext usage
    System.out.println("Writing new content to <" + tmpfile.getName() + ">");
    PdfReader reader = null;
    PdfDictionary dict = null;
    Document pdfDoc = new Document();
    PdfCopy writer = new PdfCopy(pdfDoc, new FileOutputStream(tmpfile));
    pdfDoc.open();
    PageNode node = null;
    for (int i = 0; i < listContentMain.size(); i++) {
        node = (PageNode) listContentMain.get(i);
        if (node.password == null)
            reader = new PdfReader(node.filename);
        else
            reader = new PdfReader(node.filename, node.password.getBytes());
        dict = reader.getPageN(node.pagenumber);
        dict.put(PdfName.ROTATE, new PdfNumber(node.rotation));
        writer.addPage(writer.getImportedPage(reader, node.pagenumber));
        reader.close(); // close input file
        System.out
                .println("Page " + node.pagenumber + "  File:" + node.filename + "  Rotation:" + node.rotation);
    }

    //
    // save page mode and layout preferences
    //
    if (jCheckBoxEnablePDFViewerPrefs.isSelected()) {

        String key = jPanelViewPrefs.getKeyPageMode();
        writer.setViewerPreferences(PageMode.get(key));

        key = jPanelViewPrefs.getKeyPageLayout();
        writer.setViewerPreferences(PageLayout.get(key));

        if (jPanelViewPrefs.jCheckBoxHideToolbar.isSelected())
            writer.addViewerPreference(PdfName.HIDETOOLBAR, PdfBoolean.PDFTRUE);
        if (jPanelViewPrefs.jCheckBoxHideMenubar.isSelected())
            writer.addViewerPreference(PdfName.HIDEMENUBAR, PdfBoolean.PDFTRUE);
        if (jPanelViewPrefs.jCheckBoxHideWindowUI.isSelected())
            writer.addViewerPreference(PdfName.HIDEWINDOWUI, PdfBoolean.PDFTRUE);
        if (jPanelViewPrefs.jCheckBoxFitWindow.isSelected())
            writer.addViewerPreference(PdfName.FITWINDOW, PdfBoolean.PDFTRUE);
        if (jPanelViewPrefs.jCheckBoxCenterWindow.isSelected())
            writer.addViewerPreference(PdfName.CENTERWINDOW, PdfBoolean.PDFTRUE);
        if (jPanelViewPrefs.jCheckBoxDisplayDocTitle.isSelected())
            writer.addViewerPreference(PdfName.DISPLAYDOCTITLE, PdfBoolean.PDFTRUE);
    }

    pdfDoc.close(); // close Helper Class
    writer.close(); // close output file

    // save old file to a XXX.bak file
    if (bakfile.exists())
        bakfile.delete();
    if (file.renameTo(bakfile.getCanonicalFile())) {
        System.out.println("Orginal File is saved in <" + bakfile.getName() + ">");
    }

    // move new content to original file name
    file = new File(fileName);
    if (tmpfile.renameTo(file))
        System.out.println("<" + tmpfile.getName() + "> is copied to <" + file.getName() + "> ");
    else {
        JOptionPane.showMessageDialog(MelangeJFrame.this,
                messages.getString("canNotWriteFile") + file.getName() + messages.getString("trySaveAs"),
                messages.getString("warning"), JOptionPane.WARNING_MESSAGE);
        System.out.println(
                messages.getString("canNotWriteFile") + file.getName() + messages.getString("trySaveAs"));
    }

}

From source file:org.jrimum.bopepo.pdf.PdfDocMix.java

License:Apache License

/**
 * Inicializa os principais objetos para a escrita dos dados do documento no
 * template PDF: {@code stamper}, {@code reader} e {@code outputStream}.
 * //from   w  w  w  . java  2s  .  c  om
 * @since 0.2
 */
private void init() {

    try {

        reader = new PdfReader(getTemplate());

        outputStream = new ByteArrayOutputStream();

        stamper = new PdfStamper(reader, outputStream);

        final String JRIMUM = "jrimum.org/bopepo";

        String creator = docInfo.creator();

        if (isBlank(creator)) {
            withCreator(JRIMUM);
        } else {
            withCreator(creator + " by (" + JRIMUM + ")");
        }

        if (isNull(docInfo.creation())) {
            docInfo.creation(Calendar.getInstance());
        }

        stamper.setMoreInfo((HashMap<?, ?>) docInfo.toMap());

        if (isNotNull(displayDocTitle)) {
            stamper.addViewerPreference(PdfName.DISPLAYDOCTITLE,
                    displayDocTitle ? PdfBoolean.PDFTRUE : PdfBoolean.PDFFALSE);
        }

        form = stamper.getAcroFields();

    } catch (Exception e) {

        Exceptions.throwIllegalStateException(e);
    }
}