私はitextを使って固定幅のpdfを作成しようとしています。 pdfの幅は85.0fに固定されています。pdfには 'border'という幅の境界があります これに対して、幅85.0f-(border * 2)の表を作成し、データを追加します。 (border * 2) しかし、私が得るpdfは、境界とテーブルの間に細い間隔を持っています。 そのスペースを削除したいと思います。 私は既にゼロなどにパディングを設定しようとしました。しかし、その薄い間隔がまだあります。 私のコードは次のとおりです。固定幅の後にitextテーブルが正確にフィットしない
public class Template2100_2 {
public static final String DEST = "D:\\uploads\\abc.pdf";
public static void main(String[] args) throws DocumentException, IOException {
Template2100_2 t=new Template2100_2();
Font font = new Font(Font.FontFamily.TIMES_ROMAN, 7f, Font.NORMAL);
t.createPdfOrdinary("The Commerce Ministry has received several references from various stakeholders seeking clarification", "E-mail ID\n"
+ " 1854213265\n"
+ " Ph: 12547869",1,font);
}
public void createPdfOrdinary(String chunk1Text, String chunk2Text,Integer border,Font font) throws DocumentException, IOException
{
Document document = new Document(PageSize.A4, 0, 0, 0, 0);
PdfPTable table = new PdfPTable(1);
table.setTotalWidth(85f-(border*2));
table.setLockedWidth(true);
//table.setWidthPercentage(100);
table.setSpacingBefore(0f);
table.setSpacingAfter(0f);
PdfPCell cell;
cell = new PdfPCell(new Phrase(chunk1Text));
cell.setBorder(0);
cell.setPadding(0);
cell.setColspan(1);
cell.isUseBorderPadding();
cell.setPaddingBottom(1f);
cell.setPaddingRight(-1f);
cell.setBackgroundColor(BaseColor.PINK);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
cell = new PdfPCell(new Phrase(chunk2Text));
cell.setBorder(0);
cell.setPadding(0);
cell.setPaddingBottom(1f);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setRowspan(1);
cell.setBackgroundColor(BaseColor.PINK);
cell.isUseBorderPadding();
table.addCell(cell);
FileOutputStream fos=new FileOutputStream(DEST);
PdfWriter writer = PdfWriter.getInstance(document, fos);
document.open();
document.add(table);
Float height=table.getTotalHeight();
System.out.println(table.getTotalHeight()+"::"+table.getTotalWidth());
document.close();
fos.close();
writer.close();
Rectangle pagesize = new Rectangle(85f, height+(border*2));
pagesize.setBorder(Rectangle.BOX);
pagesize.setBorderWidth(border);
document = new Document(pagesize, border, border,border, border);
fos=new FileOutputStream(DEST);
writer = PdfWriter.getInstance(document, fos);
document.open();
document.add(table);
document.close();
fos.close();
writer.close();
}
}
は、誰もが国境とテーブルの間に薄い間隔がどこから来ているお勧めできますし、どのように私はit.Thanksを削除することができます。
サンプルにコードが多すぎます。あなたの質問に関係のない部分を削除してください。あなたの質問に答えたい人は、関係のないものから関連性のあるものを解き放つために、あまりにも多くの時間を尋ねていると決めるかもしれません。 –