public byte[] Serialize(ReportDocument document) { //long start = DateTime.Now.Ticks; Size documentSize = document.PaperType == Paper.Type.Custom ? document.PixelSize : Paper.GetPaperSize(document.PaperType); if (document.Layout == Com.Delta.PrintManager.Engine.ReportDocument.LayoutType.Portrait) { pdfDocument = new PdfDocument(PdfDocumentFormat.InInches(documentSize.Width * 0.72 / 72, documentSize.Height * 0.72 / 72)); } else { pdfDocument = new PdfDocument(PdfDocumentFormat.InInches(documentSize.Height * 0.72 / 72, documentSize.Width * 0.72 / 72)); } document.StartPrinting(); for (int sectionCounter = 0; sectionCounter < document.Sections.Count; sectionCounter++) { document.NewPage(); Section section = (Section)document.Sections[sectionCounter]; section.Prepare(true); PdfPage page = pdfDocument.NewPage(); bool morePages = false; int sectionPage = 0; do { sectionPage++; morePages = section.UpdateDynamicContent(); for (int i = 0; i < section.Objects.Length; i++) { if (section.Objects[i].Layout == ICustomPaint.LayoutTypes.EveryPage) { ProcessElement(page, section.Objects[i]); } else if (section.Objects[i].Layout == ICustomPaint.LayoutTypes.FirstPage) { if (sectionPage == 1) { ProcessElement(page, section.Objects[i]); } } else if (section.Objects[i].Layout == ICustomPaint.LayoutTypes.LastPage) { if (!morePages) { ProcessElement(page, section.Objects[i]); } } } if (morePages) { page.SaveToDocument(); page = pdfDocument.NewPage(); document.NewPage(); section.Prepare(false); } }while(morePages); page.SaveToDocument(); document.NewSection(); } MemoryStream ms = new MemoryStream(); pdfDocument.SaveToStream(ms); byte[] content = new byte[ms.Length]; //Console.WriteLine((DateTime.Now.Ticks-start)/10000); ms.Position = 0; ms.Read(content, 0, content.Length); ms.Close(); return(content); }