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

Free Support Forum - aspose.com

PageInfo styles after processParagraphs()

Dear all.


I’m using Aspose Pdf for .NET to create a new Pdf files.

For that i’m defining some general styles. Some of them i loose on the second page for the textfragments which doesn’t fit in the first page:

Document pdfDocument = new Document();

pdfDocument.PageInfo.Margin.Top = 72;
pdfDocument.PageInfo.Margin.Right = 30;
pdfDocument.PageInfo.Margin.Bottom = 72;
pdfDocument.PageInfo.Margin.Left = 40;
pdfDocument.PageInfo.DefaultTextState.Font = FontRepository.FindFont(“Arial”);
pdfDocument.PageInfo.DefaultTextState.FontSize = 14.0F;
pdfDocument.PageInfo.DefaultTextState.FontStyle = FontStyles.Italic;
pdfDocument.PageInfo.DefaultTextState.ForegroundColor = Color.DarkBlue;

Page page = pdfDocument.Pages.Add();

for (int i = 0; i < 150; i++)
page.Paragraphs.Add(new TextFragment(“Lorem ipsum dolor sit amet, consectetur, adipisci velit…”));

pdfDocument.ProcessParagraphs();

What can I do to add the same options in the second page, which has been created automatically?

Thanks in advance.

Hi David,


Thanks for contacting support.

In order to get the same style of text on every page you need to specify the TextState at TextFragment level. Please check the following code snippet which I have used to achieve the requirement. I have also attached the output document generated by below code for your reference.

Document pdfDocument = new Document();<o:p></o:p>

pdfDocument.PageInfo.Margin.Top = 72;

pdfDocument.PageInfo.Margin.Right = 30;

pdfDocument.PageInfo.Margin.Bottom = 72;

pdfDocument.PageInfo.Margin.Left = 40;

Page page = pdfDocument.Pages.Add();

for (int i = 0; i < 150; i++)

{

TextFragment frag = new TextFragment("Lorem ipsum dolor sit amet, consectetur, adipisci velit..");

frag.TextState.Font = FontRepository.FindFont("Arial");

frag.TextState.FontSize = 14.0F;

frag.TextState.FontStyle = FontStyles.Italic;

frag.TextState.ForegroundColor = Color.DarkBlue;

page.Paragraphs.Add(frag);

}

pdfDocument.Save(dataDir + "DifferentStyles.pdf");


In case of any further assistance please feel free to contact us.


Best Regards,

Hi again


Thank you very much for your quick answer…

So there is no way to add the document Pageinfo styles automatically, right? I’m asking because I have seen, that the margin styles are taken over to the automatically generated page.

I wanna try to avoid the option to style every TextFragment one by one by adding general document styles.

Thank you in advance

Best regards
David Peier

Hi David,


Thanks for your feedback.

In order to apply different styles on the text you need to define it on text level objects (e.g TextFragment, TextSegment). You cannot define text styles at document level as if a Text Object is causing new pages to add in the document the formatting/styles will not be preserved for newly added pages. That is why you need to set the properties at text level. In case of further assistance please feel free to contact us. We are sorry for the inconvenience faced.


Best Regards,

Thank you very much for the explanation…