Copy link to clipboard
Copied
I have created a trusted function (code below), when I call this function the button gets created on the page however this button is just a blank box, how do I get an image to show in the created button. I am running this in Adobe Reader XI, which I believe should allow this functionality, if not can anyone explain how I am able to add an image to a pdf using javascript.
app.addToolButton({cName:"TestButton", cExec:"CreateMyButton('NextButton', this.pageNum)", cLabel:"Test Button", cTooltext:"Test_Button"});
var CreateMyButton = app.trustedFunction(function(cName, nPage)
{
app.beginPriv();
// Acquire the crop box (visible area) for the current page
var pgRect = this.getPageBox("Crop", nPage);
// Build Button Rectangle in lower left corner of page
var fldRect = []; fldRect [0] = pgRect[0] + 36;
// 1/2 inch from left side
fldRect [1] = pgRect[0] + 56;
// 20 points high
fldRect [2] = pgRect[0] + 172;
// 1/2 inch wide
fldRect [3] = pgRect[0] + 136;
// 1/2 inch from bottom
// Create Button on page
var oFld = this.addField( cName , "button", nPage, fldRect);
// Setup Button's Properties
if(oFld != null) {
//oFld.buttonSetCaption("Next");
oFld.buttonPosition = position.iconOnly;
oFld.buttonImportIcon("/fileserver/folder/folder2/iconimage.pdf");
oFld.borderStyle = border.b;
// Beveled edges
oFld.strokeColor = color.blue;
// Border Color
oFld.textColor = color.black; oFld.lineWidth = 1;
// Thin Border
oFld.setAction("MouseUp", "this.pageNum++");
// Navigation
}
return oFld;
app.endPriv();
});
Copy link to clipboard
Copied
It works fine for me... Are you sure that the file-path of the image file is correct? To verify it I recommend you open that file (in Acrobat) and then run this code from the JS Console:
this.path
It will print out the file's path in the syntax that you should use in your code.
Copy link to clipboard
Copied
I opened the file i.e. iconimage.pdf in acrobat reader xi and launched the console and ran this.path; the resulting string is exactly the string I am using in oFld.buttonImportIcon(" ... ");
as an aside, I did move the icon image pdf into my c drive and tested the path to the new file and the code worked, so seems there is an issue with a network shared drive, even though I use the same path as this.path shows.
In addition to the original query is there a way for the user to move the button around the pdf after it is placed like you can with other fields or does it have to remain in the static position the script placed it?
Copy link to clipboard
Copied
Yes, the network location is probably the issue. You can try mounting that network folder as a drive and then it might work...
Users in Reader can't move fields around. Not through the standard GUI, anyway. This field is no exception.
Copy link to clipboard
Copied
would it be possible to create a mouseevent on click, then move the button to the location of the next click co-ords?
essentially I want it to act like a stamp but can't set the image as a stamp in this instance as the required image would change depending on the situation
Copy link to clipboard
Copied
What's stopping you from adding such a button with an icon to your stamp?
Copy link to clipboard
Copied
I have a folder of images, the images in this folder could also change over time. If I were to create custom stamps of these images I would need to know the AP value that Acrobat gives each stamp, then I would need to be able to recall each AP depending on which one I wanted to place on the pdf. At least by using the button icon I am able to specify a file on the fly which can be built with variables, which I wouldn't be able to do with the stamps.
This button solution is a workaround for a situation, but not my ideal solution. I know my users will want to place this image where they want and not where I specify in my script, hence the reason I ask if there is a way to be able to move the button.
Copy link to clipboard
Copied
Moving the field in Reader is a big challenge, and you can specify dynamic
images in your stamps. You add a button field to the stamp and then use a
script to populate it with the desired image file, just like with a normal
field.
On Wed, Nov 9, 2016 at 2:14 PM, owaind29065507 <forums_noreply@adobe.com>
Copy link to clipboard
Copied
This is a great idea not thought of that. Will I need a non-reader version of Acrobat to create the initial stamp with the button? Also if I have a blank stamp with a blank button on, how would I specify the Image Icon, for example I use the below to add an existing stamp to a document, if this stamp was my one with the blank button on it, how would it know what image to load as the icon?
this.addAnnot({page:this.pageNum, type:"Stamp", AP:"#GK7P2pHTrnc98RrOh_fmZC", rect:[433, 40, 581, 119], name:"Test_Stamp"});
Just to let you know I did try using the drive annotation of a mounted newtork drive but it was still unable to load the image, so guess I either need to store the files locally or write some other script to get the file needed and move it into a local folder.
Copy link to clipboard
Copied
- Yes, you would need Acrobat to crate the stamp with the fields in it.
- I don't know how it would know which image to use, since I don't know the
logic behind what you're trying to achieve...
On Wed, Nov 9, 2016 at 5:22 PM, owaind29065507 <forums_noreply@adobe.com>
Copy link to clipboard
Copied
What I meant was how do I specify the image name when calling the stamp. At the moment if I have two images (image1.pdf, image2.pdf) I can set them to a variable then when I call oFld.buttonImportIcon I can specify the image name variable so it knows what file to load. If I now put the button in the stamp, how do I pass the image name to that stamp, so it shows the correct image i need.
Copy link to clipboard
Copied
You can use a global variable, for example.
Copy link to clipboard
Copied
ok I have this working in a normal form within a pdf. How do I convert that to be a dynamic stamp? If I try and add it using the Create custom stamp the fields seem to get flattened and it is just a plain pdf
Copy link to clipboard
Copied
Once a stamp gets added to the page, it's no longer interactive. You'd need to introduce logic into the dynamic code of the stamp to add the image. Why not just two stamps?
Copy link to clipboard
Copied
Ignore my last comment, after creating the stamp I then add the form fields
Copy link to clipboard
Copied
I presume when using a button in a stamp we lost all background transparency?
Copy link to clipboard
Copied
Not necessarily. The artwork of the stamp needs to be transparent and you need to have the button set to have a transparent background for it to work though.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now