2017-04-27 28 views
0

PDF417のバーコードを生成し、ITEXT APIを使用してフィールドIDを持つPDFフィールドに入力する必要があります。私は、このようなフィールド識別子にITEXTを使用してPDFでPDF-417を入力してください

ウェイ1

 PdfContentByte cb = stamper.getUnderContent(1); 
     BarcodePDF417 pf = new BarcodePDF417(); 
     pf.setText("Some text value for encoding"); 
     Rectangle size = pf.getBarcodeSize(); 

     PdfTemplate template = cb.createTemplate(size.getWidth(), size.getHeight()); 
     pf.placeBarcode(template, BaseColor.BLACK, 5, 5); 
     Image image = Image.getInstance(template); 
     image.setAbsolutePosition(35f, 40f); 
     cb.addImage(image); 

として、いくつかの方法を使用している

ここでの問題は、バーコードが正しいサイズのものではなく、正しい位置に配置されていないです。ここでは2

BarcodePDF417 barcode = new BarcodePDF417(); 
    barcode.setText("Some text value for encoding"); 
    barcode.placeBarcode(cb, BaseColor.BLACK, 5, 5); 

道はあまりにも問題が、バーコードは、右のサイズと同じではありません、正しい位置に配置されていません。

私はバーコードを具体的に配置する必要があるフィールドのIDENTIFIERを知っています。 セルを取得し、このセルの正確なサイズのバーコードイメージを生成して配置する方法はありますか?

ありがとうございました!

答えて

0

私は最後にこれを実装できました。私のコードは

 PdfContentByte cb = stamper.getUnderContent(i);// i being the pdf page number. 
     BarcodePDF417 barcode = new BarcodePDF417(); 
     barcode.setErrorLevel(5); 
     barcode.setCodeColumns(30); 
     barcode.setCodeRows(5); 
     barcode.setOptions(BarcodePDF417.PDF417_FIXED_RECTANGLE); 
     barcode.setText(<Byte[] - aka byte array of the text that needs to be encoded.>); 
     Rectangle rect = barcode.getBarcodeSize(); 

     PdfTemplate template = cb.createTemplate(2 + rect.getWidth(), 2 + rect.getHeight()); 

     barcode.placeBarcode(template, BaseColor.BLACK, 1, 1); 

     Image image = Image.getInstance(template); 
     image.scaleAbsolute(535, 135); 
     image.setAbsolutePosition(40f, 40f); 
     cb.addImage(image); 
です
関連する問題