Font style, type and weight in insertrun how

3 Answers 24 Views
PdfProcessing
David
Top achievements
Rank 1
Iron
Iron
Iron
David asked on 20 Jul 2021, 03:48 PM

We are using a RadFixedDocument and RadFixedDocumentEditor to try to create a sample PDF

I can not find any documentation showing how to actually change the font info. Where are the specifics? Here is the code I have tried.

 

RadFixedDocument document = new RadFixedDocument();

            using (RadFixedDocumentEditor editor = new RadFixedDocumentEditor(document))
            {            

                List list = editor.Lists.AddList(ListTemplateType.BulletDefault);
                editor.ParagraphProperties.ListId = list.Id;
                editor.ParagraphProperties.ListLevel = 0;

                editor.InsertParagraph();
               // editor.CharacterFormatting.FontFamily.LocalValue = new FontFamily("Times New Roman");
                editor.InsertRun(new FontFamily("Times New Roman"), new FontStyle(3) , new FontWeight(15) , "Blazor Demo:");

                editor.ParagraphProperties.ListLevel = 1;
                editor.InsertParagraph();
                editor.InsertRun("This is a prototype to explore the various Architectual Elements needed for a SPOT rewrite.");

                editor.InsertParagraph();
                editor.InsertRun("Explore Blazor in regards to moving from a ASP.Net WebForm development team to Blazor MVC structure with.Net Core.");

                editor.InsertParagraph();
                editor.InsertRun("✓Use of EntityFramework within Blazor /.Net Core.");

                editor.InsertParagraph();
                editor.InsertRun("✓Basic Search screen with search fields.");

                editor.InsertParagraph();
                editor.InsertRun("✓Basic Edit screen with field validation both RealTime and on submitting.");

                editor.InsertParagraph();
                editor.InsertRun("✓Telerik Blazor controls, specially the Grid with Sorting and Paging, Dialogs, Pop_up windows.");

                editor.InsertParagraph();
                editor.InsertRun("✓BootStrap use with Blazor for page support of any screen resolution(within reason!).");

                editor.InsertParagraph();
                editor.InsertRun("✓Logging.");
                editor.InsertRun("✓Pass Fortify! Test with current SPOT settings.");

                editor.InsertParagraph();
                editor.InsertRun("✓Custom field validation(SSN / FIN, Phone number).");

                editor.InsertParagraph();
                editor.InsertRun("✓Creating our own Blazor components for fields like SSN.");

                editor.InsertParagraph();
                editor.InsertRun("✓Handle error messages from the server.");

                editor.InsertParagraph();
                editor.InsertRun(" Explore configuration files ");

                editor.InsertParagraph();
                editor.InsertRun(" Global Exception Handling and Logging ");

                editor.InsertParagraph();
                editor.InsertRun("✓Validation messages Resource file and i18n ");

                editor.InsertParagraph();
                editor.InsertRun(" Explore validation messages store in the DB.");

                editor.InsertParagraph();
                editor.InsertRun(" Authentication ");

                editor.InsertParagraph();
                editor.InsertRun("✓Session Timeout ");

                editor.InsertParagraph();
                editor.InsertRun(" Does it work with XUNIT ?");

                editor.InsertParagraph();
                editor.InsertRun("✓Does it work with Resharper ?");

                editor.InsertParagraph();
                editor.InsertRun("✓Popup windows and confirmation dialogs.");

                editor.InsertParagraph();
                editor.InsertRun("✓Calling stored procedures from EF core.");

                editor.InsertParagraph();
                editor.InsertRun(" SSRS Reporting Viewer and report interfacing."); //Dave talk to Cynthia, Cynthia says talk to Chou, Zhang

                editor.InsertParagraph();
                editor.InsertRun(" PDF generation "); //Dave do a pdf of this list

                editor.InsertParagraph();
                editor.InsertRun(" Unhandled Exception Handling(i.g.Reload message)");

 

}

                

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 22 Jul 2021, 01:25 PM

Hi David,

Thank you for sharing the code snippet with us. It seems the font info is set in the correct way. Font-related information when inserting inlines with the help of the RadFixedDocumentEditor can be found in the RadFixedDocumentEditor`s Inlines help topic.

As a side note, if you are using the PdfProcessing assemblies in a .NET Core/.NET Standard environment and you are using fonts different from the 14 Standard Fonts you will need to provide the font data to the FontsProvider property of the FixedExtensibilityManager. More information can be found in the PdfProcessing`s Cross-Platform Support help article. We have a good SDK example in our GitHub repository as well: CreatePdfUsingRadFixedDocumentEditor.

