Author Topic: Want To Create Custom Field When Stamping  (Read 7926 times)

0 Members and 1 Guest are viewing this topic.

Amazed

  • Newbie
  • *
  • Posts: 8
Want To Create Custom Field When Stamping
« on: August 16, 2016, 08:36:17 AM »
What great software. This is gonna get the job done. I can feel it. Last part.
When I stamp a document, I want to also create a custom field in that document(if it doesn't already exist) and populate that field with specific data that I determine at the time I apply the stamp.

Also, I want to able to prevent duplicate attempts to apply the same stamp on documents.

If that all makes sense? Could somebody please point me in the right direction?

Thanks.


RTT

  • Administrator
  • *****
  • Posts: 918
Re: Want To Create Custom Field When Stamping
« Reply #1 on: August 16, 2016, 11:48:10 PM »
Without more details, I suppose a My Script is the right way to execute this workflow.
Use the stamp tool to create and save the stamp template you want to apply on these files. The script will apply the stamp and populate the custom field, using also a custom field to check if the PDFs are already stamped or not. This custom field may be the same (if the field exists them it was already stamped) you will use to store that specific data you talk about.

Here is a generic sample script around this idea:
Code: [Select]
var StampTemplate = "C:\\PDFStampTemplates\\Template1.stp";

var shell = pdfe.CreateObject("WScript.Shell");
var ProgressBar = pdfe.ProgressBar;

ProgressBar.max = pdfe.SelectedFiles.Count;
for (var i = 0; i < pdfe.SelectedFiles.count; i++) {
    ProgressBar.position = i + 1;
    var doc = pdfe.SelectedFiles(i);
    var filename = doc.filename;
    if (!doc.metadata['StampData']) {
        pdfe.echo('Processing ' + filename);
        shell.Run('"' + shell.ExpandEnvironmentStrings("%PROGRAMFILES%") + '\\PDF-ShellTools\\PDFShellTools.exe" stamp -s Template="' + StampTemplate + '" "' + filename + '""', 0, true);
        doc.metadata['StampData'] = 'Your specific data';
        doc.metadata.commitchanges();
        pdfe.echo(' : done', 0, true);
    } else {
        pdfe.echo(filename + ' : already stamped');
    }
}
pdfe.echo('all done');
This script expects a stamp template at C:\PDFStampTemplates\Template1.stp, and a custom field named "StampData" defined in the list of custom fields.
In this example the stamp is using static data. If your intention is to stamp dynamic data, check this other example.

If you need further help, please give me more details.

Amazed

  • Newbie
  • *
  • Posts: 8
Re: Want To Create Custom Field When Stamping
« Reply #2 on: August 17, 2016, 12:51:00 AM »
^^ Looks like the idea. Thanks. Let me work through that.

Amazed

  • Newbie
  • *
  • Posts: 8
Re: Want To Create Custom Field When Stamping
« Reply #3 on: August 17, 2016, 08:42:31 AM »
Any way to get the current date into the script somehow so i can stuff it in the custom field?

Thanks.

Ignore. Got it, thanks.


Amazed

  • Newbie
  • *
  • Posts: 8
Re: Want To Create Custom Field When Stamping
« Reply #4 on: August 17, 2016, 11:09:11 AM »
How does one hide script output window when script is running please?
Thanks.

RTT

  • Administrator
  • *****
  • Posts: 918
Re: Want To Create Custom Field When Stamping
« Reply #5 on: August 17, 2016, 11:37:30 PM »
The stamp tool GUI will be hidden by passing the -s switch in the shell.Run... script line, as in the above script, but, as explained in the user's guide, this switch doesn't work in the trial version.
The script output window visibility is defined by script, from the manager. Check the attached screenshot.

Amazed

  • Newbie
  • *
  • Posts: 8
Re: Want To Create Custom Field When Stamping
« Reply #6 on: August 18, 2016, 01:22:01 AM »
Stupid question. Under my nose, should have read harder. Yup worked out the stamp switch, thanks.

I think this is going to work great.



Amazed

  • Newbie
  • *
  • Posts: 8
Re: Want To Create Custom Field When Stamping
« Reply #7 on: August 18, 2016, 05:42:00 AM »
All going pretty good thanks. Sent you some money and was happy to pay. Really good value and great support.
Thanks.

RTT

  • Administrator
  • *****
  • Posts: 918
Re: Want To Create Custom Field When Stamping
« Reply #8 on: August 18, 2016, 04:38:02 PM »
Great! I'm glad you find it useful, and thank you.