Hi

Why does this code work bad? Instead, connect the two documents first cut on one side? In addition, if the document to be added to the original is only one page that nothing happens?

Thank you for your reply, best regards, Paul

private void AppendToDocument(string sourcePdfPath1, string sourceAddPdfPagePath, string outputPdfPath)
        {

using (var sourceOrginalDocumentStream = new FileStream(sourcePdfPath1, FileMode.Open))
                {
using (var sourceAddPagePathStream = new FileStream(sourceAddPdfPagePath, FileMode.Open))
                    {
using (var sourceDestinationDocumentStream = new FileStream(outputPdfPath, FileMode.OpenOrCreate))
                        {
var pdfConcat = new PdfConcatenate(sourceDestinationDocumentStream);
var pdfReader = new PdfReader(sourceOrginalDocumentStream);
var pdfReader2 = new PdfReader(sourceAddPagePathStream);
try
                            {
var pages = new List<int>();
for (int i = 0; i < pdfReader.NumberOfPages; i++)
                                {
                                    pages.Add(i);
                                }

                                pdfReader.SelectPages(pages);
                                pdfConcat.AddPages(pdfReader);

//  pdfReader2 = new PdfReader(sourceAddPagePathStream);

                                pages = new List<int>();
for (int i = 0; i < pdfReader2.NumberOfPages; i++)
                                {
                                    pages.Add(i);
MessageBox.Show("Odczytałem strone nr: " + i.ToString());
                                }

                                pdfReader.SelectPages(pages);
                                pdfConcat.AddPages(pdfReader);


                            }
catch (DocumentException docEx)
                            {
//handle pdf document exception if any
MessageBox.Show(docEx.Message, "Ostrzeżenie", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                lblKomunikat.Text = "";
                                lblKomunikat.Text = docEx.Message;
                            }
catch (IOException ioEx)
                            {
//handle IO exception
MessageBox.Show(ioEx.Message, "Ostrzeżenie", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                lblKomunikat.Text = "";
                                lblKomunikat.Text = ioEx.Message;
                            }
catch (Exception ex)
                            {
// handle other exception if occurs
MessageBox.Show(ex.Message, "Ostrzeżenie", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                lblKomunikat.Text = "";
                                lblKomunikat.Text = ex.Message;
                            }
finally
                            {
//close document and writer
                                pdfReader.Close();
                                pdfReader2.Close();
                                pdfConcat.Close();
                            }
                        } //using output
                    }
                }

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to