在iText
页面标签可以通过以下方式设置:
PdfPage page = pdfDoc.getPage(1);
page.setPageLabel(PageLabelNumberingStyle.UPPERCASE_ROMAN_NUMERALS, "Cover", 1);
但是,生成的 PDF 的第一页将被标记为 CoverI
,并且所有后续页面也将被标记。我不希望在我的页面标签 Cover
中添加任何内容,也不希望在任何其他页面上添加标签。
那么,如何为单个页面设置页面标签?
我希望第一页有自定义字符串标签,其他页面有阿拉伯数字,后续页面有罗马数字。
最佳答案
页面标签配置适用于您设置的页面以及所有连续页面。因此,要使第 2 页及以后的页面具有标准的阿拉伯数字,只需确保显式设置配置即可。对于您提到的情况,代码大致如下:
PdfPage page = pdfDocument.getPage(1);
page.setPageLabel(PageLabelNumberingStyle.UPPERCASE_ROMAN_NUMERALS, "Cover", 1);
page = pdfDocument.getPage(2);
int pageNumToStartFrom = 2; // Replace it with 1 if you want the blocks to be numbered independently
page.setPageLabel(PageLabelNumberingStyle.DECIMAL_ARABIC_NUMERALS, null, pageNumToStartFrom);
page = pdfDocument.getPage(4);
pageNumToStartFrom = 4; // Replace it with 1 if you want the blocks to be numbered independently
page.setPageLabel(PageLabelNumberingStyle.UPPERCASE_ROMAN_NUMERALS, null, pageNumToStartFrom);
关于java - 如何在iText7中为单个页面设置页面标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58682928/