Sep 13, 2016

ColdFusion and PDF Sticky Note Collaboration

I recently took an issue where a ColdFusion customer needed to build a feature to support their internal staff share comments on thousands of PDFs that were all scanned into their repository.  The PDFs were all flat and the elements were images as the result of the scanning process.
The solution I came up with was to create a small pdf, I am calling menubar.pdf, that I could merge into the PDF in their repository using cfpdf.  Then menubar.pdf would have the ability to submit the PDF back to the ColdFusion Server.  Included below is the small piece of code required to merge in the menubar.pdf.  I also placed the filename into the metadata which will be used when I send the PDF back to the ColdFusion Server.
<code>
<cfset pdfroot = "ENTER PDF WORKING DIRECTORY">
<cfset fname = "PDF NAME">
<cfpdf action = "merge"  name = "mergedpdf" >
<cfpdfparam source="#pdfroot#/menubar.pdf"  >
    <cfpdfparam source="#pdfroot#/#fname#.pdf" >
</cfpdf>
<cfset newkeywords = StructNew()>
<cfset newkeywords.keywords = fname>
<!--- Add filename int the keyword metadata and save. --->
<cfpdf action="setinfo" info = "#newkeywords#"  source="mergedpdf" destination="#pdfroot#/notes_#fname#.pdf" overwrite = "yes"> 
</code>
The result is a PDF that can now accept comments, and be submitted back to ColdFusion and saved on the server at anytime.
Below is the code which will capture the submitted PDF and returned the saved PDF with all the new comments.
<code>
<!--- **************************************************************
Capture a submitted PDF
To Do:
1. Handle Concurrency
2. Versioning
3. Add a security token to make sure pdf is one you delivered to client.
The PDF form needs a button which will submit the entire form to this PDF.
****************************************************************--->
<!--- User submitted a pdf --->
<cfset pdfroot = "ENTER PDF WORKING DIRECTORY">
<cfset uid =  createuuid()>
<cfif StructkeyExists(gethttprequestdata().headers, "Content-Type") and 
gethttprequestdata().headers["Content-Type"] EQ "application/pdf">
     <!--- Save the binary to a file to have the cfpdf tag read it
you might find a way to way to go straight to a pdf - I was not.--->
     <cffile action="write"  output="#gethttprequestdata().content#"  file="#pdfroot#\temp.pdf" nameconflict="overwrite">
     <cfpdf action="read" source="#pdfroot#/temp.pdf" name="temppdf">
     <cfpdf action="getinfo" source="temppdf" name="pdfinfo">
     <cfpdf action="write" source="temppdf" destination="notes_#pdfinfo.keywords#.pdf"  overwrite="yes">
</cfif>
<!--- Return the new PDF
If this is sent from a Browser the user will get the new PDF
If inside Acrobat a new window opens with new PDF. --->
<cfcontent type="application/pdf" file="#pdfroot#/notes_#pdfinfo.keywords#.pdf" reset="yes" >
</code>
The menubar can be as simple as a one button PDF.  I built the menubar.pdf with LiveCycle Designer and I saved it as an Adobe Static PDF.  The merge does if you save its with the default Adobe Dynamic PDF.  Here is a screen shot of the simple PDF.  You are looking at a PDF with one button that submits the entire PDF to the above capturepdf.cfm.
<img src="http://www.supportobjective.com/blog/images/pdfsubmit.jpg" width="650" />
So with these three files you have a start at building out a way to collaborate on PDFs using the awesome PDF sticky note commenting feature.
I would probably deliver the PDFs as view only at first, then have the user click a button to add notes, which would then deliver the PDF with the menubar.
Features that you will want to look if you implement something like this feature:
<ul>
<li>Versioning -  to be able to track changes</li>
<li>Concurrency - to protect form changes overwriting each other</li>
<li>Security Token -  to verify only PDFs you delivered are ones coming back in</li> 
</ul>
This should be enough to get you started with integrated ColdFusion and PDF Sticky Note collaboration.

No comments:

Post a Comment