Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Apr 04, 2022 8:29 am

Hello I'm trying to add two lines of heading but it just looks horrible. Heading1 (first row) is in the middle and Heading2 is positioned normally, but also not at the very beginning of the table.
The two headlines have different length.
I want it to look like this:
headline1
headline2
Table.....


//Create a pdf document.<br>
PdfDocument doc = new PdfDocument();
PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
PdfMargins margin = new PdfMargins();
margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
margin.Bottom = margin.Top;
margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
margin.Right = margin.Left;
// Create new page
PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);
float y = 10;

PdfBrush brush1 = PdfBrushes.Black;
PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Right);
page.Canvas.DrawString("Formular", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
y = y + font1.MeasureString("Formular", format1).Height;
page.Canvas.DrawString("Beurteilungsbogen fuer Arbeitszeugnis", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
y = y + font1.MeasureString("Beurteilungsbogen fuer Arbeitszeugnis", format1).Height;
y = y + 5;

ivster.4
 
Posts: 6
Joined: Thu Mar 31, 2022 10:34 am

Mon Apr 04, 2022 6:08 pm

Hello,

Thanks for your inquiry.

I tested you code but sorry that I'm not sure about your requirements. Which of the pictures below is your desired result? If I misunderstood, please describe your needs in more detail. Thanks in advance.
pic1.png

pic2.png
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Tue Apr 05, 2022 8:51 am

hello the second one is my result, but I want the first one

ivster.4
 
Posts: 6
Joined: Thu Mar 31, 2022 10:34 am

Tue Apr 05, 2022 9:59 am

Hi,

Here is the code for your reference. If you have any other questions, just feel free to contact us.

Code: Select all
            PdfDocument doc = new PdfDocument();
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;
            // Create new page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);
            float y = 10;

            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Left);
            page.Canvas.DrawString("Formular", font1, brush1, 0, y, format1);
            y = y + font1.MeasureString("Formular", format1).Height;

            page.Canvas.DrawString("Beurteilungsbogen fuer Arbeitszeugnis", font1, brush1, 0, y, format1);
            y = y + font1.MeasureString("Beurteilungsbogen fuer Arbeitszeugnis", format1).Height;
            y = y + 5;
            doc.SaveToFile("output.pdf", FileFormat.PDF);
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Return to Spire.PDF