On Tue, Jun 24, 2008 at 09:06:05PM +0900, Vladimir wrote:
> Good day.

Hi,
sorry, for late answer, but some work has come in the midle of this
email and I wasn't able to finish it sooner then now.

> 
> I want to merge several pdf files into one. I can use pdfedit with gui but
> when pdf files is about 100 it is rather annoying. I think there must be a way
> to process all files in command line. pdfedit has script support but I 
> cound't find
> any example of it use for my case.

Similar think was discussed for mass delinearization in the
http://sourceforge.net/mailarchive/message.php?msg_id=BAY106-W5219A792D82C6E60E3BD3E9CE60%40phx.gbl
thread.

> I want something like this
> $ pdfmerge -oOUTPUTFILE PDF_FILES_IN_ORDER
> where pdfmerge may be a shell script calling pdfedit with its script commands.
> Could someone point me on appropriate documentation and especially example?

Attached, you can find script which defines two functions (
__mass_merge - for low-level usage - meaning that direct usage of pdf
        instances
mass_merge - for high-level usage - meaining that filenames are used for
        output and input docuemnts)

In theory, it can be used for your purpose, but I had hard times how to
use it without gui :(
When you place it into the ~/.pdfedit/scripts directory, you can use it
from gui - justcall 
        mass_merge("output_file", ["input1" "input2" ... ["inputN"]])
where output_file is existing pdf document which will contain all pages
(including those it contains originaly) from all input documents (note
that they are defined as array, so they have to be enclosed in `[' `]'
and elements are separated by space).

Note that the script is just example without proper error handling and
all paths should be absolute (otherwise you would need to play with the
script a bit).

pdfedit has -console and -run parameters which should work also without
GUI, but there some issues we have to deal with before this script can
be useable from them. 

I hope that at least this will help a bit.

Just a hint for more automatic handling:
You can also generate input array from directory regexp, but it needs
some more tweaking:
(quick kick off)

Dir d = new Dir(PATH);
var l = d.entryList('*.pdf');   // l contains array compatible list of all
                                // pdf documents in the PATH (but it
                                // contains only names and doesn't
                                // contain path - so you need to expand
                                // each element with PATH
nass_merge("output.pdf", l);    

So put all your documents to the PATH and this should work for you.

> 
> P.S. Sorry, if my English is poor.
> ---
> WBW, Vladimir Lomov

Best regards
-- 
Michal Hocko
/** Merges all pdfs to the given one.
 * @param outPdf Existing pdf instance where to merge.
 * @param pdfs Array of pdf instances which to merge.
 *
 * outPdf will contain all pages from pdfs (in the order they are
 * listed in the input array) inserted at the end.
 */
function __mass_merge(outPdf, pdfs)
{
        var insertPos=outPdf.getPageCount() + 1;
        var i;
        for(i=0; i<pdfs.length; ++i)    
        {
                var pdf=pdfs[i];
                var p;
                for(p=1; p<=pdf.getPageCount(); ++p, ++insertPos)
                {
                        var page = pdf.getPage(p);
                        outPdf.insertPage(page, insertPos);
                }
        }
}

/** Merges all inputFiles to the given outputFile.
 * @param outputFile Name of the existing output pdf document.
 * @Param inputFiles Array of all pdf documetns which to merge.
 *
 * Note that you have to use absolute path for all pdf documents.
 */
function mass_merge(outputFile, inputFiles)
{
        print("loading output file:"+outputFile)
        var outPdf=loadPdf(outputFile);
        var pdfs=[];

        for(i=0; i<inputFiles.length; ++i)
        {
                print("loading input file["+i+"]"+inputFiles[i]);
                pdfs[i]=loadPdf(inputFiles[i]);
        }
        
        __mass_merge(outPdf, pdfs);

        for(i=0; i<pdfs.length; ++i)
                pdfs[i].unloadPdf();
        
        outPdf.save();
        outPdf.unloadPdf();
}
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Pdfedit-support mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdfedit-support

Reply via email to