Copy link to clipboard
Copied
I'm looking for ways to create a button which allows the user to upload x amount of files to a specific area of a page in the PDF. any ideas?
Copy link to clipboard
Copied
You can use the addAnnot method in a loop, creating a separate "FileAttachment" comment each time.
The cAttachmentPath property can be used to prompt the user to select the file.
Copy link to clipboard
Copied
Give this a go:
var attachmentCounter = 0;
do {
attachmentCounter++;
var fileAttachment = this.addAnnot({
page: 0, // Specify the page number where you want to add the annotation
type: "FileAttachment",
rect: [100, 100, 200, 200], // Set the position and size of the annotation on the page
contents: "Attached file " + attachmentCounter // Set the annotation's contents
});
fileAttachment.cAttachmentPath
} while (app.alert("Add another file?",2,2)==4);
Copy link to clipboard
Copied
It does both, but the current code will add the icons one on top of another (because the rect property is the same). You can find them at the bottom left corner (more or less) of page 1 of the file. You should also see them in the Comments List panel.
Copy link to clipboard
Copied
To make the icons not overlap with each other, replace the rect property in the code above (which doesn't seem to work anyway), with this:
point: [100+(attachmentCounter*10), 100], // Set the position of the annotation on the page
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You can use the addAnnot method in a loop, creating a separate "FileAttachment" comment each time.
The cAttachmentPath property can be used to prompt the user to select the file.
Copy link to clipboard
Copied
Can you elaborate please? I created a button with a Java Script option with the below but nothing happens when I click the button.
// Get the current document
var doc = this;
// Prompt the user to select the files
var filePaths = app.browseForDoc();
// Loop through the selected files
for (var i = 0; i < filePaths.length; i++) {
// Create a new file attachment annotation
var fileAttachment = doc.addAnnot({
page: 0, // Specify the page number where you want to add the annotation
type: "FileAttachment",
cAttachmentPath: filePaths[i], // Set the attachment path to the selected file
rect: [100, 100, 200, 200], // Set the position and size of the annotation on the page
contents: "Attached file " + (i + 1) // Set the annotation's contents
});
}
Copy link to clipboard
Copied
Give this a go:
var attachmentCounter = 0;
do {
attachmentCounter++;
var fileAttachment = this.addAnnot({
page: 0, // Specify the page number where you want to add the annotation
type: "FileAttachment",
rect: [100, 100, 200, 200], // Set the position and size of the annotation on the page
contents: "Attached file " + attachmentCounter // Set the annotation's contents
});
fileAttachment.cAttachmentPath
} while (app.alert("Add another file?",2,2)==4);
Copy link to clipboard
Copied
the button now opens up the file explorer, thank you!
is there a way to have the files inserted in the same section as the button as opposed to just on the "attachments" tab?
Copy link to clipboard
Copied
like just the little icons, where once clicked, the attachment opens up? Similar to how you can attach files in word
Copy link to clipboard
Copied
It does both, but the current code will add the icons one on top of another (because the rect property is the same). You can find them at the bottom left corner (more or less) of page 1 of the file. You should also see them in the Comments List panel.
Copy link to clipboard
Copied
To make the icons not overlap with each other, replace the rect property in the code above (which doesn't seem to work anyway), with this:
point: [100+(attachmentCounter*10), 100], // Set the position of the annotation on the page
Copy link to clipboard
Copied
thank you so much!
Copy link to clipboard
Copied
is there a way to get the the file name under the file attachment icon?
Copy link to clipboard
Copied
No.

