Como concatenar as paginas de um pdf?

Estou usando o pdfview…alguem sabe como eu concateno as paginas?

[code] // draw the first page to an image
PDFPage page = pdffile.getPage(0);

    int npages = pdffile.getNumPages();
    System.out.println("Paginas :"+npages);
    
    //get the width and height for the doc at the default zoom 
    Rectangle rect = new Rectangle(0,0,
            (int)page.getBBox().getWidth(),
            (int)page.getBBox().getHeight());
    
    //generate the image
    Image img = page.getImage(
            rect.width, rect.height, //width & height
            rect, // clip rect
            null, // null for the ImageObserver
            true, // fill background with white
            true  // block until drawing is done
            );[/code]

Só consigo mostrar as paginas separadas…Preciso juntar todas elas em uma unica imagem!! :roll:

Ja fiz isso, se nao me engano era essa classe que peguei da internet

/*
 * $Id: Concatenate.java 2441 2006-10-27 17:24:01Z xlv $
 * $Name$
 *
 * This code is free software. It may only be copied or modified
 * if you include the following copyright notice:
 *
 * This class by Mark Thompson. Copyright (c) 2002 Mark Thompson.
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

/**
 * This class demonstrates copying a PDF file using iText.
 * @author Mark Thompson
 */
package com.lowagie.examples.general.copystamp;

import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

import com.lowagie.text.Document;
import com.lowagie.text.pdf.PRAcroForm;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.SimpleBookmark;

/**
 * Tool that can be used to concatenate existing PDF files.
 */
public class Concatenate {

    /**
     * This class can be used to concatenate existing PDF files.
     * (This was an example known as PdfCopy.java)
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        if (args.length < 2) {
            System.err.println("arguments: file1 [file2 ...] destfile");
        }
        else {
        	System.out.println("PdfCopy example");
            try {
                int pageOffset = 0;
                ArrayList master = new ArrayList();
                int f = 0;
                String outFile = args[args.length-1];
                Document document = null;
                PdfCopy  writer = null;
                while (f < args.length-1) {
                    // we create a reader for a certain document
                    PdfReader reader = new PdfReader(args[f]);
                    reader.consolidateNamedDestinations();
                    // we retrieve the total number of pages
                    int n = reader.getNumberOfPages();
                    List bookmarks = SimpleBookmark.getBookmark(reader);
                    if (bookmarks != null) {
                        if (pageOffset != 0)
                            SimpleBookmark.shiftPageNumbers(bookmarks, pageOffset, null);
                        master.addAll(bookmarks);
                    }
                    pageOffset += n;
                    
                    if (f == 0) {
                        // step 1: creation of a document-object
                        document = new Document(reader.getPageSizeWithRotation(1));
                        // step 2: we create a writer that listens to the document
                        writer = new PdfCopy(document, new FileOutputStream(outFile));
                        // step 3: we open the document
                        document.open();
                    }
                    // step 4: we add content
                    PdfImportedPage page;
                    for (int i = 0; i < n; ) {
                        ++i;
                        page = writer.getImportedPage(reader, i);
                        writer.addPage(page);
                    }
                    PRAcroForm form = reader.getAcroForm();
                    if (form != null)
                        writer.copyAcroForm(reader);
                    f++;
                }
                if (!master.isEmpty())
                    writer.setOutlines(master);
                // step 5: we close the document
                document.close();
            }
            catch(Exception e) {
                e.printStackTrace();
            }
        }
    }
}

Vlw ffranceschi…Onde vc arrumou estas classes com.lowagie.text.pdf.*???

eu usei algo parecido uns 3 anos atrás, e agora eu busquei no www.google.com por “pdf concat java”
se a classe que usei nao foi a mesma, parecida com certeza é!

No meu caso eu tive que montar contrato dinamicos, onde variava a capa do contrato (com nome da empresa), que depois eu concatanava o corpo do contrato que era padrão pra todos os clientes, e na ultima folha com o preço variava tb de acordo com a escolha do plano. Entao usei isso pra juntar tudo

[]´s

procura por itext, a biblioteca de manipulação de pdf’s

Eu entrei no site…
http://www.lowagie.com/iText/download.html
Mas pelo que vejo isto parece ser pago!!
Preciso de algo sem licença de uso…Eu estou usando
https://pdf-renderer.dev.java.net/

Mas o problema que não consigo mostrar o pdf por completo em um JFrame!!

Consegui concatenar…o problema agora é mostrar em um JFrame!!! :roll:

[code]PdfReader reader = new PdfReader("c://manual_APD_operacional.pdf");
// n recebe o numero total de páginas
int n = reader.getNumberOfPages();
// tamanho da primeira página
Rectangle psize = reader.getPageSize(1);
float width = psize.getHeight();
float height = psize.getWidth();

    		    	         // cria segundo pdf
    		    	         Document document = new Document(new Rectangle(width, height));
    		    	         PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(&quot;C://SegundoPDF.pdf&quot;));
    		    	         document.open();
    		    	         // adiciona conteudo ao segundo pdf
    		    	         PdfContentByte cb = writer.getDirectContent();
    		    	         int i = 0;
    		    	         int p = 0;
    		    	         while (i &lt; n) {
    		    	            document.newPage();
    		    	            p++;
    		    	            i++;
    		    	            PdfImportedPage page1 = writer.getImportedPage(reader, i);
    		    	            cb.addTemplate(page1, .5f, 0, 0, .5f, 60, 120);
    		    	            if (i &lt; n) {
    		    	               i++;
    		    	               PdfImportedPage page2 = writer.getImportedPage(reader, i);
    		    	               cb.addTemplate(page2, .5f, 0, 0, .5f, width / 2 + 60, 120);
    		    	            }
    		    	            
    		    	            BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    		    	            //adiciono texto no rodapé 
    		    	            cb.beginText();
    		    	            cb.setFontAndSize(bf, 14);
    		    	            Date d = new Date();
    		    	          
    		    	            
    		    	            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, &quot;Konsultex &quot;+fdata2.format(d),  width / 2, 40, 0);
    		    	            cb.endText();
    		    	         }
    		    	         
    		    	         document.close(); 
[/code] 

Preciso jogar este cb em uma imagem para usar…no meu cod SWING!!

[code]JFrame frame = new JFrame("PDF Test");
jScrollPane1 = new JScrollPane();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon img2 = new ImageIcon(img);

   frame.add(jScrollPane1, BorderLayout.CENTER);
   {
	   label = new JLabel();  
	   jScrollPane1.setViewportView(label);
	   label.setIcon( img2 );
   }
   // frame.add(new JLabel(new ImageIcon(img)));
    frame.pack();
    frame.setVisible(true);
    frame.setSize(img2.getIconWidth(),600); 
    frame.setBounds(50, 50, img2.getIconWidth(),600);  [/code]