Solved!

I used another algorythm for the concatenation:

public Byte[] ConcatPdf(List<Byte[]> sourceFiles, Boolean PrintWhenOpen =
false)
        {
            Document document = new Document();
            MemoryStream output = new MemoryStream();

            try
            {
                // Initialize pdf writer
                PdfWriter writer = PdfWriter.GetInstance(document, output);
                writer.PageEvent = new PdfPageEvents();
                if (PrintWhenOpen)
                {
                    PdfAction action_apristampa = new
PdfAction(PdfAction.PRINTDIALOG);
                    writer.SetOpenAction(action_apristampa);
                }

                // Open document to write
                document.Open();
                PdfContentByte content = writer.DirectContent;

                // Iterate through all pdf documents
                for (Int32 fileCounter = 0; fileCounter < sourceFiles.Count;
fileCounter++)
                {
                    // Create pdf reader
                    PdfReader reader = new
PdfReader(sourceFiles[fileCounter]);
                    Int32 numberOfPages = reader.NumberOfPages;

                    // Iterate through all pages
                    for (Int32 currentPageIndex = 1; currentPageIndex <=
numberOfPages; currentPageIndex++)
                    {
                        // Determine page size for the current page
                       
document.SetPageSize(reader.GetPageSizeWithRotation(currentPageIndex));

                        // Create page
                        document.NewPage();
                        PdfImportedPage importedPage =
writer.GetImportedPage(reader, currentPageIndex);

                        // Determine page orientation
                        Int32 pageOrientation =
reader.GetPageRotation(currentPageIndex);
                        if ((pageOrientation == 90) || (pageOrientation ==
270))
                            content.AddTemplate(importedPage, 0, -1f, 1f, 0,
0, reader.GetPageSizeWithRotation(currentPageIndex).Height);
                        else
                            content.AddTemplate(importedPage, 1f, 0, 0, 1f,
0, 0);
                    }

                    ConcatPdf_NumPag += numberOfPages;
                }
            }
            catch (Exception exception)
            {
                throw new Exception("There has an unexpected exception" +
                      " occured during the pdf merging process.",
exception);
            }
            finally
            {
                document.Close();
            }
            return output.GetBuffer();
        }
        internal class PdfPageEvents : IPdfPageEvent
        {
            #region members
            private BaseFont _baseFont = null;
            private PdfContentByte _content;
            #endregion

            #region IPdfPageEvent Members
            public void OnOpenDocument(PdfWriter writer, Document document)
            {
                _baseFont = BaseFont.CreateFont(BaseFont.HELVETICA,
                                 BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                _content = writer.DirectContent;
            }

            public void OnStartPage(PdfWriter writer, Document document)
            { }

            public void OnEndPage(PdfWriter writer, Document document)
            {
                // Write header text
                String headerText = "PDF Merger by Smart-Soft";
                _content.BeginText();
                _content.SetFontAndSize(_baseFont, 8);
                _content.SetTextMatrix(GetCenterTextPosition(headerText,
                                       writer), writer.PageSize.Height -
10);
                _content.ShowText(headerText);
                _content.EndText();

                // Write footer text (page numbers)
                String text = "Page " + writer.PageNumber;
                _content.BeginText();
                _content.SetFontAndSize(_baseFont, 8);
                _content.SetTextMatrix(GetCenterTextPosition(text, writer),
10);
                _content.ShowText(text);
                _content.EndText();
            }

            public void OnCloseDocument(PdfWriter writer, Document document)
            { }

            public void OnParagraph(PdfWriter writer,
                        Document document, Single paragraphPosition)
            { }

            public void OnParagraphEnd(PdfWriter writer,
                        Document document, Single paragraphPosition)
            { }

            public void OnChapter(PdfWriter writer, Document document,
                                  Single paragraphPosition, Paragraph title)
            { }

            public void OnChapterEnd(PdfWriter writer,
                        Document document, Single paragraphPosition)
            { }

            public void OnSection(PdfWriter writer, Document document,
                        Single paragraphPosition, Int32 depth, Paragraph
title)
            { }

            public void OnSectionEnd(PdfWriter writer,
                        Document document, Single paragraphPosition)
            { }

            public void OnGenericTag(PdfWriter writer, Document document,
                                     Rectangle rect, String text)
            { }
            #endregion

            private Single GetCenterTextPosition(String text, PdfWriter
writer)
            {
                return writer.PageSize.Width / 2 -
_baseFont.GetWidthPoint(text, 8) / 2;
            }
        }



--
View this message in context: 
http://itext-general.2136553.n4.nabble.com/Insufficient-data-for-an-Image-when-using-PdfConcatenate-tp4658229p4658253.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and 
their applications. This 200-page book is written by three acclaimed 
leaders in the field. The early access version is available now. 
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
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