Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
7

Adding a button to open file explorer and upload multiple files

Community Beginner ,
Jun 12, 2023 Jun 12, 2023

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?

TOPICS
General troubleshooting , JavaScript , PDF , PDF forms
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
5 ACCEPTED SOLUTIONS
Community Expert ,
Jun 12, 2023 Jun 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.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 14, 2023 Jun 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);

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 14, 2023 Jun 14, 2023

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.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 14, 2023 Jun 14, 2023

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

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 14, 2023 Jun 14, 2023
LATEST
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 12, 2023 Jun 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 14, 2023 Jun 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
});
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 14, 2023 Jun 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);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 14, 2023 Jun 14, 2023

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 14, 2023 Jun 14, 2023

like just the little icons, where once clicked, the attachment opens up? Similar to how you can attach files in word

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 14, 2023 Jun 14, 2023

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 14, 2023 Jun 14, 2023

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 14, 2023 Jun 14, 2023

thank you so much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 14, 2023 Jun 14, 2023

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 14, 2023 Jun 14, 2023
LATEST

No.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines