itext writeSelectedRows不';这是我第一次打印文件的时候

itext writeSelectedRows不';这是我第一次打印文件的时候,itext,Itext,我有一个header类,它创建了一个header。每个页面上都会输出该标题。如果文档是草稿而不是最终文档,我需要在标题中添加草稿报告。 每次都会显示标题表文本。第一次创建文档时,draftTable文本不会显示,但如果再次创建文档,则会显示 有人知道如何解决这个问题或者为什么会发生吗?我有以下代码: public void onEndPage(PdfWriter writer, Document document) { CustomPdfReport.incrementPageNum(); Pd

我有一个header类,它创建了一个header。每个页面上都会输出该标题。如果文档是草稿而不是最终文档,我需要在标题中添加
草稿报告

每次都会显示
标题表
文本。第一次创建文档时,
draftTable
文本不会显示,但如果再次创建文档,则会显示

有人知道如何解决这个问题或者为什么会发生吗?我有以下代码:

public void onEndPage(PdfWriter writer, Document document) {
CustomPdfReport.incrementPageNum();
PdfContentByte cb = writer.getDirectContent();

String pgTitle = CustomPdfPage.getPageTitle();
if (null != pgTitle && !pgTitle.isEmpty()){
    Phrase pageTitle = getHeaderPageTitle(pgTitle);
    BaseResource baseResource = BaseResource.getInstance();
    String AppPath = baseResource != null ? baseResource.getStringValue(BaseResource.APPLICATION_PATH) : BaseResource.getString(BaseResource.APPLICATION_PATH);

    String imagePath = AppPath + "shared" + File.separator + "images"+ File.separator + "printTitleHeaderImage.jpg";

    try{
        logoImage = Image.getInstance(imagePath);
       } catch (DocumentException | IOException e) {
    LOGGER.error("CustomHeaderFooter.onOpenDocument had an error seting up the image instance "+ e);
    e.printStackTrace();
}

float [] imageScale = {50,50};
float width = PdfConversionFromInches.convertInchesToPageUnits(10.0);
float [] headerTableWidth = {80,20};
PdfPTable headerTable = new PdfPTable(2);
try{
    headerTable.setWidths(headerTableWidth);
    headerTable.setTotalWidth(width);
    headerTable.setLockedWidth(true);
    headerTable.getDefaultCell().setFixedHeight(topMargin);
    PdfPCell headerCell = PdfCell.createTextCell(pageTitle, Element.ALIGN_LEFT, 1, pageColor);
          headerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
          headerTable.addCell(headerCell);

         PdfPCell imageCell = PdfCell.createImageCell(imagePath, Element.ALIGN_TOP,   Element.ALIGN_RIGHT, 1, imageScale, pageColor);
         headerTable.addCell(imageCell);
         headerTable.addCell(PdfCell.createEmptyTableCell(2,pageColor,PdfCell.BIGGER_STANDARD_CELL_HEIGHT));

         headerTable.writeSelectedRows(0, -1, leftMargin,  PdfConversionFromInches.convertInchesToPageUnits(8.5), cb);

//check for report being a draft report so we can put the DRAFT REPORT indicator on the page's header
         if (isDraftReport){
              PdfPTable draftTable = new PdfPTable(1);
              draftTable.setTotalWidth(PdfConversionFromInches.convertInchesToPageUnits(2.25));
              draftTable.setSplitLate(false);

              Phrase draftTitle = new Phrase(draftText,customFonts.getDraftFont());
              draftTable.addCell(PdfCell.createTextCell(draftTitle, Element.ALIGN_LEFT, 3*PdfCell.STANDARD_CELL_HEIGHT, 1, pageColor));
              float height = 8.2f; 
              float xposition = document.leftMargin() + PdfConversionFromInches.convertInchesToPageUnits(7);
              draftTable.writeSelectedRows(0, -1, xposition,    PdfConversionFromInches.convertInchesToPageUnits(height), cb);
         }
        catch(DocumentException de) {
            LOGGER.debug("Custom HeaderFooter. An error occurred creating the header.  Error = "+de);
            throw new ExceptionConverter(de);           
         }

这可能与iText无关。如果在
If(isDraftReport){…}
中添加
System.out
,您是否看到打印到
System.out
的内容?如果没有,请查看您在何处以及如何设置
isDraftReport
值。此外,奇怪的是,您会使用一个单列、单行表来处理可以使用
ColumnText
对象轻松添加的内容。顺便说一下:当您使用
writeSelectedRows()
时,使用
setSplitLate()
没有任何意义。非常感谢。它正在进入isDraft代码,但文本没有按预期设置。设置平台是一个剪切粘贴错误,我将扩展该表。谢谢你把我引向正确的方向,它现在工作得很好。