🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.lenguajes.java
Article #278

Concatenar ficheros con iText

#278
From: Kurro
Date: Thu, 29 May 2008 10:06
45 lines
2815 bytes
Hola a todos.
Estoy haciendo una clase de Java para unir documentos PDF usando la
clase iText, el problema está en que debo de leer el contenido de los
PDF y colocarlo uno a continuación de otro, en lugar de una página
detras de otra.

Ahora estoy haciendo lo siguiente:

(nota: la variable files[] es una clase que hemos creado para agrupar
los documentos, el método getContent() devuelve el binario de un pdf)

Document newDocument = null;
OutputStream outputStream = null;
byte[] pdfContents = null;
 try
 {
	rutaTemporal = "c:/temp/";
	nombreTemporal = System.currentTimeMillis() + ".pdf";
	ficheroSalida = rutaTemporal + nombreTemporal;
	outputStream = new FileOutputStream(ficheroSalida);

        newDocument = new Document();
        PdfWriter pdfWriter = PdfWriter.getInstance(newDocument,
outputStream);
        pdfWriter.open();
        PdfContentByte pdfContentByte = pdfWriter.getDirectContent();

        newDocument.open();
  	for(int iFor=1;iFor < totalFicheros; iFor++)
         {
    		pdfContents = ficheros[iFor].getContent();
    		try {
                    PdfReader pdfReader = new PdfReader(pdfContents);
                    for (int pagina=1; pagina <=
pdfReader.getNumberOfPages(); pagina++){
                    newDocument.newPage();
                    PdfImportedPage importedPage =
pdfWriter.getImportedPage(new PdfReader(pdfContents), pagina);
                    pdfContentByte.addTemplate(importedPage, 0, 0);
                    }

    	          } catch (IOException e) {
    				e.printStackTrace();
    	}
}
Technical Details
Message-ID: <efbb6594-337c-4ba7-b0c2-2c0f8d9cd09e@k13g2000hse.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!postnews.google.com!k13g2000hse.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 1116f3,68d74d71ff573d0c,start
X-Google-Attributes: gid1116f3,domainid0,public,usenet
X-Google-Language: SPANISH,ASCII
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!postnews.google.com!k13g2000hse.googlegroups.com!not-for-mail
From: Kurro <kurro.lopez@gmail.com>
Newsgroups: es.comp.lenguajes.java
Subject: Concatenar ficheros con iText
Date: Thu, 29 May 2008 03:06:46 -0700 (PDT)
Organization: http://groups.google.com
Lines: 45
Message-ID: <efbb6594-337c-4ba7-b0c2-2c0f8d9cd09e@k13g2000hse.googlegroups.com>
NNTP-Posting-Host: 80.59.121.110
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1212055607 23937 127.0.0.1 (29 May 2008 10:06:47 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 29 May 2008 10:06:47 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: k13g2000hse.googlegroups.com; posting-host=80.59.121.110; 
 posting-account=Rx1SigoAAABsB6Ik706nXE7H-5GpbLqg
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.1.14) 
 Gecko/20080404 Firefox/2.0.0.14,gzip(gfe),gzip(gfe)