+ Start a Discussion
Luke Osmundson 2Luke Osmundson 2 

Fill out existing user-submitted PDF form programatically

I am looking for a way to fill out PDF forms programatically (and for free, so not Conga). We have a way to fill out DOCX forms, so either we need a way to convert DOCX to PDF client side, or a way to merge data into a PDF. This needs to be accomplished with a single click from the user, and uploaded directly to a file sharing site without any further user intervention. The program also needs to be Win10 compatible, so ActiveX is not a viable solution. It also should function without any preexisting custom code on the computer at hand, although it can be assumed that Adobe Acrobat and Microsoft Word will be available on the computer.  I also need to be able to take in an arbitrary PDF document or Word document as the input, which prevents the use of the renderas feature as being a solution. 

I am capable of writing custom code for this, however as far as I know, there is no PDF library for Javascript (excluding Node.IO) or Apex. I already have functioning code that edits the text in the DOCX, I would just need to convert it to PDF clientside somehow.
 
Martijn SchwarzerMartijn Schwarzer
Hi Luke,

This can be done using Visualforce. You create a visualforce page which has the look and feel of the pdf you need. In your apex controller, you can set the field values from the user-submitted form (for example by the use of url parameters).

You can then in Apex retrieve the contents of that page as pdf and send it to any webservice you want (or save it as an attachment in SF).

The code to do so can look like this:
 
Pagereference pr = Page.YourVisualforcePageName;
//repeat the following line for each parameter
pr.getParameters().put('parameter_name', 'parameter_value');

//Get the page contents as PDF
Blob b = pr.getContentsAsPDF();

Hope this helps!

Best regards,
Martijn Schwärzer

Ps. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer
Luke Osmundson 2Luke Osmundson 2
Thanks for the reply, I missed adding in the fact that I need to fill arbitrary PDF forms submitted by the user. I have already written something that does this function for DOCX, so I need either a way to translate DOCX to PDF, or a way to fill arbitrary PDFs.