List of usage examples for com.lowagie.text.pdf PdfName HIDEMENUBAR
PdfName HIDEMENUBAR
To view the source code for com.lowagie.text.pdf PdfName HIDEMENUBAR.
Click Source Link
From source file:jPDFmelange.MelangeJFrame.java
License:Open Source License
/** * Main save method./* ww w .j a va 2 s .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")); } }