• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Merging Pdf files in directories

New Here ,
Sep 14, 2009 Sep 14, 2009

Copy link to clipboard

Copied

I am completely new to this. I have tons of directories with pdf files which i want to merge and i need to do it programatically, The contents of each directory (i.e pdf) should be merged and the name of the final pdf for each directory (i.e. 1900) should be the name of the directory itself.(i.e. 1900.pdf)

My folder structure looks like this

c:\ 

|

|--------- Batch 1

|              |___ 1900   (each directory here contains the pdf files that are to be merged)      

|              |___ 1901

|              |___ 1902

|               etc

|

|---------- Batch 2

|              |____1990

|              |____1991

|               etc

I need to get the code to go through each folder/directory and generate a list of the files, then merge the files in each directory using each direcory name as the name the file for each directory.

My research shows that i need to generate a list of the directory and files then use <cfpdf> but i'm stuck. Please HELP

TOPICS
Advanced techniques

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 24, 2009 Sep 24, 2009

I didn't manage to get any errors like yours, but I found it pretty easy for my server instance to run out of heap space when merging a few non-very-big PDF files.  Which doesn't impress me too much.

--

Adam

Votes

Translate

Translate
New Here ,
Sep 24, 2009 Sep 24, 2009

Copy link to clipboard

Copied

I hope i will get an answer this time

So far i have been able to pass the directory and file information to a <cfpdf> tag which will merge the files in each directory using the directory name as the final file output for each directory.

However, the tag throws up an error: 
Here is the code:
<cfdirectory action="list" directory="D:\Dox" name="filelist">

<cfset tempPath=""> <cfloop query="filelist">

<cfset fPath="#directory#\#filelist.name#">

<cfpdf action="merge" directory="#fpath#" destination="D:\dox\#filelist.name#\#filelist.name#.pdf" overwrite="yes"> </cfloop>

and i get the error below, i have tried to, store and retrieve the directory and filename in a database, still the same problem. Can anyone tell me what i am missing

The error is below:

The system has attempted to use an undefined value, which usually indicates a  programming error, either in your code or some system code.  Null Pointers are another name for undefined values.     

The error occurred in C:\wamp\www\codex\tesk.cfm: line 14

12 : <cfloop query="filelist">

13 : <cfset fPath="#directory#\#filelist.name#">

14 : <cfpdf action="merge" directory="#fpath#"  destination="D:\pdfgen\#filelist.name#\#filelist.name#.pdf" overwrite="yes">

15 : </cfloop>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 24, 2009 Sep 24, 2009

Copy link to clipboard

Copied

Just for the sake of debugging, in your <cfloop> can you output (or log) all the variables that you're passing to <cfpdf> and check they hold what you expect them to hold.  At the same time, it'll give you an idea if the process is failing outright, or whether, say, the PDFs in some specific subdir are giving you a problem.

What does this code do if you try to merge PDFs in an empty subdir, btw?

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 24, 2009 Sep 24, 2009

Copy link to clipboard

Copied

>Just for the sake of debugging, in your <cfloop> can you output (or log) all the variables that you're passing to <cfpdf> and check they hold what you > >expect them to hold.

They certainly hold what i expected, I used the code below to output the variables

<cfdirectory action="list" directory="D:\dox" name="filelist">

<cfset tempPath="">

<cfloop query="filelist">

<cfset fPath="#directory#\#filelist.name#">

<cfoutput>#directory#\#filelist.name#\<br></cfoutput>

</cfloop>

and i got the directories and subdirectories which is now passed to <cfpdf>

D:\dox\1662\
D:\dox\1846\
D:\dox\1901\
D:\dox\1902\
D:\dox\3498\
D:\dox\69\
D:\dox\8730\

> What does this code do if you try to merge PDFs in an empty subdir, btw?

It simply goes through without generating any error at all, i tried it on an empty directory.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 24, 2009 Sep 24, 2009

Copy link to clipboard

Copied

Cool.  So, back to the other question I asked: is it halting on a particular subdir, or is it just faceplanting on the very first one?

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 24, 2009 Sep 24, 2009

Copy link to clipboard

Copied

it merges the files in the first directory and outputs them to the required file, then it stops.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 24, 2009 Sep 24, 2009

Copy link to clipboard

Copied

OK.  Can you try to run the process just on that second dir?  Why I ask is perhaps <cfpdf> might not clear up after itself properly, and be failing as a matter of course on the second call.  Or it could be something in that second dir <cfpdf> doesn't like.

If - when you just run on the second dir - it still crashes, check for any obvious differences between the two dirs?  How many PDFs are we talking?  Is it viable to omit each one, one at a time from the merge (renaming a file to .dud or something should omit it... or to be on the safe side move it right out of the dir)?  I've of some PDFs not working so well with CF's PDF ops.

If none of that crashes, can you re-try the entire process, but move that second dir out of the way first (so the third dir becomes the second dir, if you see what I mean).

In the mean time, I'll set up a similar rig here and see what I get.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 24, 2009 Sep 24, 2009

Copy link to clipboard

Copied

What i did was to start moving out each directory and running the code, I ended up moving out three directories out, the code worked successfully through the remaining 4 directories without any problem.

Initially I thought that that the issue had to do with the compatibility of the pdf files. But again I copied the contents of the directories that i moved out into some of the directories and ran the code and it worked perfectly, which left me confused as to what the problem could really be. I'm glad though that the code is working in some directories. Many thanks for your time, please let me know your findings with the one you set up. thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 24, 2009 Sep 24, 2009

Copy link to clipboard

Copied

LATEST

I didn't manage to get any errors like yours, but I found it pretty easy for my server instance to run out of heap space when merging a few non-very-big PDF files.  Which doesn't impress me too much.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation