java类com.itextpdf.text.pdf.PdfPageLabels的实例源码

ReadPageLabels.java 文件源码 项目:testarea-itext5 阅读 17 收藏 0 点赞 0 评论 0
/**
 * <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]);
            }
        }
    }
}
SetPageLabelIText5TaskTest.java 文件源码 项目:sejda-itext5 阅读 13 收藏 0 点赞 0 评论 0
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();
}
PageLabelUtils.java 文件源码 项目:sejda-itext5 阅读 19 收藏 0 点赞 0 评论 0
/**
 * 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;
}
AbstractPdfCopier.java 文件源码 项目:sejda-itext5 阅读 20 收藏 0 点赞 0 评论 0
public void setPageLabels(PdfPageLabels labels) {
    pdfCopy.setPageLabels(labels);
}
PdfCopier.java 文件源码 项目:sejda-itext5 阅读 15 收藏 0 点赞 0 评论 0
/**
 * sets the input page labels to the underlying pdf copy.
 * 
 * @param labels
 */
void setPageLabels(PdfPageLabels labels);


问题


面经


文章

微信
公众号

扫码关注公众号