java.io.IOException:该文档没有页面。在本地工作正常,但在aws中部署后无法工作

问题描述 投票:0回答:1

[您好,我正在尝试使用itextpdf创建PDF。在本地测试时,它工作正常。但是在aws部署之后,我收到406 Not not accept with java.io.IOException:该文档没有页面专有内容。

有很多答案,但与部署问题无关。我是否需要检查任何网络配置或pdf生成代码中存在的问题?

以下是我的代码实现:请提出一些解决方案。

public byte[] createPdf(List<Participant> participantList) throws IOException,
        DocumentException, com.google.zxing.WriterException {
    Document document = new Document();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, byteArrayOutputStream);
    document.open();
    document.add(createMainTable(participantList));
    document.close();
    return byteArrayOutputStream.toByteArray();
}

public static PdfPTable createMainTable(List<Participant> optionalParticipant) throws BadElementException,
        IOException, com.google.zxing.WriterException {
    PdfPTable table = new PdfPTable(2);
    logger.info("Main Table was created");
    for (int i = 0; i < optionalParticipant.size(); i++) {
        PdfPCell cell1 = new PdfPCell();
        cell1.setBorderWidth(0);
        cell1.setPadding(10f);
        cell1.addElement(createSubTable(optionalParticipant.get(i)));
        table.addCell(cell1);
    }
    return table;
}

public static PdfPTable createSubTable(Participant participant) throws BadElementException,
        IOException, com.google.zxing.WriterException {

    BaseColor baseColor = new BaseColor(150, 150, 150);
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);
    PdfPCell cell, cell1, cell2;
    Font font = new Font();
    font.setSize(10f);
    font.setColor(BaseColor.WHITE);
    String participantName = participant.getFirstName() + " " + participant.getLastName();
    Chunk chunk = new Chunk(participantName, font);
    Paragraph head = new Paragraph("             "+chunk);
    head.setFont(font);
    cell = new PdfPCell(head);
    cell.setColspan(2);
    cell.setBackgroundColor(baseColor);
    cell.setPadding(2f);
    table.addCell(cell);
    String qrData = participant.getQrCodeData();
    Image img = getQRCodeImage(qrData);

    font = new Font();
    font.setSize(5f);

    chunk = new Chunk("\n" + "Event ID: " + participant.getEvent().getEventId() +
            "\n\n" + "Unique ID: " + participant.getUniqueId() +
            "\n\n" + "Email ID: " + participant.getEmail(), font);

    Paragraph body = new Paragraph(chunk);
    cell1 = new PdfPCell(body);
    cell1.setBorderWidthRight(0);
    cell1.setPadding(10f);

    cell2 = new PdfPCell();
    cell2.addElement(img);
    cell2.setBorderWidthLeft(1);
    cell2.setPadding(10f);

    table.addCell(cell1);
    table.addCell(cell2);
    logger.info("Sub Table was created");
    return table;
}
java amazon-web-services amazon-ec2 itext
1个回答
0
投票

请检查partnerList不为空,并且包含元素。您可以使用记录仪在开始使用之前打印列表的大小。

logger.info("No of participants: "+participantList.size());

此外,打开文档后,请始终在文档中立即添加一个空块,以免发生此异常。

document.open();
document.add(new Chunk(""));
© www.soinside.com 2019 - 2024. All rights reserved.