When two pages having barcodes are merged into a single PDF document, the resultant PDF document does not display the barcode if we use any third party tools.
Using Acrobat JavaScript, I am able to merge the documents with barcode.
The following is the code, I am using to merge the files:
function MergeMultipleFiles()
{
var doc = app.newDoc();
vFiles = new Array("/C/TestPDF/First.pdf","/C/TestPDF/Second.pdf","/C/TestPDF/Third.pdf");
for ( var i=0; i < vFiles.length; i++)
{
doc.insertPages ({nPage: doc.numPages-2,cPath: vFiles[i],nStart: 0});
}
doc.saveAs({cPath: "/C/TestPDF/MergedJS.pdf"});
doc.closeDoc(true);
}
app.trustedFunction(MergeMultipleFiles);
Could you please provide the answers to the below questions?
1. When I tried to merge the PDF files from the above code, it is creating a blank page at the beginning of the document. How can this be avoided?
2. The code I am using is correct or will it cause any other issues?
3. How can I call Acrobat Javascript from C# code, since I need to merge the pdf files from my aspx page?
4. I want to write the above function as a generic function, i.e. I want to pass two parameters (NewFile and the files which I want to merge) to the above function. How can I do that?
First, the "app.newDoc()" function creates a pdf with a single blank page. You can insert the document so that the blank page is last, but if you want to get rid of it, it has to be deleted with the "doc.deletePages()" function, also a privileged function.
2)
The function code you've provided is correct. However, it will only work from a folder level script. "app.trustedFunction()" can only be executed from a privileged context. You've also set it up incorrectly. app.trustedFunction() returns a function. Instead, asign it to a variable:
var myMergFn = app.trustedFunction(MergeMultipleFiles);
Then it can be used by JavaScript in any context. But it has to be defined in a folder level script.
3)
You can't call Acrobat from C# in an ASP.NET script because the C# executes on the server. Using Acrobat on a server is strictly forbidden by the Acrobat License Agreement.
4)
function MergeMultipleFiles(cNewFile,aMergeFiles)
{
...
}
This is core JavaScript.
Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script