Skip to main content
Participating Frequently
June 12, 2023
Answered

Adding a button to open file explorer and upload multiple files

  • June 12, 2023
  • 1 reply
  • 2062 views

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?

This topic has been closed for replies.
Correct answer try67

is there a way to get the the file name under the file attachment icon?


No.

1 reply

try67
Community Expert
Community Expert
June 12, 2023

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.

Participating Frequently
June 14, 2023

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
});
}

try67
Community Expert
Community Expert
June 14, 2023

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);