Thread View: es.comp.lenguajes.java
1 messages
1 total messages
Started by Kurro
Thu, 29 May 2008 10:06
Concatenar ficheros con iText
Author: Kurro
Date: Thu, 29 May 2008 10:06
Date: Thu, 29 May 2008 10:06
45 lines
2815 bytes
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();
}
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads