These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

check the total sizes of total attachments not allow more than 9 mb when adding attachments to a PDF

cindy_77
Registered: Sep 10 2008
Posts: 16
Answered

My clients requested the form has the validation when I add attachments to a PDF, the total sizes of these atttachments not more than 9 mb. I can just check the size of each attachment but I cannot check the total sizes of the attachment. I am not sure what I am doing wrong the coding is unsucessful. Please help!!!!
Thank you very much.
 
Here is the coding in event:click - attachment button
  
var maxSize=75497472; //bits

try{
var count= 0;
var oDoc = event.target;
var oAttachment = oDoc.dataObjects;
if(oAttachment != null){

count = oAttachment.length;
 
}
  
oDoc.importDataObject("attachment" + (count + 1))
var dataObj = oDoc.getDataObject("attachment" + (count + 1));

var fileName = dataObj.path;
var fileType = fileName.substring(fileName.lastIndexOf("."));
if(fileType != ".pdf" && fileType != ".PDF" && fileType != ".JPG" &&
fileType != ".jpg" && fileType != ".tif" && fileType != ".TIF"&&
fileType != ".tiff" && fileType != ".TIFF" &&
fileType != ".doc" && fileType != ".DOC"){
xfa.host.messageBox("Please correct the file type.");
oDoc.removeDataObject("attachment" + (count + 1));
  
}

 
// combine size
 
//get content
var oFile = oDoc.getDataObjectContents("attachment" + (count + 1), true);

var oBase64Stream = SOAP.streamEncode(oFile, "base64");
var oFile = SOAP.stringFromStream(oBase64Stream);
 
// check the length of the document
var lenTotal = oFile.length;
FileSize.rawValue = lenTotal;

if (lenTotal > maxSize)
{
xfa.host.messageBox("the total size is 9 MB");
oDoc.removeDataObject("attachment" + (count + 1));
}// end if
else
{
xfa.host.messageBox("successfull attachment","Attachment",2);
}
 
}

catch (e)
{

xfa.host.messageBox("Please review the document");
}
       

My Product Information:
LiveCycle Designer, Windows
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Accepted Answer
Hi,

because of the base64 encoding the string length is different to the binary data stream length.
The factor is around 3/4 so when you use

var maxSize = 9437184 / 0.75;...
you are pretty close the the 9 MB you like to use as maximum.

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

cindy_77
Registered: Sep 10 2008
Posts: 16
Hi,
Thank you for your response.

I fixed the maxSize as your suggestion. After that, I tested the form but coding is unsuccessful.

The total attachments is not more than 9 MB. For example, I can add attachmnents as much as I can but total of attachments is not more than 9 MB.

I have added 2 attachments to the PDF. Each attachment has the size is 5888Kb(over 5 MB). I think I can only add one attachment only. But I can add more than 5 attachments(5,100 KB/each attachment).

Is it something wrong in my coding? It is easy for you to see for you to follow.

I try to insert my testing file to the forum but I don't know how to add my file to the forum.Cindy