Merge .pdf's into one .pdf using cfpf merge
Filed under ColdFusion , T-SQL
I needed to print a large group of customer Orders by date in .pdf format. Instead of having an employee individually click and sort 2000 .pdf's each day, (Yes they were doing that) I set up a little web application to do all the sorting for them. I first needed to get an OCR software that could read characters off of large .pdf file, split the .pdf into individual .pdfs by customer order number and store specific data into a database. After that task was complete I needed to make a simple interface for an employee to click specific dates or groups of customer orders. So first I made a query that grabbed specfic order numbers based on a date selected. The query is below:
|
<cfquery name="Printpdf" datasource="dsnTest"> CONVERT(VARCHAR(10),<cfqueryparam
cfsqltype="cf_sql_date" value="#URL.date#"> , 101) |
I had the OCR software name each .pdf by the customer order number as it was a unique number. I then created a loop that copied the .pdf's from one folder and pasted them into another folder based on the order numbers queried above. The loop uses a simple <cffile action="copy"> to copy and move the the .pdf's into my destination folder.
| <cfset pdfFolder = expandPath("../pdf")> <cfset batchFolder = expandPath("./temp")> <cfloop query="Printpdf" startrow="1" endrow="#Printpdf.recordcount#"> <cffile action="copy" source="#pdfFolder#\#OrderNum#.pdf" destination ="#batchFolder#"> </cfloop> |
I then merged all the selected .pdf's into one large .pdf using the <cfpdf action="merge"> tag introduced in ColdFusion 8 (I believe).
| <cfpdf action="merge" directory="#batchFolder#" name="mergedpdf"> |
After the merge I printed the created .pdf using <cfprint> tag.
| <cfprint type="pdf" source="#batchFolder#\mergedpdf.pdf"> <cfcontent type="application/pdf" reset="true" variable="#batchFolder#\#mergedpdf#" |
After the print I updated the database with the person who printed the documents and at what date/time. It should be known that >cffile� will will overwrite any file with the same name. Don't know if there is an easier way to this but it got the job done ;)
| View count: 1342Oct30








