How i can specify DefaultFontName for Document class

Hi,


In Aspose.Pdf.Generator.Pdf class we were using following properties.

1. DefaultFontName
2. IsCoreFontUsed
3. IsTruetypeFontMapCached
4.TruetypeFontMapPath

How we can achieve similar functionality in Aspose.Pdf.Document class object.

Regards,
Sandeep

Hi Sandeep,


Thanks for your inquiry. I am afraid the mentioned properties are not available in new generator (Aspose.Pdf.Generator). We have a logged an enhancement ticket as PDFNEWNET-37501 in our issue tracking system for further investigation and implementation.

Moreover, we will appreciated it if you please share your sample code here, it will help us to address your use case exactly to provide any solution/workaround.

We are sorry for the inconvenience caused.

Best Regards,

sgarg@saba.com:
1. DefaultFontName

How we can achieve similar functionality in Aspose.Pdf.Document class object.
Hi Sandeep,

Adding more to Tilal’s comments, once the PDF file is generated, you can change the font of PDF file by following the instructions specified over Replace fonts in existing PDF file

Question here is how we can set the DefaultFont?

Hi Sandeep,


Thanks for your feedback. We are looking into your requirement and will update you asap. Moreover, as stated above we will appreciated it if you please share your sample code, using above mentioned font related properties. It will help us in implementation of your requirements.

Thanks for your patience and cooperation.

Best Regards,

I am creating PDF document in Generator


Document = new Pdf
{
DefaultFontName = ChartDocument.DefaultFont,
IsCoreFontUsed = false,
IsTruetypeFontMapCached = true,
TruetypeFontMapPath = SomeTempFolder,
};
Pages = new Dictionary<int, List>();

Can you tell me how i can achieve this in New DOM

Regards,
Sandeep

Hi Sandeep,

Thanks for contacting support.

In new Document Object Model, you do not specify the font for whole PDF document, but you can add TextFragments inside PDF file, where you can specify the font for each Fragment. The font is installed over system and can be accessed using Aspose.Pdf.Text.FontRepository.FindFont("TimesNewRoman"); method. Or in case you need to use TrueType or OpenType font placed over system directory (font file, not installed font), please try using Aspose.Pdf.Text.FontRepository.OpenFont(@"E:\fonts\HelveticaNeueLTPro-Lt.otf");.

In order to embed font in resultant document, please try textFragment.TextState.Font.IsEmbedded = true;

[C#]

// Load source PDF document
Aspose.Pdf.Document doc = new Aspose.Pdf.Document();

// Create text fragment
TextFragment textFragment =  new TextFragment("main text");
textFragment.Position =  new Position(100, 600);

// Set text properties
textFragment.TextState.FontSize = 12;
textFragment.TextState.Font = Aspose.Pdf.Text.FontRepository.OpenFont(@"E:\HelveticaNeueLTPro-Lt.otf");
textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray;
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Red;
textFragment.TextState.Font.IsEmbedded = true;

// Create TextBuilder object
TextBuilder textBuilder = new TextBuilder(doc.Pages[1]);

// Append the text fragment to the PDF page
textBuilder.AppendText(textFragment);

// Save updated document containing table object
doc.Save("c:/pdftest/FontEmbedded_test.pdf");

Thanks for your reply.


But my question is not answered. Specifying a default font save me from any point if i have not specified the font. That is the useful property for me.


And what about
IsTruetypeFontMapCached = true,
TruetypeFontMapPath

Properties.

Regards,
Sandeep

Hi Sandeep,


Thanks for your feedback. I am afraid currently new generator does not support the default font setting. As stated above, we have already logged a ticket PDFNEWNET-37501 for the enhancement. We have raised the issue priority and requested our product team to share an ETA at their earliest. We will keep you updated about the issue resolution progress.

Meanwhile you can set font of individual elements as Nayyer suggested above.

We are sorry for the inconvenience caused.

Best Regards,

sgarg@saba.com:
But my question is not answered. Specifying a default font save me from any point if i have not specified the font. That is the useful property for me.


And what about
IsTruetypeFontMapCached = true,
TruetypeFontMapPath
Hi Sandeep,

When using new DOM, you do not have to specify the above properties as we have different approach for specifying the font folder information. Furthermore, using new approach, you get some great features like

The issues you have found earlier (filed as PDFNEWNET-37501) have been fixed in Aspose.Pdf for .NET 10.5.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi,


Sorry to say but i think my queries are not answered. So i would like to know if you can suggest me with some code snippet how my following code should be written in new DOM API.

Document = new Pdf
{
DefaultFontName = DefaultFont,
IsCoreFontUsed = false,
IsTruetypeFontMapCached = true,
TruetypeFontMapPath = TempFolder,
};


Regards,
Sandeep

Hi Sandeep,

Thanks for your patience.

In order to accomplish the earlier requested feature, please try using the DefaultTextState property instead of a set of properties.

C#

TextState textState = new TextState();
textState.Font = FontRepository.FindFont("Arial", FontStyles.Bold);

Document = doc new Document();
doc.PageInfo.DefaultTextState = textState;
page = doc.Pages.Add();

paragraphs.Add(new TextFragment("Some bold arial text"));
doc.Save(outFile);

Thanks for your code snippet.


What we should do for other properties.

We used to generate “Aspose.Pdf.TruetypeFontMap.xml” and point to that using other properties. So do you think it is not required now?

Regards,
Sandeep

Hi Sandeep,


When using legacy Aspose.Pdf.Generator, the Aspose.Pdf.TrueTypeFontMap.xml is used to gather information regarding fonts installed over system. So when pdf.IsTruetypeFontMapCached = true; is called, a file named Aspose.Pdf.TruetypeFontMap.xml is created over the path specified against pdf.TruetypeFontMapPath = “.”; code line.

Now concerning to new DOM approach, there is no need to have such file as the API can automatically locate the fonts installed over system and fonts can be used in PDF file using following simple code lines.

[C#]
//Create text fragment
TextFragment textFragment = new TextFragment(“main text”);
textFragment.Position = new Position(100, 600);

//Set text properties
textFragment.TextState.FontSize = 12;
textFragment.TextState.Font = FontRepository.FindFont(“TimesNewRoman”);
textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray);
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red);