我正在研究最终用户填写 pdf 文档并单击按钮生成带有字段值的条形码的用例......我正在 PDFBox 或 IText7 或 Aspose 中寻找解决方案......
我使用上述参考资料创建了可编辑的 pdf 文档。
我尝试过 itext7 和 PDFBox 但没有成功
我不认为直接使用Aspose.PDF可以实现这些要求。您可以在按钮后面指定要触发的 JavaScript 方法,然后 Adobe Reader 使用自己的引擎/调试器执行该操作。
您无法告诉 Adobe Reader 使用 Aspose.Barcode 生成条形码图像并将其添加到 PDF 中。
有一个可以尝试的解决方法。我不确定它是否适用于所有情况,但值得一试。即
使用Aspose.Barcode生成条形码图像的代码:
BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Pdf417, "Åspóse.Barcóde©");
gen.Parameters.Barcode.XDimension.Pixels = 2;
gen.Parameters.Barcode.Pdf417.Columns = 3;
gen.Save("Pdf417Basic.png", BarCodeImageFormat.Png);
使用 Aspose.PDF 指定 PDF 按钮后面的 JavaScript 操作的代码:
var userInput = this.getField("userInput").value; // Get user input from the text field
// Execute your console application with userInput as an argument
// You can use the 'app.execMenuItem' function to execute an external command
// For example:
var result = app.execMenuItem("App.exec", "your_console_app.exe " + userInput);
if (result == 0) {
// Success: The console application executed
// Now, you can add the generated image to the PDF
var imageRect = this.getPageBox("Crop", this.pageNum);
this.addImage({
cName: "GeneratedImage",
nPage: this.pageNum,
rCrop: imageRect,
cPath: "path_to_generated_image.jpg"
});
}
可以使用以下方法将上面的 JS Action 添加到按钮后面:
field.Actions.OnPressMouseBtn = new JavascriptAction(opendocscript);
您可以尝试以上解决方法。我希望它能帮助你。如果您遇到任何问题,请在官方Aspose 支持论坛 中创建帖子,您将获得相应的帮助。我是 Asad Ali,我是 Aspose 的开发人员布道者。