Javascript 如何在itext 5中使用按钮作为图像字段
任何人都可以帮助我使用java代码使用按钮作为图像字段使用itext 5。我尝试了下面的代码,但不起作用Javascript 如何在itext 5中使用按钮作为图像字段,javascript,java,itext,Javascript,Java,Itext,任何人都可以帮助我使用java代码使用按钮作为图像字段使用itext 5。我尝试了下面的代码,但不起作用 com.itextpdf.text.pdf.PushbuttonField button = new com.itextpdf.text.pdf.PushbuttonField(writer, new com.itextpdf.text.Rectangle(90, 500, 140, 800), "submit"); button.setText("POST"); button.setBac
com.itextpdf.text.pdf.PushbuttonField button = new com.itextpdf.text.pdf.PushbuttonField(writer, new com.itextpdf.text.Rectangle(90, 500, 140, 800), "submit");
button.setText("POST");
button.setBackgroundColor(new com.itextpdf.text.BaseColor(255, 255, 255));
button.setVisibility(com.itextpdf.text.pdf.PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT);
com.itextpdf.text.pdf.PdfFormField submit = button.getField();
submit.setAction(com.itextpdf.text.pdf.PdfAction.createSubmitForm("/book/fdf", null, 0));
writer.addAnnotation(submit);
com.itextpdf.text.pdf.TextField file = new com.itextpdf.text.pdf.TextField(writer, new com.itextpdf.text.Rectangle(90, 500, 140, 800), "image");
file.setOptions(com.itextpdf.text.pdf.PushbuttonField.FILE_SELECTION);
com.itextpdf.text.pdf.PdfFormField upload = file.getTextField();
upload.setAdditionalActions(com.itextpdf.text.pdf.PdfName.U, com.itextpdf.text.pdf.PdfAction.javaScript("this.getField('image').browseForFileToSubmit();"+ "this.getField('submit').setFocus();", writer));
writer.addAnnotation(upload);
试试这个:
<div class="col-md-2">
<label for="pre">
Your Image
</label>
<a id="pre" onclick="$('#imagetr').trigger('click'); ">
<img id="preview" class="col img img-fluid" src="images/defaultloadimage.jpg" title="your default place holder" />
</a>
<input type="file" name="image" id="imagetr" style="display:none;" />
你的形象
函数readURL(输入){
if(input.files&&input.files[0]){
var reader=new FileReader();
reader.onload=函数(e){
$('#preview').attr('src',e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$(“#imagetr”)。更改(函数(){
readURL(this);
});
感谢Javad的回复。我不熟悉iText,我正在使用iTextJava代码生成PDF文档。我正在使用PdfFormFields添加文本框和复选框字段。是否有任何方法将图像字段添加为表单字段?实际的PDF表单技术AcroForm forms不提供图像字段类型。对于某些上下文,一个可用的解决方法是使用一个按钮,该按钮的外观被更改以嵌入图像。这对你合适吗?是的,这对我很有帮助。我读过这篇文章,但无法理解如何准确地实施它。你能帮我实现这个-@mklco的代码吗?考虑到你的编辑,你似乎想将PDF表单作为fdf发布。这有点关键,因为图像不是按钮的值,而仅仅是它的外观,因此它不会作为简单的fdf post的一部分传输。如果设置IncludeAppendSaves提交表单操作标志,则任何添加的图像都将包含在增量更新中。顺便说一下,从一开始就不清楚是否要从PDF查看器发布表单。我想知道的答案是如何使用iText替换按钮字段的图像,以及如何使用iText提取它
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#preview').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imagetr").change(function () {
readURL(this);
});
</script>