Author Topic: Custom Field for Attachments  (Read 5095 times)

0 Members and 1 Guest are viewing this topic.

Padanges

  • Newbie
  • *
  • Posts: 179
Custom Field for Attachments
« on: August 10, 2016, 12:21:33 PM »
Hi,
is it possible to create such a Custom Field that it would be able to show in a Grid Layout boolean value for existing Attachments in pdfs, just like for the "Security" property? If so, could you suggest how to accomplish this?

Thanks in advance.

RTT

  • Administrator
  • *****
  • Posts: 907
Re: Custom Field for Attachments
« Reply #1 on: August 10, 2016, 05:20:46 PM »
Check my reply at this forum post on how to accomplish this, although for a different property, with the Edit Info Fields batch tool and a script function. The second method, where it is explained how to put the needed info in a custom field and show it in the grid.
In this case you can use a ready available HasAttachments script function, so you just need to customize a custom field to hold the value and run the Edit Info Fields batch tool, writing [HasAttachments] at that respective custom field.

If instead of just the indication of the existence or not of attachments the actual count is preferable you can use a script function like this:
Code: [Select]
function AttachmentsCount() {
    return CountAttachments(BatchFile.AttachmentRoot.Children);
}

function CountAttachments(Attachments) {
    var n = 0;
    if (Attachments) {
        for (var i = 0; i < Attachments.count; i++) {
            var attachment = Attachments(i);
            if (attachment.AttType == 1 /*attFile*/ ) {
                n++;
            } else {
                n = n + CountAttachments(attachment.Children);
            }
        }
    }
    return n;
}

Padanges

  • Newbie
  • *
  • Posts: 179
Re: Custom Field for Attachments
« Reply #2 on: August 11, 2016, 08:45:38 AM »
Unfortunatelly the Scripts Editor gives Error: 'BatchFile.AttachmentRoot.Children' is null or not an object. Running the code for the script does not change column values.
The NameLength() example works fine though. Could you, please, give at least a hint as why is it so?

Padanges

  • Newbie
  • *
  • Posts: 179
Re: Custom Field for Attachments
« Reply #3 on: August 11, 2016, 10:57:05 AM »
After updating to the latest version - everything works as expected. Thank you!

Padanges

  • Newbie
  • *
  • Posts: 179
Re: Custom Field for Attachments
« Reply #4 on: August 11, 2016, 11:21:53 AM »
While testing the script I found a pdf file with attachments which was not processed properly by the script, attachments count is listed as 0.
The sample pdf with an attachment is from here: http://www.colorpilot.com/pdfsamples/PDFWithFileAttachmentAnnotation.pdf
Is there any way to distinguish files which have "proper" attachments?

RTT

  • Administrator
  • *****
  • Posts: 907
Re: Custom Field for Attachments
« Reply #5 on: August 11, 2016, 05:32:08 PM »
While testing the script I found a pdf file with attachments which was not processed properly by the script, attachments count is listed as 0.
The sample pdf with an attachment is from here: http://www.colorpilot.com/pdfsamples/PDFWithFileAttachmentAnnotation.pdf
Is there any way to distinguish files which have "proper" attachments?
This particular way to include file attachment is realized by the use of page annotations, and these are not included in the PDF file attachments tree object. The only way to find these is by parsing all the page annotations, and do it for each page. The attachments tool will list these files from the "embedded" tab. This is a slow task for very big documents, not practical to do it from the scripts API, at least without clearly requiring to do so. I suppose I need to add a way to list these embedded files using the scripts API too. :-\

Padanges

  • Newbie
  • *
  • Posts: 179
Re: Custom Field for Attachments
« Reply #6 on: August 12, 2016, 01:45:56 PM »
Yup, it would be great to have an additional option for "deep attachment scanning".