We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Add text in PDF line by line with specific formatting and style using Aspose.PDF for .NET

Hello Group,

My agency uses Aspose. I need to find out if there is a way to use Aspose to format data as it is read line by line from a text file(.txt) and input into a PDF. We use vb.net in a web service and read a .txt file. As each line is read we apply formats to each line such as Font, Line Height, Line Width, Underlining, Margin Indenting, etc… Can the Aspose suite, using what I would assume to be the Aspose.PDF dll, be able to handle this process?

Thank you in advance.

Lee Wheeler

@LeeWheeler

Thanks for contacting support.

Sure, you can add text in PDF document line by line while specifying its formatting. Please check following code snippet in C#.NET which you can use for the purpose and modify it as per your requirement:

Document document = new Document();
document.Pages.Add();
Page page = document.Pages[1];
string[] lines = new[] { "First Line", "Second Line" };
foreach(string line in lines)
{
 TextFragment text = new TextFragment(line);
 text.TextState.Font = FontRepository.FindFont("Arial");
 text.TextState.FontSize = 40;
 text.TextState.FontStyle = FontStyles.Italic;
 page.Paragraphs.Add(text);
}
document.Save(dataDir + "test_out.pdf");

Thank you. Will try it out.