List of usage examples for com.lowagie.text.pdf PdfPageLabels DECIMAL_ARABIC_NUMERALS
int DECIMAL_ARABIC_NUMERALS
To view the source code for com.lowagie.text.pdf PdfPageLabels DECIMAL_ARABIC_NUMERALS.
Click Source Link
From source file:ErrMsgException.java
License:Open Source License
public static void main(String args[]) { // ?//from ww w . j a v a 2s .c o m if (args.length < 3 || args.length > 5) { usage(); return; } // ?? ArrayList<HashMap> bookmark = new ArrayList<HashMap>(); HashMap<String, Object> lastmap = null; ArrayDeque<ArrayList> queue = new ArrayDeque<ArrayList>(); queue.push(bookmark); // ????? try { File file = new File(args[2]); BufferedReader br = new BufferedReader(new FileReader(file)); String line; int previouslevel = 0; int lno = 0; while ((line = br.readLine()) != null) { lno++; if (line.startsWith("#")) continue; // ?# int level = 0; if (line.startsWith("\t")) { // do { line = line.substring(1); level++; } while (line.startsWith("\t")); } String lines[] = line.split("\t"); line = ""; if (lines.length > 2) { for (int i = 0; i < lines.length - 1; i++) { line += lines[i]; if (i < lines.length - 1) line += ""; } } else { line = lines[0]; } if (lines.length < 2) continue; int preample = 0; if (args.length >= 4) { preample = Integer.parseInt(args[3]); } int page = roman2arabic(lines[lines.length - 1], preample); HashMap<String, Object> map = new HashMap<String, Object>(); map.put("Title", line); map.put("Action", "GoTo"); map.put("Page", page + " Fit"); if (args.length >= 5) { // ?? int foldlevel = Integer.parseInt(args[4]); if (foldlevel <= level) map.put("Open", "false"); } if (level > previouslevel) { if (level - previouslevel > 1) { // ??? throw new ErrMsgException( lno + ": ??2?????????"); } // ArrayList<HashMap> kids = new ArrayList<HashMap>(); kids.add(map); if (lastmap != null) { lastmap.put("Kids", kids); } else { throw new ErrMsgException( lno + ": ??????????"); } queue.push(kids); } else if (level < previouslevel) { // ? for (int i = previouslevel; i > level; i--) { queue.pop(); } queue.peek().add(map); } else { // ???????? queue.peek().add(map); } lastmap = map; previouslevel = level; } br.close(); } catch (IOException e) { System.out.println(e); return; } catch (ErrMsgException e) { System.out.println("?????\n" + e.getMessage()); return; } // PDF???? try { PdfReader reader = new PdfReader(args[0]); int maxpage = reader.getNumberOfPages(); OutputStream os = new FileOutputStream(args[1]); PdfCopyFields copyFields = new PdfCopyFields(os); copyFields.addDocument(reader); copyFields.setOutlines(bookmark); if (args.length > 3) { // ? PdfPageLabels labels = new PdfPageLabels(); if (maxpage > 0) labels.addPageLabel(1, PdfPageLabels.LOWERCASE_ROMAN_NUMERALS, null, 1); if (maxpage > Integer.parseInt(args[3])) labels.addPageLabel(Integer.parseInt(args[3]) + 1, PdfPageLabels.DECIMAL_ARABIC_NUMERALS, null, 1); copyFields.getWriter().setPageLabels(labels); } copyFields.close(); os.close(); } catch (DocumentException e) { System.out.println(e); return; } catch (IOException e) { System.out.println(e); return; } System.out.println(args[1] + " ?????"); }
From source file:RomanNmbl.java
License:Open Source License
public static void main(String args[]) { if (args.length != 3) { usage();/*w ww .j a v a 2 s. co m*/ return; } try { PdfReader reader; reader = new PdfReader(args[0]); int maxpage = reader.getNumberOfPages(); PdfStamper stamper; stamper = new PdfStamper(reader, new FileOutputStream(args[1])); PdfPageLabels labels = new PdfPageLabels(); if (maxpage > 0) labels.addPageLabel(1, PdfPageLabels.LOWERCASE_ROMAN_NUMERALS, null, 1); if (maxpage > Integer.parseInt(args[2])) labels.addPageLabel(Integer.parseInt(args[2]) + 1, PdfPageLabels.DECIMAL_ARABIC_NUMERALS, null, 1); stamper.getWriter().setPageLabels(labels); stamper.close(); } catch (IOException e) { // FIXME: Better error handling. System.out.println(e); return; } catch (DocumentException e) { System.out.println(e); return; } }
From source file:org.pdfsam.console.business.pdf.handlers.PageLabelsCmdExecutor.java
License:Open Source License
/** * mapping from the console style variable to the iText variable * //from w ww . ja va2s . com * @param style * @return iText style variable */ private int getPageLabelStyle(String style) { int retVal = PdfPageLabels.DECIMAL_ARABIC_NUMERALS; if (PageLabel.ARABIC.equals(style)) { retVal = PdfPageLabels.DECIMAL_ARABIC_NUMERALS; } else if (PageLabel.EMPTY.equals(style)) { retVal = PdfPageLabels.EMPTY; } else if (PageLabel.LLETTER.equals(style)) { retVal = PdfPageLabels.LOWERCASE_LETTERS; } else if (PageLabel.LROMAN.equals(style)) { retVal = PdfPageLabels.LOWERCASE_ROMAN_NUMERALS; } else if (PageLabel.ULETTER.equals(style)) { retVal = PdfPageLabels.UPPERCASE_LETTERS; } else if (PageLabel.UROMAN.equals(style)) { retVal = PdfPageLabels.UPPERCASE_ROMAN_NUMERALS; } return retVal; }