/** * Defines the sort order of the field (ascending or descending). * @param ascending an array with every element corresponding with a name of a field. */ public void setSortOrder(boolean[] ascending) { PdfObject o = get(PdfName.S); if (o instanceof PdfArray) { if (((PdfArray)o).size() != ascending.length) { throw new IllegalArgumentException("The number of booleans in this array doesn't correspond with the number of fields."); } PdfArray array = new PdfArray(); for (int i = 0; i < ascending.length; i++) { array.add(new PdfBoolean(ascending[i])); } put(PdfName.A, array); } else { throw new IllegalArgumentException("You need a single boolean for this collection sort dictionary."); } }
/** * Sets the viewer preferences as the sum of several constants. * * @param preferences * the viewer preferences * @see PdfViewerPreferences#setViewerPreferences */ public void setViewerPreferences(int preferences) { this.pageLayoutAndMode |= preferences; // for backwards compatibility, it is also possible // to set the following viewer preferences with this method: if ((preferences & viewerPreferencesMask) != 0) { pageLayoutAndMode = ~viewerPreferencesMask & pageLayoutAndMode; if ((preferences & PdfWriter.HideToolbar) != 0) viewerPreferences.put(PdfName.HIDETOOLBAR, PdfBoolean.PDFTRUE); if ((preferences & PdfWriter.HideMenubar) != 0) viewerPreferences.put(PdfName.HIDEMENUBAR, PdfBoolean.PDFTRUE); if ((preferences & PdfWriter.HideWindowUI) != 0) viewerPreferences.put(PdfName.HIDEWINDOWUI, PdfBoolean.PDFTRUE); if ((preferences & PdfWriter.FitWindow) != 0) viewerPreferences.put(PdfName.FITWINDOW, PdfBoolean.PDFTRUE); if ((preferences & PdfWriter.CenterWindow) != 0) viewerPreferences.put(PdfName.CENTERWINDOW, PdfBoolean.PDFTRUE); if ((preferences & PdfWriter.DisplayDocTitle) != 0) viewerPreferences.put(PdfName.DISPLAYDOCTITLE, PdfBoolean.PDFTRUE); if ((preferences & PdfWriter.NonFullScreenPageModeUseNone) != 0) viewerPreferences.put(PdfName.NONFULLSCREENPAGEMODE, PdfName.USENONE); else if ((preferences & PdfWriter.NonFullScreenPageModeUseOutlines) != 0) viewerPreferences.put(PdfName.NONFULLSCREENPAGEMODE, PdfName.USEOUTLINES); else if ((preferences & PdfWriter.NonFullScreenPageModeUseThumbs) != 0) viewerPreferences.put(PdfName.NONFULLSCREENPAGEMODE, PdfName.USETHUMBS); else if ((preferences & PdfWriter.NonFullScreenPageModeUseOC) != 0) viewerPreferences.put(PdfName.NONFULLSCREENPAGEMODE, PdfName.USEOC); if ((preferences & PdfWriter.DirectionL2R) != 0) viewerPreferences.put(PdfName.DIRECTION, PdfName.L2R); else if ((preferences & PdfWriter.DirectionR2L) != 0) viewerPreferences.put(PdfName.DIRECTION, PdfName.R2L); if ((preferences & PdfWriter.PrintScalingNone) != 0) viewerPreferences.put(PdfName.PRINTSCALING, PdfName.NONE); } }
/** * Defines the sort order of the field (ascending or descending). * @param ascending true is the default, use false for descending order */ public void setSortOrder(boolean ascending) { PdfObject o = get(PdfName.S); if (o instanceof PdfName) { put(PdfName.A, new PdfBoolean(ascending)); } else { throw new IllegalArgumentException("You have to define a boolean array for this collection sort dictionary."); } }
/** * Sets the viewer preferences for printing. */ public void addViewerPreference(PdfName key, PdfObject value) { switch(getIndex(key)) { case 0: // HIDETOOLBAR case 1: // HIDEMENUBAR case 2: // HIDEWINDOWUI case 3: // FITWINDOW case 4: // CENTERWINDOW case 5: // DISPLAYDOCTITLE case 14: // PICKTRAYBYPDFSIZE if (value instanceof PdfBoolean) { viewerPreferences.put(key, value); } break; case 6: // NONFULLSCREENPAGEMODE if (value instanceof PdfName && isPossibleValue((PdfName)value, NONFULLSCREENPAGEMODE_PREFERENCES)) { viewerPreferences.put(key, value); } break; case 7: // DIRECTION if (value instanceof PdfName && isPossibleValue((PdfName)value, DIRECTION_PREFERENCES)) { viewerPreferences.put(key, value); } break; case 8: // VIEWAREA case 9: // VIEWCLIP case 10: // PRINTAREA case 11: // PRINTCLIP if (value instanceof PdfName && isPossibleValue((PdfName)value, PAGE_BOUNDARIES)) { viewerPreferences.put(key, value); } break; case 12: // PRINTSCALING if (value instanceof PdfName && isPossibleValue((PdfName)value, PRINTSCALING_PREFERENCES)) { viewerPreferences.put(key, value); } break; case 13: // DUPLEX if (value instanceof PdfName && isPossibleValue((PdfName)value, DUPLEX_PREFERENCES)) { viewerPreferences.put(key, value); } break; case 15: // PRINTPAGERANGE if (value instanceof PdfArray) { viewerPreferences.put(key, value); } break; case 16: // NUMCOPIES if (value instanceof PdfNumber) { viewerPreferences.put(key, value); } break; } }
/** * Sets the initial visibility of the field. * @param visible the default is true (visible) */ public void setVisible(boolean visible) { put(PdfName.V, new PdfBoolean(visible)); }
/** * Indication if the field value should be editable in the viewer. * @param editable the default is false (not editable) */ public void setEditable(boolean editable) { put(PdfName.E, new PdfBoolean(editable)); }