Link to home
Start Free TrialLog in
Avatar of mld4165
mld4165Flag for United States of America

asked on

I am trying to use vbScript to insert date and image file into a pdf document

Hi All,

I am trying to use vbScript to insert date and image file into a pdf document. The image file is a custom graphic (jpg format) that is an approval of the document from the boss.

I have installed the Acrobat 5 SDK and have been playing around with some of the scripts that merge documents but have not been able to figure out how to send the date and image. Need more documentation?

I would be grateful for any help and upgrading to VB6 is OK if needed.

Matthew

here is a sample javascript that does what I want but I do not know how to send it to adobe. i believe that it uses FDFTOOLKIT?

var lastPage = this.numPages - 1;
var todaysDateStr = util.printd("mmmm d, yyyy", new Date());
try {
      var dateFieldExists = false;
      var fDateSigned1 = this.getField("dateText");
      if (fDateSigned1.name == "dateText")
        { dateFieldExists = true; };
    } catch(e) {
      console.println("\n field dateText does not exist, field will be added");
};

if (dateFieldExists)
  { var fDateSigned = this.getField("dateText"); }
else
  { var fDateSigned = this.addField("dateText", "text", lastPage, [30,30,115,48]); };


fDateSigned.defaultValue = todaysDateStr;
fDateSigned.fillColor = color.white;
fDateSigned.textColor = color.red;
fDateSigned.textSize = 0;
fDateSigned.alignment = "left";
this.resetForm(fDateSigned);

try {
      var signatureButtonExists = false;
      var fSignatureButton1 = this.getField("signatureButton");
      if (fSignatureButton1.name == "signatureButton")
        { signatureButtonExists = true; };
    } catch(e) {
        console.println("\n Button signatureButton does not exist, button will be added");
};

try {
      if (signatureButtonExists)
        { var fSignatureButton = this.getField("signatureButton"); }
      else
        { var fSignatureButton = this.addField("signatureButton", "button", lastPage, [240, 30, 528, 140]); };

      fSignatureButton.buttonPosition = position.iconOnly;
      var returnCode = fSignatureButton.buttonImportIcon("/c/Aesop/coffman/Signature/jbc-eastern.pdf", 0);
      fSignatureButton.buttonScaleWhen = scaleWhen.always;
      fSignatureButton.buttonScaleHow = scaleHow.proportional;
    } catch(e) {
      app.alert(e);
      console.println("\n Exception while trying to access signatureButton: " + returnCode);
};

this.resetForm(fSignatureButton);
Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

Are you familiar with the document "Programming Acrobat JavaScript Using Visual Basic"? This is part of the SDK and describes how you can interface VB with JavaScript. I'm not programming in VB, so I cannot give you a more detailed answer at this time (I will look through the document however, to see if there is anything that would help in your particular situation).
... one more thing: You don't need (or want) the FDFToolkit - this is only useful if you are working with a web server, creating FDF files on the fly and parsing the results returned by Acrobat. You are creating forms with Acrobat, the FDFToolkit works independant of Acrobat.
Avatar of mld4165

ASKER

khkremer

thanks for looking into this for me. I really don't care if it is in javascript either. I just want the user who approves the form to be able to either click on icon on the quick launch bar of windows, or some hot key combo that inserts the date and graphic which approves the document.

thanks

Matt
Do you know that you need the full version of Acrobat (either Acrobat 5 or 6) to do this? How is the user approving the document? Because it's a PDF file, it probably needs to be displayed in Acrobat in the first place, so why not just use JavaScript without any VB interaction? Acrobat JavaScript allows you to add menu items and toolbar buttons in Acrobat.
Avatar of mld4165

ASKER

khkremer,

To answer your questions.

I do have the full version of Adobe Writer.

Yes the file is open and displayed in Acrobat.

Currently we are not using this method to approve the document. This is a new process and I hope it can be done by inserting a graphic.

I would like to save a file as a pdf to be inserted into the document as approved.

I have never used Acrobat version or regular javascript. I have done some vbscripts but I am still learning.

"Acrobat JavaScript allows you to add menu items and toolbar buttons in Acrobat."

Can you help me with this?

thanks,
Matt
Sorry for the delay, but I'm pretty busy with work right now. I have one question: The signature you want to add, is this a "digital signature" or just an image containing the signature?

There is no product called "Acrobat Writer", so I assume you mean "Adobe Acrobat", and because you did not add 'Standard' or 'Professional', I assume it's Adobe Acrobat 5. Is this correct?
ASKER CERTIFIED SOLUTION
Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mld4165

ASKER

Adobe Writer? oops it is Adobe Acrobat version 5.0.5

The signature file is an image file.

Thanks for the help so far! I was reading through that document and was trying to put the app.addMenuitem to use.

Going from a quote that you made earlier that you can add toolbar buttons:
"Acrobat JavaScript allows you to add menu items and toolbar buttons in Acrobat."

I was thinking that toolbar buttons was the route to go as we have two images containing signatures depending on which district the pdf file was going. If I could place a toolbar button with a W and E on them it woiuld almost be perfect. Is that possible? I don't see a command like app.addMenuitem for the toolbar?

Another question is that currently we use WordPerfect for these documents and it allows for the use of a script to insert the signature, and can be assigned a keyboard combination to call it in WordPerfect. Any chance that would be possible in Adobe Acrobat? It would be nice to assign "alt-e" and "alt-w" to get Adobe to run the script.

Can you recommend any resources for learning Adobe Javascript or a good book on Javascript that can relate to Adobe? Scripting seems to me to becoming more and more important as time goes by.

thanks,
Matt


I have to check my documentation to see if the toolbar button was supported in Acrobat 5. I know that it can be done in Acrobat 6.

JavaScript does not support keyboard accelerators (Ctrl or Alt combinations), but you can create menu items that use shortcuts (you could for example open the File menu with Alt-F and then type one key (one that's not used for any other shortcut in this menu) by prefixing this characters with '&' when you create the menu item. Change for example the line

       cUser: "Add Signature",

to
       cUser: "Add Signa&ture",

This will select the "T" as the shortcut key.

You can have accelerator keys when you write and install a plug-in for Acrobat (this is no trivial task).

As far as I know, there is only one book specifically about Acrobat JavaScript: http://www.amazon.com/exec/obidos/tg/detail/-/0321172388/102-6695405-6994507?v=glance

JavaScript is alwasy two parts: The core language, which is the same for web browsers, Acrobat or any other implementation that uses JavaScript and the application specific extensions. And these are of course different between different applications. You need an introduction into the core language, and there are a number of books that do a pretty good job at that. I dont' have any specific recommendations, just go to your local book store and browse through the JavaScript books until you find one that looks good. Read a few pages in order to find out if you like the style. For the Acrobat specific extensions, you need something like the Deubert book.
Avatar of mld4165

ASKER

khkremer,

You are awesome!!

I am going to give the points out soon I promise!  Can I award some points now and the rest later?

I have a few more questions and comments.

The app.addMenuItem makes a sub-menu item, and I was wondering if a main item menu could be made. In other words instead of having to do an alt + f to get into the file menu and another key be sent to the sub-menu that a new menu be created that only adds my signature?

Let me know about the toolbars and thanks for the book references.

matt
No, you have to award all the points at the same time.

The menubar is not accessible from a JavaScript program, you can only add menus to the already existing menus. You do however have access to the menu bar from a plug-in (again, this is a non-trivial task).

I finally had a chance to check the Acrobat 5 JS Reference, and the toolbar buttons are definitely not supported by Acrobat 5. You need Acrobat 6 for that.
Avatar of mld4165

ASKER

Thanks!!