/** * <a href="http://stackoverflow.com/questions/32393858/why-result-of-getpagelabels-is-different-from-the-adobe-acrobat"> * Why result of GetPageLabels is different from the Adobe Acrobat * </a> * <br/> * <a href="https://drive.google.com/file/d/0Bxb0Du7de8igNmVPSUc3VzdPSjg/view?usp=sharing"> * testHuangMeizai.pdf * </a> * <p> * Indeed, the labels are wrong. There is a small bug in {@link PdfPageLabels#getPageLabelFormats(PdfReader)}. * When encountering a new page label dictionary without a P (prefix) entry, it does not reset the current * prefix value. * </p> */ @Test public void testTestHuangMeizai() throws IOException { try ( InputStream resource = getClass().getResourceAsStream("testHuangMeizai.pdf")) { final PdfReader reader = new PdfReader(resource); String[] objLabels = PdfPageLabels.getPageLabels(reader); System.out.println("page number:"); if (objLabels != null) { for (int i = 0; i <= objLabels.length - 1; i++) { System.out.printf("%2d - %s\n", i, objLabels[i]); } } } }
private void doExecute() throws TaskException, IOException { parameters.setOutput(getOutputFile()); when(context.getTask(parameters)).thenReturn((Task) victimTask); victim.execute(parameters); PdfReader reader = getReaderFromResultFile(); assertCreator(reader); assertEquals(PdfVersion.VERSION_1_6.getVersionAsCharacter(), reader.getPdfVersion()); PdfPageLabelFormat[] formats = PdfPageLabels.getPageLabelFormats(reader); assertEquals(1, formats[0].logicalPage); assertEquals(1, formats[1].logicalPage); assertEquals(1, formats[0].physicalPage); assertEquals(3, formats[1].physicalPage); assertEquals(PdfPageLabels.LOWERCASE_ROMAN_NUMERALS, formats[0].numberStyle); assertEquals(PdfPageLabels.DECIMAL_ARABIC_NUMERALS, formats[1].numberStyle); assertEquals("Test", formats[1].prefix); reader.close(); }
/** * Maps a map of {@link PdfPageLabel} to a {@link PdfPageLabels} instance that can be used as input for the PdfCopy. * * @param labels * @param totalPages * @return the resulting {@link PdfPageLabels} */ public static PdfPageLabels getLabels(Map<Integer, PdfPageLabel> labels, int totalPages) { PdfPageLabels retVal = new PdfPageLabels(); for (Entry<Integer, PdfPageLabel> entry : labels.entrySet()) { PdfPageLabel label; if (entry.getKey() <= totalPages) { label = entry.getValue(); retVal.addPageLabel(entry.getKey(), PAGE_NUMBERS_STYLES.get(label.getNumberingStyle()), label.getLabelPrefix(), label.getLogicalPageNumber()); } else { LOG.warn("Page number out of rage, {} will be ignored.", entry.getValue()); } } return retVal; }
public void setPageLabels(PdfPageLabels labels) { pdfCopy.setPageLabels(labels); }
/** * sets the input page labels to the underlying pdf copy. * * @param labels */ void setPageLabels(PdfPageLabels labels);