private void WriteReport(PdfDocument doc, IEnumerable <Product> products) { foreach (var product in products) { var p = new Paragraph(new Phrase(product.Name)) { Font = { Size = 16 }, Alignment = Element.ALIGN_LEFT }; p.Font.SetStyle("bold"); doc.Add(p); p = new Paragraph(new Phrase(product.Description)) { Alignment = Element.ALIGN_JUSTIFIED, Font = { Size = 14 } }; doc.Add(p); p = new Paragraph(new Phrase(product.Price)) { Font = { Size = 16 }, Alignment = Element.ALIGN_LEFT }; p.Font.SetStyle("bold"); doc.Add(p); doc.Add(new Paragraph("")); } }
public bool CreatePdf() { bool result = true; try { if (calendarEvent == null) { result = false; } else { PdfDocument.Open(); Chapter chapter = AddChapter(new Paragraph(GetTitleText("Záznam o návšteve")) { SpacingAfter = 10f, Alignment = HAlingmentLeft }, 0, 0); iTextSharp.text.Section firstSection = AddSection(chapter, 0f, new Paragraph(GetSectionText(calendarEvent.Patient.FullName + " " + calendarEvent.StartDate.ToString("d. MMMM yyyy, HH:mm"))) , 0); firstSection.Add(CreateInfoTable()); iTextSharp.text.Section actionsSection = AddSection(chapter, 0f, new Paragraph(GetSectionText("Vykonané")), 0); if (!string.IsNullOrEmpty(calendarEvent.ExecutedActionText)) { actionsSection.Add(new Paragraph(GetText(calendarEvent.ExecutedActionText))); } actionsSection.Add(CreateActionsTable()); iTextSharp.text.Section billingSection = AddSection(chapter, 0f, new Paragraph(GetSectionText("Vyúčtovanie")), 0); EventBill eventBill = calendarEvent.EventBills.FirstOrDefault(); if (eventBill != null && eventBill.EventBillItems.Count != 0) { billingSection.Add(CreateBillingTable(eventBill)); } else { billingSection.Add(new Paragraph(GetBoldText("Návšteva neobsahuje žiadne účtovné položky"))); } PdfDocument.Add(chapter); AddFooter(); PdfDocument.Close(); } } catch (Exception ex) { BasicMessagesHandler.LogException(ex); result = false; } return(result); }
private void WriteHeader(PdfDocument doc) { var header = new Paragraph(new Phrase("Отчет по остатку товара")) { Alignment = Element.ALIGN_CENTER, Font = { Size = 18 } }; doc.Add(header); }
public bool CreatePdf() { bool result = true; try { if (budget == null) { result = false; } else { PdfDocument.Open(); Chapter chapter = AddChapter(new Paragraph(GetTitleText(budget.Name)) { SpacingAfter = 10f, Alignment = HAlingmentLeft }, 0, 0); iTextSharp.text.Section infoSection = AddSection(chapter, 0f, new Paragraph(GetBoldText("Základné informácie")) { SpacingAfter = 0f, SpacingBefore = 0f }, 0); AddInfoTable(infoSection); iTextSharp.text.Section itemsSection = AddSection(chapter, 0f, new Paragraph(GetBoldText("Položky")) { SpacingBefore = 0f, SpacingAfter = 0f }, 0); AddItemsTable(itemsSection); PdfDocument.Add(chapter); PdfDocument.Close(); } } catch (Exception ex) { BasicMessagesHandler.LogException(ex); result = false; if (PdfDocument.IsOpen()) { PdfDocument.Close(); } } return(result); }
public bool CreatePdf() { bool result = true; try { if (patient == null || doctor == null) { result = false; } else { PdfDocument.Open(); Chapter chapter1 = AddChapter( new Paragraph(GetTitleText(patient.FullName)) { Alignment = HAlingmentCenter, SpacingAfter = 10f }, 0, 0); iTextSharp.text.Section personalInfoSection = AddSection(chapter1, 0f, new Paragraph(GetSectionText("Osobné údaje")), 0); PdfPTable table = new PdfPTable(new[] { 60f, 40f }) { HorizontalAlignment = HAlingmentLeft, SpacingBefore = 10f, SpacingAfter = 10f, WidthPercentage = 100f }; PdfPTable personalInfoTable = CreatePersonalInfoTable(); Image pic = null; if (patient.AvatarImagePath != null && System.IO.File.Exists(patient.AvatarImagePath)) { pic = Image.GetInstance(patient.AvatarImagePath); pic.ScaleToFit((RX - LX) / 2f, GetTableHeight(personalInfoTable)); } else { pic = Image.GetInstance((System.Drawing.Image)Properties.Resources.noUserImage, System.Drawing.Imaging.ImageFormat.Png); } PdfPCell imageCell = new PdfPCell(pic, false) { PaddingTop = 5f, BorderColor = BaseColor.WHITE }; PdfPCell tableCell = new PdfPCell(personalInfoTable) { PaddingTop = 5f, BorderColor = BaseColor.WHITE }; table.AddCell(tableCell); table.AddCell(imageCell); personalInfoSection.Add(table); iTextSharp.text.Section addressAndContactSection = AddSection(chapter1, 0f, new Paragraph(GetSectionText("Adresa a kontaktné údaje")), 0); table = new PdfPTable(new[] { 100f }) { HorizontalAlignment = HAlingmentLeft, SpacingBefore = 10f, WidthPercentage = 100f }; PdfPCell addressCell = new PdfPCell(CreateAddressTable()) { PaddingTop = 5f, BorderColor = BaseColor.WHITE }; PdfPCell contactCell = new PdfPCell(CreateContactTable()) { PaddingTop = 5f, BorderColor = BaseColor.WHITE }; table.AddCell(addressCell); table.AddCell(contactCell); addressAndContactSection.Add(table); Chapter chapter2 = AddChapter( new Paragraph(GetTitleText("Zdravotná karta pacienta")) { SpacingAfter = 10f }, 0, 0); foreach (var ezkoSection in ezkoController.GetSections().OrderBy(x => x.Name)) { iTextSharp.text.Section pdfSection = AddSection(chapter2, 0f, new Paragraph(GetSectionText(ezkoSection.Name)), 0); PdfPTable sectionTable = CreateEzkoSectionTable(pdfSection, ezkoSection); pdfSection.Add(sectionTable); } PdfDocument.Add(chapter1); PdfDocument.Add(chapter2); Chapter chapter3 = AddChapter( new Paragraph(GetTitleText("Návštevy pacienta")) { SpacingAfter = 10f }, 0, 0); if (patient.CalendarEvents.Count > 0) { PdfPTable eventsTable = CreateEventsTable(); chapter3.Add(eventsTable); } else { chapter3.Add(new Paragraph(GetNoteText("Pacient zatial nemá žiadne návštevy"))); } //chapter3.Add(new Paragraph(GetText("Pacient zatial nemá žiadne návštevy"))); PdfDocument.Add(chapter3); PdfDocument.Close(); } } catch (Exception ex) { BasicMessagesHandler.LogException(ex); result = false; } return(result); }
public bool CreatePdf() { bool result = true; try { if (form == null) { result = false; } else { PdfDocument.Open(); Chapter chapter = AddChapter(new Paragraph(GetTitleText(form.Name)) { SpacingAfter = 10f, Alignment = HAlingmentLeft }, 0, 0); PdfDocument.Add(chapter); AddHorizontalLine(); float currentY = Y; foreach (var item in form.FieldForms.Where(x => !x.Field.IsDeleted).OrderBy(x => x.Question.Index)) { switch (item.Field.TypeID) { case (int)FieldTypeEnum.LongText: currentY = AddTextBox(item.Question.Value, currentY, richTextBoxHeight, 0.8f, 5f, System.Drawing.Color.Black); break; case (int)FieldTypeEnum.Text: currentY = AddTextBox(item.Question.Value, currentY, textBoxHeight, 0.8f, 5f, System.Drawing.Color.Black); break; case (int)FieldTypeEnum.CheckBox: string[] choices = item.Field.FieldValues.Select(x => x.Value).ToArray(); currentY = AddCheckBoxes(choices, item.Question.Value, "(Môžete označiť viacero možností)", currentY, checkBoxSize, 0.8f, 5f, System.Drawing.Color.Black); break; case (int)FieldTypeEnum.RadioBox: choices = item.Field.FieldValues.Select(x => x.Value).ToArray(); currentY = AddCheckBoxes(choices, item.Question.Value, "(Vyberte jednu z možností)", currentY, checkBoxSize, 0.8f, 5f, System.Drawing.Color.Black); break; case (int)FieldTypeEnum.SelectBox: choices = item.Field.FieldValues.Select(x => x.Value).ToArray(); currentY = AddCheckBoxes(choices, item.Question.Value, "(Vyberte jednu z možností)", currentY, checkBoxSize, 0.8f, 5f, System.Drawing.Color.Black); break; default: break; } } PdfDocument.Close(); } } catch (Exception ex) { BasicMessagesHandler.LogException(ex); result = false; } return(result); }
/// <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; } }