PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Migradoc header with multiple lines and styles
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1808
Page 1 of 1

Author:  alimnios72 [ Thu Oct 06, 2011 7:04 pm ]
Post subject:  Migradoc header with multiple lines and styles

Hi,

I'm new to Migradoc and PDFSharp and I want to have a header containing multiple lines and styles. I coded this way:

Code:
  Document documento = new Document();
           documento.Info.Title = "Caratula del Contrato";

            Style style = documento.Styles["Normal"];
            style.Font.Name = "Verdana";

            Section section = documento.AddSection();
            section.PageSetup.TopMargin = Unit.FromCentimeter(3);

            //Header
            Paragraph header = section.Headers.Primary.AddParagraph();
            header.AddText(this.recaI);
            header.AddLineBreak();
            header.AddText("CreaBienestar");
            header.AddLineBreak();
            style = documento.Styles.AddStyle("Header1", "Normal");
            style.Font.Name = "Elegance";
            style.Font.Size = 9;
            header.AddFormattedText("CREA BIENESTAR, S.A. de C.V., SOFOM, E.N.R.", "Header1");
            header.AddLineBreak();
            header.AddText("Crédito y Bienestar para tu familia");
            header.Format.Alignment = ParagraphAlignment.Right;


My header must have 4 lines with different style each line, I'm adding linebreaks in my code to make this happen. However my problem is with the styles.
In My code I try to add a style to line 3 but my document is not rendered. If AddText method it is used in line 3 my document is rendered fine, but no styles are added. Do you know what I'm doing wrong?

Author:  alimnios72 [ Thu Oct 06, 2011 7:09 pm ]
Post subject:  Re: Migradoc header with multiple lines and styles

I think is a problem with supported fonts, so how do I know which fonts are supported?

regards

Author:  Thomas Hoevel [ Mon Oct 10, 2011 8:20 am ]
Post subject:  Re: Migradoc header with multiple lines and styles

Hi!
alimnios72 wrote:
In My code I try to add a style to line 3 but my document is not rendered.
What does that mean? Do you get an error message or an exception? An empty document?

Styles normally are paragraph styles (one style per paragraph). I'd use one paragraph per line, so styles will be no problem. You try to use one paragraph with four lines and try to assign a different style to the third line. I'm not sure which limitations apply to that setup.

The code I'd try would look like this:
Code:
Paragraph header = section.Headers.Primary.AddParagraph("First line");
header = section.Headers.Primary.AddParagraph("Second line");
header = section.Headers.Primary.AddParagraph("Third line");
header.Style = "HeaderSpecialStyle";
header = section.Headers.Primary.AddParagraph("Fourth line");

Author:  alimnios72 [ Wed Oct 12, 2011 10:33 pm ]
Post subject:  Re: Migradoc header with multiple lines and styles

Thanks Thomas, I tried changing the font family and that worked out. I noticed that the issue here is that the font chosen is not supported. For some reason I wasn't getting any exception, but my document was not rendered. How do I know which fonts are supported?

Author:  Thomas Hoevel [ Thu Oct 13, 2011 7:19 am ]
Post subject:  Re: Migradoc header with multiple lines and styles

Look here (or see FAQ)):
http://www.pdfsharp.net/wiki/PostScript_fonts.ashx

Author:  alimnios72 [ Mon Oct 17, 2011 10:22 pm ]
Post subject:  Re: Migradoc header with multiple lines and styles

Thanks Thomas

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/