Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merge multiple PDF files into one PDF uisng Javascript - Help needs

Status
Not open for further replies.

nkshah

Programmer
Dec 16, 2009
25
0
0
US
Hi friends,

Below is my detail explanation.

Every Morning, we are getting multiple PDF files and our Executive needs to see in one PDF files.

Right, now I am diong manually PDF Merge process using Acrobate Profetional. But Now, my client asking to convert this into automated process every morning.

My question is , How can we Merge PDF processing using programming language .NET / Java Script and automate this every morning ?.

(My client is not allowing to use any third paty tool for this process.)

Can someone provide me a suggestions for this ?

I am not a great programmer.

So, if anyone provide me Coding Template / good URL, I will appreciate this.

Let me know if you need more information.
 
[0] >(My client is not allowing to use any third paty tool for this process.)[/i]

[0.1] Just to mention in passing, if you can use some kind of utility, it would be doable (with zero cost) with "pdf toolkit" (pdftk.exe), google search is easy to find. Then you can run a bat file or if you insists a wsh jscript, like this.
[tt]
//your givens here[green]
//path to pdftk.exe
var spdftk_path="c:\\progra~1\\pdftk-1.41\\";
//source pdf's, assumed in a common path and file name without spaces
var commonpath="c:\\xyz\\";
var srcfiles=Array("pdf_0.pdf","pdf_1.pdf","pdf_2.pdf");
var outfile="pdf_out.pdf";[/green]

var scmd=spdftk_path + "pdftk.exe" + " " + srcfiles.join(" ") + " cat output " + outfile + " dont_ask";

var wshshell=new ActiveXObject("WScript.Shell");
wshshell.CurrentDirectory=commonpath;
wshshell.Run(scmd);
wshshell=null;
[/tt]
[1] Now, assuming you have the adobe authoring package, you can also do it with the AcroExch.PDDoc which happens to be an automation interface and that is crucial.

[1.1] The main reference is here.

[1.2] In wsh jscript, you can do script the automation with the overall layout like this.
[tt]
//your givens here[green]
//at least one source file
var srcfiles=Array("pdf_0.pdf","pdf_1.pdf","pdf_2.pdf");
var commonpath="c:\\path\\";
var outfile="pdf_out.pdf";[/green]

var bret=true;
var npage=-1;
var npage2=-1;

var oproc=new ActiveXObject("AcroExch.PDDoc");
var oproc2=new ActiveXObject("AcroExch.PDDoc");

for (var i=0; i<srcfiles.length; i++) {
if (i==0) {
bret=oproc.Open(commonpath + srcfiles);
} else {
bret=oproc2.Open(commonpath + srcfiles);
}

if (!bret) {
WScript.echo ("Failed to load: " + srcfiles + "\nOperation aborted");
oproc.Close();
if (i>0) {
oproc2.Close();
}
break;
}
if (i>0) {
npage=oproc.GetNumPages();
npage2=oproc.GetNumPages();
bret=oproc.InsertPages(npage-1, oproc2, 0, npage2, true); //bookmarks copied: true
if (!bret) {
WScript.echo ("Failed to insert with file: " + srcfiles + "\nOperation aborted");
if (i>0) {
oproc2.Close();
}
break;
}
oproc2.Close();
}
}
if (bret) {
oproc.Save(0x05,commonpath + outfile); //PDSaveFull=0x05
}
oproc.Close();

oproc2=null;
oproc=null;
//WScript.echo ("done");
//WScript.quit();
[/tt]
ps: brain code; typos and details, you have to take care if any yourself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top