Hello Folks,
I am wondering whether we can restrict some documents attaching to a PDF or not. For example, i can add only Microsoft Word documents to PDF and ignore reset of all other documents. Please let me know how should i generate this type of functionality.
Thanks in Advance
Rajesh
Solved! Go to Solution.
Views
Replies
Total Likes
Hi Rajesh,
If you are using a button for the user to add an attachment then you can use some JavaScript code like this in the click event;
var attachmentName = "SupportDocument"
var validTypes = 'doc,docx,xls,xlsx'
var pdf = event.target;
if (pdf.importDataObject(attachmentName))
{
var attachment = pdf.getDataObject(attachmentName);
var filetype = attachment.path.replace(/(.*)\.([a-zA-Z]+)$/, '$2')
if (validTypes.split(',').indexOf(filetype) === -1)
{
pdf.removeDataObject(attachmentName);
app.alert('invalid file type');
}
}
You will still have to check when they submit that they haven't added an attachment via the builtin Adobe attachment pane. Something like;
var pdf = event.target;
if (pdf.dataObjects !== null)
{
for (var i = 0; i < pdf.dataObjects.length; i++)
{
if (pdf.dataObjects[i].name === pdf.dataObjects[i].path)
{
app.alert("you have an invalid attachment");
break;
}
}
}
This relies on the name property being set to the path if using the attachment pane or the arguement to the importDataObject function if using code. You may want to keep you own record of the attachments added via script as this behaviour could be changed by Adobe in a future release.
I don't want to make it sound like I know what Adobe might do, just that the name property used to be set to Untitled when using the attachment pane.
Regards
Bruce
Views
Replies
Total Likes
Hi Rajesh,
If you are using a button for the user to add an attachment then you can use some JavaScript code like this in the click event;
var attachmentName = "SupportDocument"
var validTypes = 'doc,docx,xls,xlsx'
var pdf = event.target;
if (pdf.importDataObject(attachmentName))
{
var attachment = pdf.getDataObject(attachmentName);
var filetype = attachment.path.replace(/(.*)\.([a-zA-Z]+)$/, '$2')
if (validTypes.split(',').indexOf(filetype) === -1)
{
pdf.removeDataObject(attachmentName);
app.alert('invalid file type');
}
}
You will still have to check when they submit that they haven't added an attachment via the builtin Adobe attachment pane. Something like;
var pdf = event.target;
if (pdf.dataObjects !== null)
{
for (var i = 0; i < pdf.dataObjects.length; i++)
{
if (pdf.dataObjects[i].name === pdf.dataObjects[i].path)
{
app.alert("you have an invalid attachment");
break;
}
}
}
This relies on the name property being set to the path if using the attachment pane or the arguement to the importDataObject function if using code. You may want to keep you own record of the attachments added via script as this behaviour could be changed by Adobe in a future release.
I don't want to make it sound like I know what Adobe might do, just that the name property used to be set to Untitled when using the attachment pane.
Regards
Bruce
Views
Replies
Total Likes
Thank you, very much. it is very helpful.
I have created a sample which works file
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies