Hi
Hi Sandeep,
Hi Sandeep,
Aspose.Pdf.Generator supports the feature to create PDF files from scratch and in order to get the string width, the PDF file first needs to be saved over the system. Now concerning to your requirement, you may consider using following code snippet where you can use textFragment.Text.Length
to get the width of TextFragment
.
//open document
Document pdfDocument = new Document();
//get particular page
Page pdfPage = (Page)pdfDocument.Pages.Add();
//create text fragment
TextFragment textFragment = new TextFragment("main text");
textFragment.Position = new Position(100, 600);
Console.WriteLine(textFragment.Text.Length);
// create TextBuilder object
TextBuilder textBuilder = new TextBuilder(pdfPage);
// append the text fragment to the PDF page
textBuilder.AppendText(textFragment);
//save document
pdfDocument.Save("c:/pdftest/TextSegment_output.pdf");
Hi,
Hi Sandeep,
We already have logged a requirement in our issue tracking system to support similar features in a DOM approach. However, you may consider getting rectangular regions/coordinates for a particular text fragment. Please take a look at the following code snippet and see if it can accomplish your requirement.
[C#]
// open document
Document pdfDocument = new Document();
// get particular page
Page pdfPage = (Page)pdfDocument.Pages.Add();
// create text fragment
TextFragment textFragment = new TextFragment("main text");
textFragment.Position = new
Position(100, 600);
Console.WriteLine("Rectangular Region of String = " + textFragment.Rectangle.Width);
textFragment.TextState.FontSize = 14;
Console.WriteLine("Rectangular Region of String = " + textFragment.Rectangle.Width);
// create TextBuilder object
TextBuilder textBuilder = new TextBuilder(pdfPage);
// append the text fragment to the PDF page
textBuilder.AppendText(textFragment);
// save document
pdfDocument.Save("c:/pdftest/TextSegment_output.pdf");
PS, when multiplying FontSize with character count in String, the value is different.
The issues you have found earlier (filed as PDFNEWNET-36575) have been fixed in Aspose.Pdf for .NET 9.2.0.
The blog post for this release is created over this link
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Can you please provide example for this.
Hi Sandeep,
As per post 543029 this function is included in new release. So just want to check what that function is and details around that.
Hi Sandeep,