try this code fragment.It's in Java. convert it into iTextsharp accordingly.

 public static void main(String[] args) throws IOException {

//creating list of readers of pdf files
        try {
            PdfReader reader1 = new PdfReader("A.pdf");
            PdfReader reader2 = new PdfReader("B.pdf");



            List pdfReaderList = new  ArrayList(); //Adding readers to the
files
            pdfReaderList.add(reader1);
            pdfReaderList.add(reader2);


// Creating the PdfCopyFields
// This copy field object will take the reader object and copy the pages to
its object(copy)
// So just by adding a document we can create a PDF with your merged pdf

            PdfCopyFields copy = new PdfCopyFields(new FileOutputStream(
                    "D:/memory/Output.pdf"));

            copy.open();

            if (null != pdfReaderList && !pdfReaderList.isEmpty()) {
                Iterator iter = pdfReaderList.iterator();
                while (iter.hasNext()) {
                    String pageNOs = "";
                    PdfReader pdfReader = (PdfReader) iter.next();
                    int noOfPages = pdfReader.getNumberOfPages();
                    if (noOfPages > 0) {
                        pageNOs = getNumderOfPages(noOfPages);
                    }
                    copy.addDocument(pdfReader, pageNOs);
                }
            }
            copy.close();
        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
// TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
// TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /**
     * Function to get page numbers in string with comma separated
     * @param noOfPages
     * @return
     */
    private static String getNumderOfPages(int noOfPages) {
        String pageNOs = "";
        boolean flag = false;
        for (int i = 0; i < noOfPages; i++) {

            if (flag == true) {
                Integer c = (Integer) i;
                pageNOs = pageNOs.concat("," + c.toString());
            }
            if (flag == false) {
                Integer c = (Integer) i;
                pageNOs = c.toString();
                flag = true;
            }
        }
        return pageNOs;
    }




On Thu, May 13, 2010 at 11:17 PM, Rajani Nandella <[email protected]>wrote:

> I am trying to append a pdf document to another document. I am using
> PdfCopy to do this.
> The result I am getting is that the src file is getting copied over the
> destination file instead of appending to it.
>
> Below is the src code that I am using.
>
>
> public
> int AppendPages(String aSrcFileName, String aDestFileName)
>
> PdfReader
> aReader;
>
> iTextSharp.text.
> Rectangle size;
>
> PdfCopy aCopier;
>
> FileStream aDestFileStream;
>
> Document Doc;
>
> try
>
> {
>
> aReader =
> new PdfReader(aSrcFileName);
>
> size = aReader.GetPageSizeWithRotation(1);
>
> Doc =
> new Document(size);
>
> aDestFileStream =
> new FileStream(aDestFileName, FileMode.Append);
>
> aCopier =
> new PdfCopy(Doc, aDestFileStream);
>
> Doc.Open();
>
> for (int i = 1; i <= aReader.NumberOfPages; i++)
>
> {
>
> Doc.NewPage();
>
> aCopier.AddPage(aCopier.GetImportedPage(aReader, i));
>
> }
>
> Doc.Close();
>
> aReader.Close();
>
> return 1;
>
> }
>
> catch (Exception e)
>
> {
>
> //LogException(e);
>
> return 0;
>
> }
>
> }
> Can anyone please let me know what is missing.
>
> Thanks,
> Rajani
>
>
> ------------------------------------------------------------------------------
>
>
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> Buy the iText book: http://www.itextpdf.com/book/
> Check the site with examples before you ask questions:
> http://www.1t3xt.info/examples/
> You can also search the keywords list:
> http://1t3xt.info/tutorials/keywords/
>
------------------------------------------------------------------------------

_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to