如何在iText中设置条形码的位置和宽度?

时间:2018-12-14 19:12:25

标签: java swing itext barcode

我想更改条形码的位置或位置,以将其向下移动一点并将文本放置在其上方,并且我还想更改其宽度。

这是我的代码:

    try {
        Document d = new Document(new Rectangle(PageSize.A4));
        d.setMargins(10, 10, 10, 10);
        System.out.println(d.getPageSize());

        com.itextpdf.text.Font esm_sherka_font = FontFactory.getFont("C:\\Windows\\Fonts\\arial.ttf", BaseFont.IDENTITY_H, 10, Font.PLAIN);
        Paragraph esm_sherka = new Paragraph(esm_sherkaEBA_txt.getText(),esm_sherka_font);

        com.itextpdf.text.Font esm_sanf_font = FontFactory.getFont("C:\\Windows\\Fonts\\arial.ttf", BaseFont.IDENTITY_H, 10, Font.PLAIN);
        Paragraph esm_sanf = new Paragraph(sanfMA5E_txt.getText(),esm_sanf_font);

        Barcode128 barcode = new Barcode128();
        barcode.setCode(barcodeMA5E_txt.getText());

        PdfWriter p = PdfWriter.getInstance(d, new FileOutputStream(barcodeMA5E_txt.getText() + ".pdf"));

        d.open();

        ColumnText sanf_canvas = new ColumnText(p.getDirectContent());
        sanf_canvas.setSimpleColumn(10, 750, 559, 800);
        sanf_canvas.setRunDirection(PdfWriter.RUN_DIRECTION_LTR);
        sanf_canvas.addElement(esm_sanf);
        sanf_canvas.go();

        d.add(barcode.createImageWithBarcode(p.getDirectContent(), null, null));

        ColumnText sherka_canvas = new ColumnText(p.getDirectContent());
        sherka_canvas.setSimpleColumn(10, 750, 559, 842);
        sherka_canvas.setRunDirection(PdfWriter.RUN_DIRECTION_LTR);
        sherka_canvas.addElement(esm_sherka);
        sherka_canvas.go();


        d.close();

    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();

0 个答案:

没有答案