These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Logging overwriting with Extractpages

ingrimm
Registered: Oct 11 2010
Posts: 1

Dear members,
 
I'm new to this forum and to Acrobat-Development at all.
 
We're using a script to get a specific String from vectorized PDF Files. This string should be used as filename for a copy of the complete pdf.
 
The Process is like this:
1. We send some printed PDF's to our clients (600-1000 /14 days)
2. The Clients check if the given Data on their Pdf's is correct, make some corrections to it and send it back to us.
3. A co-worker of mine, uses our scanner to scan all those recieved letters and save them as pdf file with a timestamp as filename
4. We are running the script then which runs the ocr-feature, and returns the client-id from the head of the file, which will then be used as the filename for the new file (done with extractpages).
 
The Problem here is, that sometimes our scanner/co-worker gets something wrong and this results in 2 different pdf-scans with the same client-id.
 
If we run the script then, one of those files will be automatically overwritten.
I want to log all these files.
 
I'm using this script to get the client-id from the pdf files and save in a new file:

var idNumber = /08\d\d\d\d\-\d\d\d\-\d\d\d\d\d-\d\d\d/g;
function ExtractFromDocument(reMatch)
{
    try {
           var Out = new Object(); 
           for (var i = 0; i < 1; i++)
        {
            numWords = this.getPageNumWords(i);
            var PageText = "";
            for (var j = 0; j < 30;j++) {
                var word = this.getPageNthWord(i,j,false);
                PageText += word;
            }
            var strMatches = PageText.match(reMatch);
            if (strMatches == null) continue;
        }
        return strMatches;
    } catch(e)
    {
        app.alert("Processing error: "+e)
    }
}
var filename = ExtractFromDocument(idNumber);
&nbsp;<br />
// this is just in case the ocr-part fails. then the file is saved with a random_numer.pdf
if(filename == null || filename == undefined) {
    filename = Math.round(Math.random()*999999999999);
    this.extractPages({nEnd:(this.numPages-1), cPath : "../GAG-out/"+filename+".pdf"});
} else {
//this is the right case
   this.extractPages({nEnd:(this.numPages-1), cPath : "../GAG-out/"+filename+"-001.pdf"});
&nbsp;<br />
}

 
does extractPages offer a flag or event that says: "Hello User i have just overritten another file and 'this' was its original filename"?
 
Do you have any other ideas that could point me in the right direction?
 
greetings
 
Michael

try67
Expert
Registered: Oct 30 2008
Posts: 2398
What you can try is to open the files yourself using app.openDoc(). If the result is not null, then you know the file already exists, and you can alert the user. If the file does not exist it will return null, and then you know you can continue safely.
One problem is that the files must be disclosed in order to open (see the reference of openDoc for more info).

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com