Hello, I’m trying to use the PDF plugin but am running against some problems.
I’ve made a PDF containing some fields.
I have stored the PDF-form in a media field in my database.
now i want to get the PDF from the database , fill the form-fieldwith some data in my application and send the pdf as a email attachment.
filling of the field doesn’t work.
is it ok to get the pdf from the media field and store it in a variable or should i do something else first?
how do i fill the field in the pdf?
Are you just trying to pre-fill field data on to the PDF form and then email the form? Will all the users have the full Adobe Acrobat, or will some just have the free Adobe Reader? Have you already looked at the sample pdf form solution? Does your solution use smartclient or webclient?
Are you just trying to pre-fill field data on to the PDF form and then email the form? Will all the users have the full Adobe Acrobat, or will some just have the free Adobe Reader? Have you already looked at the sample pdf form solution? Does your solution use smartclient or webclient?
Dean Westover
Choices Software, Inc.
Hi Dean,
yes I prefill field data on the pdf form and then mail want to the form as pdf since most users will anoly have acorbat reader. My solutions uses webclient.
I have looked at the sample pdf solution. I will now loo at the pdf tutorial on the servoy website.
We have been using the PDF form plugin with web client for two years. If you are not able to find what you need, let me know and I will put together some sample code for you.
Westy:
We have been using the PDF form plugin with web client for two years. If you are not able to find what you need, let me know and I will put together some sample code for you.
Dean Westover
Choices Software, Inc.
that would be great Dean.
I am a Servoy newby and i am realy stuck here.
The following may be the long way, but it should work. The advantage of this approach it that is shows you a little about how an Adobe Acrobat FDF (forms data format) file is structured, which could come in handy if you ever need to do something out of the ordinary.
var thepdfblob
globals.selected_template = template_id;
//build a forms data format file
var fdf
//header of fdf file is always the same
fdf = '%FDF-1.2\n1 0 obj\n\n<</FDF<</Fields[\n\n'
//create field name/field value pairs
fdf += '<</T(first_name)/V(John)>>\n'
fdf += '<</T(last_name)/V(Doe)>>\n'
//footer of fdf file is always the same
fdf += '\n]\n\n/F (Form.pdf)\n\n>>>>\n\nendobj\ntrailer\n<</Root 1 0 R>>\n%%EOF\n'
var pdf_data = application.createTempFile('pdf_data','.fdf')
plugins.file.writeTXTFile(pdf_data, fdf)
//get the pdf form template
var pdf_form = global_selected_templateid_to_pdf_templates.actual_pdf_form;
//combine the form template with the form data
thepdfblob = plugins.pdf_output.convertPDFFormToPDFDocument(pdf_form, pdf_data)
//write flattened pdf to server ROOT directory in a subfolder named 'flattened_pdf'
var installdir = java.lang.System.getProperty("user.dir");
installdir = utils.stringReplace(installdir,'\\','\/');
var random_number = Math.round(Math.random()*(99999-11111)+1);
//make sure you have a folder named 'flattened_pdf' in the ROOT folder
var filepath=installdir+'/server/webapps/ROOT/flattened_pdf/'+'Form-'+ random_number +'.pdf';
plugins.file.writeFile(plugins.file.convertToJSFile(filepath), thepdfblob)
if (application.getApplicationType()==5)
{
application.showURL('/flattened_pdf/' + path,'_self')
}
else
{
application.showURL(filepath,'_self')
}
The above writes the flattened pdf to a folder within the Tomcat server root directory. From there it can be opened and emailed. Alternatively, I think it is now possible to save the flattened pdf form file to a media field (so you would not have to keep deleting files from the server). See Paul’s example code at: http://forum.servoy.com/viewtopic.php?t=7537&start=0
Also, please note that the field names within an Acrobat FDF file are case sensitive. One of those little things that can drive you crazy if you are not aware of it.
To learn more about FDF files, on Windows try copying the following code to notepad and then save to a file with a name that ends with “.FDF”. Then place your pdf form in the same folder. Make sure that the name following /F in the FDF file matches your PDF file name. Make sure the field names in the FDF file match any two field names in your pdf file. Then double-click the FDF file. It will open the pdf file and auto-fill the field data to the form fields that have matching names. It gets better. The form name in the FDF file can be a local or remote path to the pdf form template file. In other words you can auto-fill another pdf file that is located anywhere in the world just by double-clicking the FDF file. Better yet, you can email the FDF file to someone anywhere in the world and when the recipient opens the FDF file it will automatically grab the appropriate PDF file (that can be located anyhwhere) and display it with the FDF file’s data. This means that you can send someone what appears to be a filled-in PDF file by only emailing them a tiny little FDF file that you created with Notepad (or created on the fly with a Servoy method).
I just installed Servoy 3.5.6 and tried the sample PDF form solution. I agree with Patrick that the form fill does not appear to be working. It would be nice to have this fixed because it looks like the plugin now has the ability to do fillin with much less code than I discribed above.
Other possible issues with the sample pdf form solution:
On the sample Address1.pdf file the “action_id” field should be re-named “servoy_action_id” according to page 548 of the Reference Guide.
The Address1.pdf file appears to be the only sample
pdf file that has a submit button. This means that it is the only one that will work with the free Adobe Reader.
Westy:
I agree with Patrick that the form fill does not appear to be working.
It works for me. The workings of the sample solution might not be very clear though: in the solution template screen, you open the template PDF file - NOT a form instance. This is why you can’t edit it.
On the solution pdf form screen, you open a form instance. Here, you can edit field values.
Westy:
Other possible issues with the sample pdf form solution:
On the sample Address1.pdf file the “action_id” field should be re-named “servoy_action_id” according to page 548 of the Reference Guide.
Oops. You’re right, thanks for noting. We’ll fix it.
Westy:
2. The Address1.pdf file appears to be the only sample
pdf file that has a submit button. This means that it is the only one that will work with the free Adobe Reader.
When you open a form instance, you’ll notice a green submit button is inserted top-left.
Westy:
I agree with Patrick that the form fill does not appear to be working.
It works for me…
Hi Sandor,
Sorry, I was not communicating clearly. What I meant to say is that the “Default Values” defined for a template are not auto-filling their data to a fill-in PDF form. This can be fixed as follows:
Add “pdf_forms_to_pdf_form_values” relation to pdf_forms based on form_id to form_id.
Add “pdf_forms_to_pdf_template_values” relation to pdf_forms based on template_id to template_id.
Then insert the following code in the globals btn_viewPDF method right after the line that says “//it’s a document”:
//PDF Database Template Defaults
for ( var i = 0 ; i < forms.frm_forms.pdf_forms_to_pdf_template_values.getMaxRecordIndex() ; i++ )
{
forms.frm_forms.pdf_forms_to_pdf_template_values.recordIndex = i;
forms.frm_forms.pdf_forms_to_pdf_form_values.newRecord();
forms.frm_forms.pdf_forms_to_pdf_form_values.value_name = forms.frm_forms.pdf_forms_to_pdf_template_values.value_name;
forms.frm_forms.pdf_forms_to_pdf_form_values.field_value = forms.frm_forms.pdf_forms_to_pdf_template_values.default_value;
}
Westy:
2. The Address1.pdf file appears to be the only sample
pdf file that has a submit button. This means that it is the only one that will work with the free Adobe Reader.
When you open a form instance, you’ll notice a green submit button is inserted top-left.
Yes, but I think that only happens if the user has the full version of Adobe Acrobat installed (which gives them the rights to alter fields). Also, those who take the time to create fill-in PDF forms, will commonly protect them so that fields can not be added or modified on the fly.
End users will typically only have the free Adobe Reader installed, which does not allow fields to be added or modified. These users will not see the required green submit button. For this reason we always manually place the green submit button (and the other two required fields) on all PDF forms. This allows the PDF form submit button to work with both the full version of Adobe Acrobat and with the free Adobe Reader.
It may be better if all the Servoy sample PDF forms have the required three fields placed on the forms in the exact same position that they would be automatically placed on the form if the user has the full version of Acrobat. This approach will allow users to submit the forms reqardless of which version of Adobe Acrobat they are using.