private void RegisterFont(FontFamily fontFamily, FontStyle fontStyle, FontWeight fontWeight, byte[] data) { #region radpdfprocessing-concepts-fonts_0 FontsRepository.RegisterFont(fontFamily, fontStyle, fontWeight, data); #endregion #region radpdfprocessing-concepts-fonts_1 FontBase font; bool success = FontsRepository.TryCreateFont(fontFamily, fontStyle, fontWeight, out font); #endregion }
private void GetFontDataCompleted(object sender, GetFontDataCompletedEventArgs e) { this.pdfExportCounter.EndUpdate(); System.Diagnostics.Debug.WriteLine("updated font:{0}", e.Result.FontFamilyName); if (e.Error == null && e.Result.IsValid) { PdfFontsServiceFontData result = e.Result; FontFamily fontFamily = new FontFamily(result.FontFamilyName); FontStyle fontStyle = GetFontStyle(result.IsItalic); FontWeight fontWeight = GetFontWeight(result.IsBold); FontsRepository.RegisterFont(fontFamily, fontStyle, fontWeight, result.Bytes); } }
public static void GenerateImageReport(Case Case) { var fArial = new FontFamily("Arial"); var border = new Border(2, RgbColors.Black); var lightBorder = new Border(1, RgbColors.Black); //FontBase fArial16 = new FontBase(); //Set custom font provider FontsProviderBase fontsProvider = new FontsProvider(); FixedExtensibilityManager.FontsProvider = fontsProvider; //Regisitering fonts FontsRepository.RegisterFont(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Bold, fontsProvider.GetFontData(new FontProperties(fArial, FontStyles.Normal, FontWeights.Bold))); RadFixedDocument doc = new RadFixedDocument(); RadFixedDocumentEditor editor = new RadFixedDocumentEditor(doc); //Set page orientation landscape editor.SectionProperties.PageSize = new Size(editor.SectionProperties.PageSize.Height, editor.SectionProperties.PageSize.Width); TimeZoneInfo CurrentTimeZone = TimeZoneInfo.FindSystemTimeZoneById(Case.Client.TimeZoneID); string CurrentTime = DateTimeOffset.UtcNow.ToOffset(CurrentTimeZone.GetUtcOffset(DateTimeOffset.UtcNow)).ToString("ddd MMM d yyyy h:mm:ss tt zzz"); int i = 0; Table table = new Table(); foreach (var card in Case.Cards) { Block block; TableRow row; TableCell cell; if (i % 4 == 0) { if (i != 0) { #region Page header block = new Block(); //block.TextProperties.Font = new F; block.HorizontalAlignment = HorizontalAlignment.Center; block.TextProperties.FontSize = 14f; block.TextProperties.TrySetFont(fArial, FontStyles.Normal, FontWeights.Bold); var textFragment = new TextFragment("Test"); textFragment.FontSize = 14; bool success = FontsRepository.TryCreateFont(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Heavy, out FontBase font); textFragment.Font = font; block.Insert(textFragment); block.SaveTextProperties(); if (Case.ClientGroup != null) { block.InsertText(Case.ClientGroup.Name); block.InsertLineBreak(); } block.InsertText(Case.Client.Name); block.InsertLineBreak(); block.InsertText((Case.Client.Address1 + " " + Case.Client.Address2).Trim()); block.InsertLineBreak(); block.InsertText(Case.Client.City + ", " + Case.Client.State + ", " + Case.Client.Zipcode); block.InsertLineBreak(); editor.InsertBlock(block); block = new Block(); block.HorizontalAlignment = HorizontalAlignment.Center; block.TextProperties.Font = font; //block.TextProperties.TrySetFont(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Heavy); block.TextProperties.FontSize = 16f; block.InsertText("Card Image Report"); editor.InsertBlock(block); block = new Block(); block.InsertText($"Case #: {card.Case.CaseNumber} Total Cards: {ReportHelpers.GetCardCount(Case.Cards)}"); block.InsertLineBreak(); block.InsertText(CurrentTime); block.InsertLineBreak(); editor.InsertBlock(block); #endregion var section = editor.SectionProperties; editor.InsertTable(table); editor.InsertPageBreak(); } //Start new page //Set new table header and other things table = new Table(); table.LayoutType = TableLayoutType.FixedWidth; table.Margin = new Thickness { Left = 0, Right = 0 }; row = table.Rows.AddTableRow(); block = new Block(); block.InsertText(new FontFamily("Courier"), FontStyles.Normal, FontWeights.Heavy, "Images"); cell = row.Cells.AddTableCell(); cell.Padding = new Thickness(2); cell.Blocks.Add(block); cell.Borders = new TableCellBorders(border, border, border, border); block = new Block(); block.InsertText("Printed Details"); cell = row.Cells.AddTableCell(); cell.Padding = new Thickness(2); cell.Blocks.Add(block); cell.Borders = new TableCellBorders(border, border, border, border); block = new Block(); block.InsertText("Magstripe Details"); cell = row.Cells.AddTableCell(); cell.Padding = new Thickness(2); cell.Blocks.Add(block); cell.Borders = new TableCellBorders(border, border, border, border); } #region Add Row row = table.Rows.AddTableRow(); cell = row.Cells.AddTableCell(); var imageTable = new Table(); var imageRow = imageTable.Rows.AddTableRow(); foreach (var image in card.CardImages) { var imageCell = imageRow.Cells.AddTableCell(); block = new Block(); block.SpacingBefore = 3f; block.SpacingAfter = 3f; block.InsertImage(GetCaseImage(image.ImageData), 160f, 120f); imageCell.Padding = new Telerik.Documents.Primitives.Thickness(5); imageCell.Blocks.Add(block); } cell.Borders = new TableCellBorders(lightBorder, lightBorder, lightBorder, lightBorder); cell.Padding = new Telerik.Documents.Primitives.Thickness(6); imageTable.LayoutType = TableLayoutType.AutoFit; cell.Blocks.Add(imageTable); cell = row.Cells.AddTableCell(); block = new Block(); block.HorizontalAlignment = HorizontalAlignment.Left; block.VerticalAlignment = VerticalAlignment.Center; InsertDetails(block, card); cell.Borders = new TableCellBorders(lightBorder, lightBorder, lightBorder, lightBorder); cell.Padding = new Thickness(5); cell.Blocks.Add(block); cell = row.Cells.AddTableCell(); block = new Block(); block.HorizontalAlignment = HorizontalAlignment.Left; if (card.ClonedCardParent != null) { if (card.ClonedCardParent.TrackData != null) { string cardTrackUnenc = card.ClonedCardParent.TrackData.Trim(); CCTrackParser trackParser = new CCTrackParser(); var trackData = trackParser.Parse(cardTrackUnenc); InsertMagstripDetails(block, trackData); } else { InsertDetails(block, card.ClonedCardParent); } } else if (card.EntryMethod == "Swipe" || !card.MissingPrintedInfo) { if (card.TrackData != null) { string cardTrackUnenc = card.TrackData.Trim(); CCTrackParser trackParser = new CCTrackParser(); var trackData = trackParser.Parse(cardTrackUnenc); InsertMagstripDetails(block, trackData); } else { InsertDetails(block, card); } } cell.Borders = new TableCellBorders(lightBorder, lightBorder, lightBorder, lightBorder); cell.Padding = new Thickness(5); cell.Blocks.Add(block); #endregion i++; } PdfFormatProvider provider = new PdfFormatProvider(); using (var stream = new FileStream(@"outPDF.pdf", FileMode.OpenOrCreate)) { provider.Export(doc, stream); } }