Regards,
Martin
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
David
Top achievements
Rank 1
Iron
Iron
Iron
answered on 22 Jul 2021, 01:48 PM

We got our page mostly working with blocks for the headers and a list in the editor. using code like this

 

                Block blockHeader = new Block();
                blockHeader.HorizontalAlignment = HorizontalAlignment.Center;
                blockHeader.TextProperties.FontSize = 50;
                blockHeader.TextProperties.Font = FontsRepository.CourierBold;
                blockHeader.InsertText("SPOT Blazor Demo");
                editor.InsertBlock(blockHeader);

 

but we can not get zapfdingbats characters to print within a list

 

                List list = editor.Lists.AddList(ListTemplateType.BulletDefault);
                editor.ParagraphProperties.ListId = list.Id;
                editor.ParagraphProperties.ListLevel = 0;
                editor.CharacterProperties.Font = FontsRepository.TimesRoman;

                editor.InsertParagraph();
                editor.InsertRun("Explore Blazor in regards to moving from a ASP.Net WebForm development team to Blazor MVC structure with.Net Core.");

                editor.InsertParagraph();
                editor.CharacterProperties.Font = FontsRepository.ZapfDingbats;
                string c = System.Convert.ToChar(System.Convert.ToUInt32("0x2713", 16)).ToString();
                editor.InsertRun(c);

 

We r attempting tp print a checkmark. When we debug c is a checkmark but it is blank in the pdf.

Can bulleted lists not have special chars?

David
Top achievements
Rank 1
Iron
Iron
Iron
commented on 22 Jul 2021, 01:50 PM

we also tried it in a block like this:

// List listBlock = new List(ListTemplateType.BulletDefault);
Block block = new Block();
block.TextProperties.Font = FontsRepository.ZapfDingbats;
block.TextProperties.FontSize = 16;
//block.SetBullet(listBlock, 0);
string c = System.Convert.ToChar(System.Convert.ToUInt32("0x2713", 16)).ToString();
block.InsertText(c);
editor.InsertBlock(block);

all we get is a blank line.
0
Martin
Telerik team
answered on 23 Jul 2021, 09:29 AM

Hello David,

The PdfProcessing library seems to recognize this character is part of the Meiryo font family instead of the ZapfDingbats standard font, so you will need to provide the Meiryo font data using the FixedExtensibilityManager. You can achieve this by passing a custom implementation of the FontsProviderBase to the FixedExtensibilityManager`s FontsProvider property: 

FixedExtensibilityManager.FontsProvider = new FontsProvider();

and a sample implementation of the FontsProvider class:

internal class FontsProvider : FontsProviderBase
{
	private readonly string fontFolder = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);

	public override byte[] GetFontData(FontProperties fontProperties)
	{
		string fontFamilyName = fontProperties.FontFamilyName;
		bool isItalic = fontProperties.FontStyle == FontStyles.Italic;
		bool isBold = fontProperties.FontWeight == FontWeights.Bold;

		if (fontFamilyName == "Arial")
		{
			return this.GetFontDataFromFontFolder("arial.ttf");
		}
		else if (fontFamilyName == "Symbol")
		{
			return this.GetFontDataFromFontFolder("symbol.ttf");
		}
		else if (fontFamilyName == "Microsoft YaHei")
		{
			return this.GetFontDataFromFontFolder("msyh.ttc");
		}
		else if (fontFamilyName == "Meiryo")
		{
			return this.GetFontDataFromFontFolder("meiryo.ttc");
		}

		return null;
	}

	private byte[] GetFontDataFromFontFolder(string fontFileName)
	{
		using (FileStream fileStream = File.OpenRead(this.fontFolder + "\\" + fontFileName))
		{
			using (MemoryStream memoryStream = new MemoryStream())
			{
				fileStream.CopyTo(memoryStream);
				return memoryStream.ToArray();
			}
		}
	}
}

I am attaching the sample project I created to test this functionality as well. Please, feel free to modify it in a way closer to your scenario.

Regards,
Martin
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
PdfProcessing
Asked by
David
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Martin
Telerik team
David
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or