how to use push button as image field in itext 5
can anyone please help me with the java code to use push button as an image field using itext 5. I have tried the below code but does not work
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);
javascript java itext
add a comment |
can anyone please help me with the java code to use push button as an image field using itext 5. I have tried the below code but does not work
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);
javascript java itext
The actual PDF form technology, AcroForm forms, does not offer an image field type. For some contexts an usable work-around is to use a push button the appearance of which is changed to embed the image. Would this be ok for you?
– mkl
Nov 13 '18 at 9:22
Yes this would help me a lot. I read about this but not able to understand how exactly to implement it. Can you please help me with the code for implementing this - @mkl
– SACHIN S.M
Nov 13 '18 at 9:28
Considering your edit you appear to want to post the PDF form as fdf. This is a bit critical as the image is not the value of the push button but merely its appearance, so it is not transmitted as part of a simple fdf post. If you set the IncludeAppendSaves submit-form action flag, any added image will be included in the incremental updates.
– mkl
Nov 13 '18 at 10:43
By the way, it wasn't clear from the start that you wanted to post the form from a PDF viewer. The answer I had in mind would have shown how to replace the image of a pushbutton field using iText and probably how to extract it using itext.
– mkl
Nov 13 '18 at 10:48
Yes i want to post the form from pdf viewer
– SACHIN S.M
Nov 13 '18 at 11:02
add a comment |
can anyone please help me with the java code to use push button as an image field using itext 5. I have tried the below code but does not work
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);
javascript java itext
can anyone please help me with the java code to use push button as an image field using itext 5. I have tried the below code but does not work
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);
javascript java itext
javascript java itext
edited Nov 13 '18 at 10:34
mkl
52.8k1166144
52.8k1166144
asked Nov 13 '18 at 7:10
SACHIN S.MSACHIN S.M
12
12
The actual PDF form technology, AcroForm forms, does not offer an image field type. For some contexts an usable work-around is to use a push button the appearance of which is changed to embed the image. Would this be ok for you?
– mkl
Nov 13 '18 at 9:22
Yes this would help me a lot. I read about this but not able to understand how exactly to implement it. Can you please help me with the code for implementing this - @mkl
– SACHIN S.M
Nov 13 '18 at 9:28
Considering your edit you appear to want to post the PDF form as fdf. This is a bit critical as the image is not the value of the push button but merely its appearance, so it is not transmitted as part of a simple fdf post. If you set the IncludeAppendSaves submit-form action flag, any added image will be included in the incremental updates.
– mkl
Nov 13 '18 at 10:43
By the way, it wasn't clear from the start that you wanted to post the form from a PDF viewer. The answer I had in mind would have shown how to replace the image of a pushbutton field using iText and probably how to extract it using itext.
– mkl
Nov 13 '18 at 10:48
Yes i want to post the form from pdf viewer
– SACHIN S.M
Nov 13 '18 at 11:02
add a comment |
The actual PDF form technology, AcroForm forms, does not offer an image field type. For some contexts an usable work-around is to use a push button the appearance of which is changed to embed the image. Would this be ok for you?
– mkl
Nov 13 '18 at 9:22
Yes this would help me a lot. I read about this but not able to understand how exactly to implement it. Can you please help me with the code for implementing this - @mkl
– SACHIN S.M
Nov 13 '18 at 9:28
Considering your edit you appear to want to post the PDF form as fdf. This is a bit critical as the image is not the value of the push button but merely its appearance, so it is not transmitted as part of a simple fdf post. If you set the IncludeAppendSaves submit-form action flag, any added image will be included in the incremental updates.
– mkl
Nov 13 '18 at 10:43
By the way, it wasn't clear from the start that you wanted to post the form from a PDF viewer. The answer I had in mind would have shown how to replace the image of a pushbutton field using iText and probably how to extract it using itext.
– mkl
Nov 13 '18 at 10:48
Yes i want to post the form from pdf viewer
– SACHIN S.M
Nov 13 '18 at 11:02
The actual PDF form technology, AcroForm forms, does not offer an image field type. For some contexts an usable work-around is to use a push button the appearance of which is changed to embed the image. Would this be ok for you?
– mkl
Nov 13 '18 at 9:22
The actual PDF form technology, AcroForm forms, does not offer an image field type. For some contexts an usable work-around is to use a push button the appearance of which is changed to embed the image. Would this be ok for you?
– mkl
Nov 13 '18 at 9:22
Yes this would help me a lot. I read about this but not able to understand how exactly to implement it. Can you please help me with the code for implementing this - @mkl
– SACHIN S.M
Nov 13 '18 at 9:28
Yes this would help me a lot. I read about this but not able to understand how exactly to implement it. Can you please help me with the code for implementing this - @mkl
– SACHIN S.M
Nov 13 '18 at 9:28
Considering your edit you appear to want to post the PDF form as fdf. This is a bit critical as the image is not the value of the push button but merely its appearance, so it is not transmitted as part of a simple fdf post. If you set the IncludeAppendSaves submit-form action flag, any added image will be included in the incremental updates.
– mkl
Nov 13 '18 at 10:43
Considering your edit you appear to want to post the PDF form as fdf. This is a bit critical as the image is not the value of the push button but merely its appearance, so it is not transmitted as part of a simple fdf post. If you set the IncludeAppendSaves submit-form action flag, any added image will be included in the incremental updates.
– mkl
Nov 13 '18 at 10:43
By the way, it wasn't clear from the start that you wanted to post the form from a PDF viewer. The answer I had in mind would have shown how to replace the image of a pushbutton field using iText and probably how to extract it using itext.
– mkl
Nov 13 '18 at 10:48
By the way, it wasn't clear from the start that you wanted to post the form from a PDF viewer. The answer I had in mind would have shown how to replace the image of a pushbutton field using iText and probably how to extract it using itext.
– mkl
Nov 13 '18 at 10:48
Yes i want to post the form from pdf viewer
– SACHIN S.M
Nov 13 '18 at 11:02
Yes i want to post the form from pdf viewer
– SACHIN S.M
Nov 13 '18 at 11:02
add a comment |
1 Answer
1
active
oldest
votes
try this one:
<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;" />
<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>
Thanks for the reply Javad. I am new to iText and i am generating the PDF document using iText java code. I am using PdfFormFields to add textbox and checkbox fields. Is there any method to add an image field as form field?
– SACHIN S.M
Nov 13 '18 at 7:36
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275644%2fhow-to-use-push-button-as-image-field-in-itext-5%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
try this one:
<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;" />
<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>
Thanks for the reply Javad. I am new to iText and i am generating the PDF document using iText java code. I am using PdfFormFields to add textbox and checkbox fields. Is there any method to add an image field as form field?
– SACHIN S.M
Nov 13 '18 at 7:36
add a comment |
try this one:
<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;" />
<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>
Thanks for the reply Javad. I am new to iText and i am generating the PDF document using iText java code. I am using PdfFormFields to add textbox and checkbox fields. Is there any method to add an image field as form field?
– SACHIN S.M
Nov 13 '18 at 7:36
add a comment |
try this one:
<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;" />
<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>
try this one:
<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;" />
<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>
answered Nov 13 '18 at 7:21
Javad V.F.Javad V.F.
11
11
Thanks for the reply Javad. I am new to iText and i am generating the PDF document using iText java code. I am using PdfFormFields to add textbox and checkbox fields. Is there any method to add an image field as form field?
– SACHIN S.M
Nov 13 '18 at 7:36
add a comment |
Thanks for the reply Javad. I am new to iText and i am generating the PDF document using iText java code. I am using PdfFormFields to add textbox and checkbox fields. Is there any method to add an image field as form field?
– SACHIN S.M
Nov 13 '18 at 7:36
Thanks for the reply Javad. I am new to iText and i am generating the PDF document using iText java code. I am using PdfFormFields to add textbox and checkbox fields. Is there any method to add an image field as form field?
– SACHIN S.M
Nov 13 '18 at 7:36
Thanks for the reply Javad. I am new to iText and i am generating the PDF document using iText java code. I am using PdfFormFields to add textbox and checkbox fields. Is there any method to add an image field as form field?
– SACHIN S.M
Nov 13 '18 at 7:36
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275644%2fhow-to-use-push-button-as-image-field-in-itext-5%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The actual PDF form technology, AcroForm forms, does not offer an image field type. For some contexts an usable work-around is to use a push button the appearance of which is changed to embed the image. Would this be ok for you?
– mkl
Nov 13 '18 at 9:22
Yes this would help me a lot. I read about this but not able to understand how exactly to implement it. Can you please help me with the code for implementing this - @mkl
– SACHIN S.M
Nov 13 '18 at 9:28
Considering your edit you appear to want to post the PDF form as fdf. This is a bit critical as the image is not the value of the push button but merely its appearance, so it is not transmitted as part of a simple fdf post. If you set the IncludeAppendSaves submit-form action flag, any added image will be included in the incremental updates.
– mkl
Nov 13 '18 at 10:43
By the way, it wasn't clear from the start that you wanted to post the form from a PDF viewer. The answer I had in mind would have shown how to replace the image of a pushbutton field using iText and probably how to extract it using itext.
– mkl
Nov 13 '18 at 10:48
Yes i want to post the form from pdf viewer
– SACHIN S.M
Nov 13 '18 at 11:02