2017-10-31 4 views
0

に2列にまたがるセルの紹介私は下図のようにPDF文書を作成するために、iTextの(Javaバージョン)を使用しています:PDFテーブル

enter image description here

私が示すように、コンテンツを作成したいです強調表示された部分に私は、強調表示された部分を除いて、PDFの他のすべての部分の開発を終えました。

参照:

enter image description here

+0

はの要約を含めるiTextのバージョン5.0.6を使用していました問題を解決するためにこれまで行ってきた作業、それを解決している難しさの説明([help]、[ask])。 – Zabuza

+0

コードを画像として共有していますか?ああ、少年...どんな場合でも:なぜセル6の列スパンと列スパンを2に設定しますか?なぜ、セル20のcolspanを2に設定するのですか?空のセルをどこに追加していますか?あなたのコードは画像に対応しておらず、コードのさまざまな行を最も混乱させる方法で注文しています。あなたはあなたの会社を離れ、後継者に怒っていますか?あなたはプログラミングの最初のルールを知らないのですか? *あなたのコードを維持する人があなたの住んでいる場所を知っている暴力的なサイコパスになるかのように常にコードします* –

答えて

1

あなたが適切にiTextのにCOLSPANとROWSPANを使用することによって、これを達成することができます。 例は以下の見つけることができます:

https://developers.itextpdf.com/examples/tables/colspan-and-rowspan

私はあなたと問題を抱えているはずだと仮定部分の小さなコードブロックを追加しました:

public void createPdf(String dest) throws IOException, DocumentException { 
    Document document = new Document(); 
    PdfWriter.getInstance(document, new FileOutputStream(dest)); 
    document.open(); 
    PdfPTable table = new PdfPTable(3); 
    table.setWidths(new int[]{ 1, 1, 1}); 
    PdfPCell cell; 
    cell = new PdfPCell(new Phrase("8")); 
    cell.setColspan(2); 
    table.addCell(cell); 
    cell = new PdfPCell(new Phrase("10")); 
    cell.setColspan(1); 
    table.addCell(cell); 
    cell = new PdfPCell(new Phrase("15")); 
    cell.setColspan(1); 
    cell.setRowspan(2); 
    table.addCell(cell); 
    cell = new PdfPCell(new Phrase("16")); 
    cell.setColspan(1); 
    table.addCell(cell); 
    cell = new PdfPCell(new Phrase("17")); 
    cell.setColspan(1); 
    table.addCell(cell); 
    cell = new PdfPCell(new Phrase("24")); 
    cell.setColspan(1); 
    table.addCell(cell); 
    cell = new PdfPCell(new Phrase("25")); 
    cell.setColspan(1); 
    table.addCell(cell); 
    cell = new PdfPCell(new Phrase("mm")); 
    cell.setColspan(2); 
    table.addCell(cell); 
    cell = new PdfPCell(new Phrase("mm")); 
    cell.setColspan(1); 
    table.addCell(cell); 
    document.add(table); 
    document.close(); 
} 

結果のPDFは以下のようになります。 : enter image description here

私は

+0

一般に、スタックオーバーフローではリンクのみの回答は受け入れられません。 –

+0

OK、サンプルコードブ​​ロックを追加します。 – Yash

+1

OPがiText 5またはiText 7を使用しているかどうかは不明です。iText 7のコードはiText 5のコードとはかなり異なります。 –

関連する問題