Sonntag, 28. August 2016

append one PDF to another PDF

Based on the library http://itextpdf.com/.
Usecase: Add for instance common terms of condition to an invoice.

REM /**
REM  * pdf_append.bbj
REM  * @author VANDEN
REM  *
REM  */

use java.util.ArrayList
use java.io.FileOutputStream
use com.itextpdf.text.Document
use com.itextpdf.text.DocumentException
use com.itextpdf.text.pdf.PdfCopy
use com.itextpdf.text.pdf.PdfReader

declare Document document!
declare PdfCopy copy!
declare ArrayList files!
declare PdfReader reader!

outputFile$ = "c:/0/pdf3.pdf"
inputFile1$ = "c:/0/pdf1.pdf"
inputFile2$ = "c:/0/pdf2.pdf"

document! = new Document()
copy! = new PdfCopy(document!, new FileOutputStream(outputFile$))
document!.open()
files! = new ArrayList()
files!.add(inputFile1$)
files!.add(inputFile2$)
For i = 0 to files!.size() - 1
    reader! = new PdfReader(Str(files!.get(i)))
    n = reader!.getNumberOfPages()
    For page = 1 to n
        copy!.addPage(copy!.getImportedPage(reader!, page))
    Next page
    copy!.freeReader(reader!)
    reader!.close()
Next i
document!.close()

end

Benefit from the best Windows Desktop app in the world and use Strokey.Net!

Keine Kommentare:

Kommentar veröffentlichen