0

iText 1.4.1 を使用しています。

単純なテーブルをドキュメントに追加しようとしています。

しかし、PDFの作成時にメモリ不足の例外がスローされていました。

テーブルは、数十万のレコードを持つDBからデータを取得しています。

これが私のサンプルコードです。

    public String createPDF(List<OutboundPriorityGridDTO> resultList,
        ExportInputDTO arg1) {

    Document document = new Document(PageSize.A4.rotate(), 15, 15, 25, 25);
    try 
    {
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filePath));
    TableHeader includeHeader = new TableHeader();
     writer.setPageEvent(includeHeader);
    document.open();
    document.addCreationDate();
        if (isEmptyList(resultList)){
            document.add(new Phrase(new Chunk("\n**** No Records are returned. ***", PdfConstants.normalFont12)));
            stampAndFlushFilePath(document, filePath, getPageOrientation(document));
            return filePath;
        }

   for (OutboundPriorityGridDTO gridDto : resultList) {
    light =  zeroIfNull(gridDto.getTotalOlpns())
                        .subtract(zeroIfNull(gridDto.getHeavyOlpns()));

                table.addCell(createPdfCell(cell,gridDto.getShipmentNumber(),Element.ALIGN_LEFT,0,BaseColor.BLACK,fontType));
                addInterimColumn( table, fontType);
                table.addCell(createPdfCell(cell,gridDto.getCarrier(),Element.ALIGN_LEFT,0,BaseColor.BLACK,fontType));
                addInterimColumn( table, fontType);
                table.addCell(createPdfCell(cell, gridDto.getDestination(),Element.ALIGN_LEFT,0,BaseColor.BLACK,fontType));
                addInterimColumn( table, fontType);

                table.addCell(createPdfCell(cell,gridDto.getEstimatedWeight(),Element.ALIGN_RIGHT,0,BaseColor.BLACK,fontType));
                addInterimColumn( table, fontType);
                table.addCell(createPdfCell(cell,gridDto.getEstimatedCube(),Element.ALIGN_RIGHT,0,BaseColor.BLACK,fontType));
                addInterimColumn( table, fontType);
                table.addCell(createPdfCell(cell,gridDto.getDateCreated(),Element.ALIGN_LEFT,0,BaseColor.BLACK,fontType));
                addInterimColumn( table, fontType);
                table.addCell(createPdfCell(cell,gridDto.getStop(),Element.ALIGN_RIGHT,0,BaseColor.BLACK,fontType));
                addInterimColumn( table, fontType);
                table.addCell(createPdfCell(cell,gridDto.getDockDoorName(),Element.ALIGN_LEFT,0,BaseColor.BLACK,fontType));
                addInterimColumn( table, fontType);
                table.addCell(createPdfCell(cell,gridDto.getTrailerNumber(),Element.ALIGN_LEFT,0,BaseColor.BLACK,fontType));
                addInterimColumn( table, fontType);
                table.addCell(createPdfCell(cell,light,Element.ALIGN_RIGHT,0,BaseColor.BLACK,fontType));
                addInterimColumn( table, fontType);
                table.addCell(createPdfCell(cell,gridDto.getHeavyOlpns(),Element.ALIGN_RIGHT,0,BaseColor.BLACK,fontType));
                addInterimColumn( table, fontType);
                table.addCell(createPdfCell(cell,gridDto.getTotalOlpns(),Element.ALIGN_RIGHT,0,BaseColor.BLACK,fontType));
                addInterimColumn( table, fontType);
                table.addCell(createPdfCell(cell,gridDto.getShipmentStatus(),Element.ALIGN_LEFT,0,BaseColor.BLACK,fontType));
                table.completeRow();
            }
     stampAndFlushFilePath(document, filePath, getPageOrientation(document));



      public static void stampAndFlushFilePath(Document document, String filePath, boolean isPageRotated) throws IOException, FileNotFoundException, DocumentException {
    document.close();
    LOGGER.info(filePath+" successfully created.");
    PdfReader reader = new PdfReader(new FileInputStream(filePath));
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(filePath));

    int n = reader.getNumberOfPages();
    getFooterTable(n, document, stamper, isPageRotated);

    stamper.close();
      }

jvmヒープサイズを増やさずにこの例外を取り除く方法を教えてもらえますか...

4

0 に答える 0