Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3875638
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:17:24+00:00 2026-05-19T22:17:24+00:00

I’m trying to add a horizontal line on top to divide the header text

  • 0

I’m trying to add a horizontal line on top to divide the header text from the actual values in my pdf file:
enter image description here

Here’s my code:

public class StudentList
{
    public void PrintStudentList(int gradeParaleloID)
    {
        StudentRepository repo = new StudentRepository();
        var students = repo.FindAllStudents()
                            .Where(s => s.IDGradeParalelo == gradeParaleloID);

        try
        {
            Document document = new Document(PageSize.LETTER);

            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\Alumnos.pdf", FileMode.Create));
            document.Open();

            PdfContentByte cb = writer.DirectContent;
            cb.SetLineWidth(2.0f);   // Make a bit thicker than 1.0 default
            cb.SetGrayStroke(0.95f); // 1 = black, 0 = white
            cb.MoveTo(20, 30);
            cb.LineTo(400, 30);
            cb.Stroke();

            PdfPTable table = new PdfPTable(3);                
            float[] widths = new float[] { 0.6f, 0.75f, 2f };
            table.SetWidths(widths);
            PdfPCell numeroCell = new PdfPCell(new Phrase("Nro."));
            numeroCell.Border = 0;
            numeroCell.HorizontalAlignment = 0;
            table.AddCell(numeroCell);

            PdfPCell codigoCell = new PdfPCell(new Phrase("RUDE"));
            codigoCell.Border = 0;
            codigoCell.HorizontalAlignment = 0;
            table.AddCell(codigoCell);

            PdfPCell nombreCell = new PdfPCell(new Phrase("Apellidos y Nombres"));
            nombreCell.Border = 0;
            nombreCell.HorizontalAlignment = 0;
            table.AddCell(nombreCell);

            int c = 1;
            foreach (var student in students)
            {
                PdfPCell cell = new PdfPCell(new Phrase(c.ToString()));
                cell.Border = 0;
                cell.HorizontalAlignment = 0;
                table.AddCell(cell);

                cell = new PdfPCell(new Phrase(student.Rude.ToString()));
                cell.Border = 0;
                cell.HorizontalAlignment = 0;
                table.AddCell(cell);

                cell = new PdfPCell(new Phrase(student.LastNameFather + " " + student.LastNameMother + " " + student.Name));
                cell.Border = 0;
                cell.HorizontalAlignment = 0;
                table.AddCell(cell);
                c++;
            }
            table.SpacingBefore = 20f;
            table.SpacingAfter = 30f;

            document.Add(table);
            document.Close();
        }
        catch (DocumentException de)
        {
            Debug.WriteLine(de.Message);
        }
        catch (IOException ioe)
        {
            Debug.WriteLine(ioe.Message);
        }

    }
}

I don’t understand why the cb.Stroke() isn’t working. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:17:25+00:00Added an answer on May 19, 2026 at 10:17 pm

    Drawing with iTextSharp’s PdfContentByte class can be a little confusing. The height is actually relative to the bottom, not the top. So the top of the page is not 0f, but instead is actually document.Top, which on your page size of PageSize.LETTER is 726f. So if you want to draw your line 30 units from the top, try:

    cb.MoveTo(20, document.Top - 30f);
    cb.LineTo(400, document.Top - 30f);
    

    Just curious — why do it the hard way instead of using table borders? (I noticed you set your borders to 0) Trying to space out lines by hand is the biggest pain. If you ever move content in your PDF around, you’ll have to make sure your measurements still work.

    Try this:

    numeroCell.Border = 0;
    numeroCell.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
    numeroCell.BorderWidthBottom = 1f;
    
    codigoCell.Border = 0;
    codigoCell.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
    codigoCell.BorderWidthBottom = 1f;
    
    nombreCell.Border = 0;
    nombreCell.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
    nombreCell.BorderWidthBottom = 1f;
    

    That should give you a nice solid black line under your header row, no measurements needed:

    Table border sample

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a bunch of posts stored in text files formatted in yaml/textile (from
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.