亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

iText 7 - 重新生成使用 Adob??e 創建的條碼字段

iText 7 - 重新生成使用 Adob??e 創建的條碼字段

千萬里不及你 2023-05-17 16:52:56
我來找你是因為我有一個問題!我使用 Adobe Acrobat 在 acroform PDF 中創建了條碼。我可以將新值設置為 barCode 字段,但我無法使用新值生成新的“外觀”。我怎樣才能做到這一點 ?這就是我現在做的沒有成功......:PdfFormField field = fields.get("QRCODE");field.setValue(this.generateXMLDataMatrix(),false);form = form.setNeedAppearances(true);form.flattenFields();pdf.close();    所以現在,我仍然擁有在 Adobe Acrobat 中創建的默認外觀 :(謝謝你的幫助 !:)
查看完整描述

2 回答

?
慕桂英3389331

TA貢獻2036條經驗 獲得超8個贊

您將必須手動生成字段外觀。這是一個如何為 QR 碼執行此操作的示例:


PdfFormField field = fields.get("QRCODE");

// Get the annotation. If you might have multiple representations of the same field across the document the just iterate over all widgets

PdfWidgetAnnotation annotation = field.getWidgets().get(0);

// This class will help us draw the barcode

BarcodeQRCode qrCode = new BarcodeQRCode(this.generateXMLDataMatrix());

// Get the number of rectangles constituting the barcode

Rectangle size = qrCode.getBarcodeSize();

// Creating a new FormXObject that will become our apperance. Set the dimension(bbox) of the current appearance

PdfFormXObject newAppearance = new PdfFormXObject(annotation.getAppearanceObject(PdfName.N).getAsRectangle(PdfName.BBox));

// Helper class to draw on FormXObject

PdfCanvas barcodeCanvas = new PdfCanvas(newAppearance, pdfDocument);

// Calculating the side of the smaller rectangle in the barcode

float side = Math.min(annotation.getRectangle().toRectangle().getHeight() / size.getHeight(),

        annotation.getRectangle().toRectangle().getWidth() / size.getWidth());

// Draw the barcode on the XObject

qrCode.placeBarcode(barcodeCanvas, ColorConstants.BLACK, side);

// Set appearance to the newly generated one

annotation.setAppearance(PdfName.N, newAppearance.getPdfObject());


查看完整回答
反對 回復 2023-05-17
?
12345678_0001

TA貢獻1802條經驗 獲得超5個贊

解決了!這就是我最終做到的:


    //Generate BarCodedataMatrix

    BarcodeDataMatrix dataMatrix = new BarcodeDataMatrix();

    //Add code to the BarCodedataMatrix

    dataMatrix.setCode(generateXMLDataMatrix());

    dataMatrix.setOptions(BarcodeDataMatrix.DM_AUTO);

    //Add dataMatrix to PDF

    //Create a canvas for the first page

    PdfCanvas canvas = new PdfCanvas(pdf.getFirstPage());

    //Create the PdfFormXObject based on the dataMatrix

    PdfFormXObject object = dataMatrix.createFormXObject(pdf);

    //Add the pdfFormXObject to the canvas at X,Y position

    canvas.addXObject(object,50,660);


查看完整回答
反對 回復 2023-05-17
  • 2 回答
  • 0 關注
  • 258 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號