/// <summary> /// Gets the page count. /// </summary> /// <remarks>The PageRange property of the GcReport class is ignored.</remarks> /// <returns>Returns the number of pages in the PDF file.</returns> public int GetPageCount() { this.openTypeFontUtility = new OpenTypeFontUtility(GcReportContext.defaultFont, this.Dpi); GcReportContext context = new GcReportContext(this.report, this.Dpi, this.openTypeFontUtility) { UnitsPerInch = 0x48 }; this.context = context; this.context.GeneratePageBlocks(); int num = 0; foreach (List <GcPageBlock> list in this.context.Pages) { num += list.Count; } return(num); }
/// <summary> /// Exports the inner. /// </summary> /// <param name="stream">The stream</param> /// <param name="doc">The doc.</param> /// <param name="saveAuto">if set to <c>true</c> [save auto].</param> /// <param name="checkEmpty">if set to <c>true</c> [check empty].</param> /// <param name="processSettings">if set to <c>true</c> [process settings].</param> /// <param name="otfu">The otfu.</param> /// <param name="frc">The FRC.</param> /// <param name="pageCount">The page count.</param> internal void ExportInner(Stream stream, PdfDocument doc, bool saveAuto, bool checkEmpty, bool processSettings, OpenTypeFontUtility otfu, GcReportContext frc, int pageCount) { bool flag2; doc = doc ?? CreatePdfDocument(); this.currentDoc = doc; if (processSettings) { this.settings.AppendTo(doc); } bool flag = false; if (otfu != null) { this.openTypeFontUtility = otfu; this.openTypeFontUtility.Dpi = this.Dpi; } else { this.openTypeFontUtility = new OpenTypeFontUtility(GcReportContext.defaultFont, this.Dpi); flag = true; this.openTypeFontUtility.ExternalFont += this.ExternalFont; } if (frc != null) { this.context = frc; } else { GcReportContext context = new GcReportContext(this.report, this.Dpi, this.openTypeFontUtility) { UnitsPerInch = 0x48 }; this.context = context; this.context.GeneratePageBlocks(); } if (this.report.Watermark != null) { this.report.Watermark.Height = (int)this.context.PageRects.PageRectangle.Height; this.report.Watermark.Width = (int)this.context.PageRects.PageRectangle.Width; } ExporterState state = new ExporterState(this.context) { BlackAndWhite = this.report.BlackAndWhite }; int num = 0; foreach (List <GcPageBlock> list in this.context.Pages) { state.PageCount += list.Count; num = Math.Max(list.Count, num); } if (pageCount >= 0) { state.PageCount = pageCount; } else { state.PageCount += this.report.FirstPageNumber - 1; } switch (this.context.Report.PageOrder) { case PrintPageOrder.Auto: flag2 = this.context.Pages.Count >= num; break; case PrintPageOrder.DownThenOver: flag2 = true; break; case PrintPageOrder.OverThenDown: flag2 = false; break; default: throw new ArgumentOutOfRangeException(); } List <PageState> list2 = new List <PageState>(); if (flag2) { for (int i = 0; i < num; i++) { state.CurrentHPageNumber++; state.CurrentVPageNumber = 0; foreach (List <GcPageBlock> list3 in this.context.Pages) { if (list3.Count > i) { state.CurrentPageNumber++; state.CurrentVPageNumber++; list2.Add(new PageState(state.CurrentHPageNumber, state.CurrentVPageNumber, state.CurrentPageNumber, list3[i])); } } } } else { foreach (List <GcPageBlock> list4 in this.context.Pages) { state.CurrentVPageNumber++; state.CurrentHPageNumber = 0; foreach (GcPageBlock block in list4) { state.CurrentPageNumber++; state.CurrentHPageNumber++; list2.Add(new PageState(state.CurrentHPageNumber, state.CurrentVPageNumber, state.CurrentPageNumber, block)); } } } if (list2.Count > 0) { if (string.IsNullOrEmpty(this.report.PageRange)) { foreach (PageState state2 in list2) { state.CurrentHPageNumber = state2.HPageIndex; state.CurrentVPageNumber = state2.VPageIndex; state.CurrentPageNumber = (state2.PageIndex + this.report.FirstPageNumber) - 1; this.ExportPage(state, doc, state2.PageBlock); } } else { foreach (int num3 in Utilities.GetPageRange(this.report.PageRange, list2.Count)) { PageState state3 = list2[num3 - 1]; state.CurrentHPageNumber = state3.HPageIndex; state.CurrentVPageNumber = state3.VPageIndex; state.CurrentPageNumber = (state3.PageIndex + this.report.FirstPageNumber) - 1; this.ExportPage(state, doc, state3.PageBlock); } } } if (checkEmpty && (doc.Pages.PageCount <= 0)) { this.ExportEmptyPage(state, doc); } if (state.Bookmarks.Count > 0) { PdfOutlineItem item; if (doc.Outlines.Items.Count > 0) { item = doc.Outlines.Items[0]; } else { item = new PdfOutlineItem(this.report.Bookmark, state.FirstPage); doc.Outlines.Items.Add(item); } Dictionary <Bookmark, List <PdfOutlineItem> > dictionary = new Dictionary <Bookmark, List <PdfOutlineItem> >(); foreach (ExporterState.BookmarkState state4 in state.Bookmarks) { PdfOutlineItem item2 = new PdfOutlineItem(state4.Bookmark.Text, new PdfXYZDestination(state4.Page, (float)state4.Location.X, (float)state4.Location.Y, 0f)); if (!dictionary.ContainsKey(state4.Bookmark)) { dictionary.Add(state4.Bookmark, new List <PdfOutlineItem>()); } dictionary[state4.Bookmark].Add(item2); } foreach (KeyValuePair <Bookmark, List <PdfOutlineItem> > pair in dictionary) { Bookmark bookmark = pair.Key; List <PdfOutlineItem> list6 = pair.Value; if ((bookmark.Parent == null) || !dictionary.ContainsKey(bookmark.Parent)) { foreach (PdfOutlineItem item3 in list6) { item.ChildItems.Add(item3); } } else { List <PdfOutlineItem> list7 = dictionary[bookmark.Parent]; foreach (PdfOutlineItem item4 in list6) { PdfOutlineItem item5 = list7[0]; if (list7.Count > 1) { foreach (PdfOutlineItem item6 in list7) { if (item6.Dest.TargetPage == item4.Dest.TargetPage) { item5 = item6; break; } } } item5.ChildItems.Add(item4); } } } } if (processSettings) { if ((this.settings.DestinationType != DestinationType.Auto) || (doc.Pages.PageCount > 0)) { PdfArray array = new PdfArray(); if ((this.settings.OpenPageNumber <= doc.Pages.PageCount) && (doc.Pages.PageCount > 0)) { array.Add(doc.Pages.Kids[this.settings.OpenPageNumber - 1]); } else { array.Add(doc.Pages.Kids[0]); } switch (this.settings.DestinationType) { case DestinationType.Auto: break; case DestinationType.FitPage: array.Add(PdfName.Fit); break; case DestinationType.FitWidth: array.Add(PdfName.FitH); break; case DestinationType.FitHeight: array.Add(PdfName.FitV); array.Add(PdfNumber.Zero); break; case DestinationType.FitBox: array.Add(PdfName.FitB); break; default: throw new ArgumentOutOfRangeException(); } doc.Add(PdfName.OpenAction, array); } if ((this.settings.DocumentAttachments.Count > 0) && (doc.Pages.PageCount > 0)) { PdfPage page = doc.Pages.Kids[doc.Pages.PageCount - 1] as PdfPage; if (page != null) { foreach (DocumentAttachment attachment in this.settings.DocumentAttachments) { if ((!string.IsNullOrEmpty(attachment.Name) && (attachment.FileStreamInner != null)) && attachment.FileStreamInner.CanRead) { PdfFileAttachmentAnnotation annotation = new PdfFileAttachmentAnnotation { FileSpecification = { FileName = attachment.Name } }; attachment.FileStreamInner.WriteTo((Stream)annotation.FileSpecification.FileStream.Data); annotation.FileSpecification.FileStream.Size = attachment.FileStreamInner.Length; annotation.FileSpecification.FileStream.MIME = attachment.ContentType; annotation.ModifiedDate = DateTime.Now; annotation.FileSpecification.FileStream.ModifyDate = DateTime.Now; annotation.FileSpecification.FileStream.CreationDate = DateTime.Now; if (!string.IsNullOrEmpty(attachment.Description)) { annotation.Contents = attachment.Description; } if (attachment.Compress) { annotation.FileSpecification.FileStream.Filters.Enqueue(PdfFilter.FlateFilter); } annotation.Flags = PdfAnnotationBase.Flag.NoView | PdfAnnotationBase.Flag.Hidden | PdfAnnotationBase.Flag.Invisible; annotation.Rectangle = new PdfRectangle(-100f, -100f, 1f, 1f); page.Annotations.Add(annotation); } } } } } if (saveAuto) { SavePdfDocment(doc, stream); } if (flag) { this.openTypeFontUtility.ExternalFont -= this.ExternalFont; } }