2

Javaのitext pdfライブラリを使用して、データベースからpdfにレコードをエクスポートしようとしています..しかし、pdfファイル内のpdfテーブルの配置で次の問題が発生しています..

1.PDF ページ全体に表が表示されません。PDF ページの左右にスペースが残っています。

2.すべてのページは、ページの半分のみに値を表示しています.pdfテーブルがpdfページの半分に表示されていることを意味します..

これが私のコードです..

Document document = new Document();
        PdfWriter.getInstance(document, fos);


        PdfPTable table = new PdfPTable(10);

        table.setWidthPercentage(100);
        table.setSpacingBefore(0f);
        table.setSpacingAfter(0f);



        PdfPCell cell = new PdfPCell(new Paragraph("DateRange"));

        cell.setColspan(10);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(5.0f);
        cell.setBackgroundColor(new BaseColor(140, 221, 8));

        table.addCell(cell);

        table.addCell("Calldate");
        table.addCell("Calltime");
        table.addCell("Source");
        table.addCell("DialedNo");
        table.addCell("Extension");
        table.addCell("Trunk");
        table.addCell("Duration");
        table.addCell("Calltype");
        table.addCell("Callcost");
        table.addCell("Site");

        while (rs.next()) {
            table.addCell(rs.getString("date"));
            table.addCell(rs.getString("time"));
            table.addCell(rs.getString("source"));
            table.addCell(rs.getString("destination"));
            table.addCell(rs.getString("extension"));
            table.addCell(rs.getString("trunk"));
            table.addCell(rs.getString("dur"));
            table.addCell(rs.getString("toc"));
            table.addCell(rs.getString("callcost"));
            table.addCell(rs.getString("Site"));
        }




        table.setSpacingBefore(5.0f);       // Space Before table starts, like margin-top in CSS
        table.setSpacingAfter(5.0f);        // Space After table starts, like margin-Bottom in CSS                                          

        document.open();//PDF document opened........                   

        document.add(Chunk.NEWLINE);   //Something like in HTML :-)

        document.add(new Paragraph("TechsoftTechnologies.com"));
        document.add(new Paragraph("Document Generated On - " + new Date().toString()));

        document.add(table);
        document.add(Chunk.NEWLINE);   //Something like in HTML :-)           
        document.newPage();            //Opened new page
                   //In the new page we are going to add list

        document.close();

        fos.close();
4

1 に答える 1

7

あなたがマージンを抑えたいと思っていることを理解する前に、私はあなたの質問を何度も読まなければなりませんでした。あなたの例をコピー/貼り付け (および適応) しましたが、ページに余白があるという事実に私 (および他の多くの開発者) が慣れているため、問題を再現できないと思いました。

とにかく、これはあなたの例の私のバージョンです: FullPageTableで、次の PDF を作成します: full_page_table.pdf

たとえば、いくつかの小さな変更を加えました。「段落」を a のパラメーターとして渡すのは意味がありません。これは、として扱われるPdfPCellためですが、探している行は次のとおりだと思います。ParagraphPhrase

Document document = new Document(PageSize.A4, 0, 0, 0, 0);

ゼロはマージンの幅を定義します。あなたの質問を正しく理解できれば、それらのマージンを抑制したいと思うでしょう。

あなたの主張については、すべてのページがページの半分にのみ値を表示しています.pdfテーブルがpdfページの半分に表示されていることdocument.newPage();を意味します.そうでなければあなたの主張は意味がありません;-)

于 2013-11-09T11:24:18.893 に答える