public Image[] Serialize(ReportDocument document) { ArrayList images = new ArrayList(); Size documentSize = document.PaperType == Paper.Type.Custom ? document.PixelSize : Paper.GetPaperSize(document.PaperType); if (document.Layout == Com.Delta.PrintManager.Engine.ReportDocument.LayoutType.Landscape) { documentSize = new Size(documentSize.Height, documentSize.Width); } document.StartPrinting(); for (int sectionCounter = 0; sectionCounter < document.Sections.Count; sectionCounter++) { document.NewPage(); Section section = (Section)document.Sections[sectionCounter]; section.Prepare(true); Image image = new Bitmap(documentSize.Width, documentSize.Height); bool morePages = false; int sectionPage = 0; do { Graphics g = Graphics.FromImage(image); g.Clear(Color.White); sectionPage++; morePages = section.UpdateDynamicContent(); for (int i = 0; i < section.Objects.Length; i++) { if (section.Objects[i].Layout == ICustomPaint.LayoutTypes.EveryPage) { ProcessElement(g, section.Objects[i]); } else if (section.Objects[i].Layout == ICustomPaint.LayoutTypes.FirstPage) { if (sectionPage == 1) { ProcessElement(g, section.Objects[i]); } } else if (section.Objects[i].Layout == ICustomPaint.LayoutTypes.LastPage) { if (!morePages) { ProcessElement(g, section.Objects[i]); } } } if (morePages) { images.Add(image); image = new Bitmap(documentSize.Width, documentSize.Height); document.NewPage(); section.Prepare(false); } }while(morePages); if (image != null) { images.Add(image); image = new Bitmap(documentSize.Width, documentSize.Height); } document.NewSection(); } return((Image[])images.ToArray(typeof(Image))); }
internal string Serialize(ReportDocument document, bool hardcodeLink) { StringBuilder buffer = new StringBuilder(); Size documentSize = new Size(200, 200); if (document.PaperType == Paper.Type.Custom) { documentSize = document.PixelSize; } else { documentSize = Paper.GetPaperSize(document.PaperType); } MemoryStream ms = new MemoryStream(); StringWriter sw = new StringWriter(buffer); sw.WriteLine("<html>"); sw.WriteLine("<head>"); sw.WriteLine("</head>"); int pageNum = 1; int pageGap = 10; int pageOffset = 10; int pageHeight = document.Layout == Com.Delta.PrintManager.Engine.ReportDocument.LayoutType.Portrait ? documentSize.Height : documentSize.Width; sw.WriteLine("<body bgcolor=" + FormatColor(SystemColors.AppWorkspace) + " style='margin-top:10'>"); string style = ""; if (document.Layout == Com.Delta.PrintManager.Engine.ReportDocument.LayoutType.Portrait) { style += Format("width", String.Format("{0}px", documentSize.Width)); style += Format("height", String.Format("{0}px", documentSize.Height)); } else { style += Format("width", String.Format("{0}px", documentSize.Height)); style += Format("height", String.Format("{0}px", documentSize.Width)); } style += Format("border", "1px solid black"); style += Format("background-color", "white"); style += Format("margin-bottom", String.Format("{0}px", pageGap)); document.StartPrinting(); for (int sectionCounter = 0; sectionCounter < document.Sections.Count; sectionCounter++) { document.NewPage(); Section section = (Section)document.Sections[sectionCounter]; section.Prepare(true); sw.WriteLine("<a name=page1>"); sw.WriteLine("<div name=page " + FormatStyle(style) + ">"); 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(sw, section.Objects[i], i, pageOffset, hardcodeLink); } else if (section.Objects[i].Layout == ICustomPaint.LayoutTypes.FirstPage) { if (sectionPage == 1) { ProcessElement(sw, section.Objects[i], i, pageOffset, hardcodeLink); } } else if (section.Objects[i].Layout == ICustomPaint.LayoutTypes.LastPage) { if (!morePages) { ProcessElement(sw, section.Objects[i], i, pageOffset, hardcodeLink); } } } if (morePages) { document.NewPage(); section.Prepare(false); pageNum++; sw.WriteLine("</div>"); sw.WriteLine("<a name=page" + pageNum.ToString() + ">"); sw.WriteLine("<div name=page " + FormatStyle(style) + ">"); pageOffset += pageHeight + pageGap; } }while(morePages); document.NewSection(); sw.WriteLine("</div>"); pageOffset += pageHeight + pageGap; } sw.WriteLine("</body>"); sw.WriteLine("</html>"); return(buffer.ToString()); }
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); }