Table cuts off text of right most column

Document document = new Document();
        Page page = document.Pages.Add();

        var table = new Table
        {
            DefaultColumnWidth = "52",
            Top = 20,
            Left = 30,
            Border = new BorderInfo(BorderSide.Box, 1f, Color.Black),
            DefaultCellBorder = new BorderInfo(BorderSide.Box, 0.5f, Color.Black),
            DefaultCellPadding = new MarginInfo(4.5, 4.5, 4.5, 4.5),
            Margin =
            {
                Bottom = 2
            },
            DefaultCellTextState =
            {
                Font =  FontRepository.FindFont("Arial")
            }
        };


        var headerRow = table.Rows.Add();
        headerRow.Cells.Add("BATCH RECORD", new TextState() { FontStyle = FontStyles.Bold, FontSize = 14 });
        foreach (Cell cell in headerRow.Cells)
        {
            cell.BackgroundColor = Color.White;
            cell.Alignment = HorizontalAlignment.Center;
            cell.ColSpan = 10;
        }

        var filmArrayRow = table.Rows.Add();
        filmArrayRow.Cells.Add("F", new TextState(){ FontStyle = FontStyles.Bold, FontSize = 14});
        filmArrayRow.Cells[0].ColSpan = 10;
        filmArrayRow.Cells[0].IsNoBorder = false;
        filmArrayRow.Cells[0].BackgroundColor = Color.Yellow;
        filmArrayRow.Cells[0].Alignment = HorizontalAlignment.Center;
        filmArrayRow.Cells[0].Margin = new MarginInfo(0, 1, 0, 1);

        var dateOfQc = table.Rows.Add();
        dateOfQc.Cells.Add("Date Of QC:");
        dateOfQc.Cells[0].ColSpan = 2;
        dateOfQc.Cells[0].IsNoBorder = true;
        dateOfQc.Cells[0].BackgroundColor = Color.White;
        dateOfQc.Cells[0].Alignment = HorizontalAlignment.Center;
        dateOfQc.Cells.Add();
        dateOfQc.Cells[1].ColSpan = 6;
        dateOfQc.Cells[1].IsNoBorder = false;
        dateOfQc.Cells[1].Alignment = HorizontalAlignment.Center;

        AddWhiteSpace(table);

        var sampleTableHeader = table.Rows.Add();
        sampleTableHeader.Cells.Add("Reagant/Supply", new TextState() { FontStyle = FontStyles.Bold, FontSize = 10 });
        sampleTableHeader.Cells.Add("Part Number", new TextState() { FontStyle = FontStyles.Bold, FontSize = 10 });
        sampleTableHeader.Cells.Add("Lot Number", new TextState() { FontStyle = FontStyles.Bold, FontSize = 10 });
        sampleTableHeader.Cells[0].ColSpan = 4;
        sampleTableHeader.Cells[1].ColSpan = 2;
        sampleTableHeader.Cells[2].ColSpan = 2;
        foreach (var cell in sampleTableHeader.Cells)
        {
            cell.BackgroundColor = Color.LightGray;
            cell.Margin = new MarginInfo(0, 1, 0, 1);
            cell.Alignment = HorizontalAlignment.Center;
        }

        var sampleFaiv = table.Rows.Add();
        sampleFaiv.Cells.Add("S");
        sampleFaiv.Cells.Add("F");
        sampleFaiv.Cells.Add("ADFSADF");
        sampleFaiv.Cells[0].ColSpan = 4;
        sampleFaiv.Cells[1].ColSpan = 2;
        sampleFaiv.Cells[2].ColSpan = 2;
        sampleFaiv.Cells[1].Alignment = HorizontalAlignment.Center;
        sampleFaiv.Cells[2].Alignment = HorizontalAlignment.Center;
        foreach (var cell in sampleFaiv.Cells)
        {
            cell.Margin = new MarginInfo(0, 1, 0, 1);
        }


        var sampleAmp = table.Rows.Add();
        sampleAmp.Cells.Add("S");
        sampleAmp.Cells.Add("F");
        sampleAmp.Cells.Add("ADFSADF");
        sampleAmp.Cells[0].ColSpan = 4;
        sampleAmp.Cells[1].ColSpan = 2;
        sampleAmp.Cells[2].ColSpan = 2;
        sampleAmp.Cells[1].Alignment = HorizontalAlignment.Center;
        sampleAmp.Cells[2].Alignment = HorizontalAlignment.Center;
        foreach (var cell in sampleAmp.Cells)
        {
            cell.Margin = new MarginInfo(0, 1, 0, 1);
        }


        var pooledSamples = table.Rows.Add();
        pooledSamples.Cells.Add("1.5mL Swab Pooled Samples");
        pooledSamples.Cells.Add("NA");
        pooledSamples.Cells.Add("NA");
        pooledSamples.Cells[0].ColSpan = 4;
        pooledSamples.Cells[1].ColSpan = 2;
        pooledSamples.Cells[2].ColSpan = 2;
        pooledSamples.Cells[1].Alignment = HorizontalAlignment.Center;
        pooledSamples.Cells[2].Alignment = HorizontalAlignment.Center;
        foreach (var cell in pooledSamples.Cells)
        {
            cell.Margin = new MarginInfo(0, 1, 0, 1);
        }

        AddWhiteSpace(table);

        var pouchTableHeader = table.Rows.Add();
        pouchTableHeader.Cells.Add("Pouch Barcode", new TextState() { FontStyle = FontStyles.Bold, FontSize = 12 });
        pouchTableHeader.Cells.Add("Pooled Swab Barcode", new TextState() { FontStyle = FontStyles.Bold, FontSize = 12 });
        pouchTableHeader.Cells.Add("Pouch Type", new TextState() { FontStyle = FontStyles.Bold, FontSize = 12 });
        pouchTableHeader.Cells.Add("Pouch S/N", new TextState() { FontStyle = FontStyles.Bold, FontSize = 12 });
        pouchTableHeader.Cells.Add("Swab Event", new TextState() { FontStyle = FontStyles.Bold, FontSize = 12 });
        foreach (var cell in pouchTableHeader.Cells)
        {
            cell.BackgroundColor = Color.LightGray;
            cell.Alignment = HorizontalAlignment.Center;
            cell.ColSpan = 2;
            cell.Margin = new MarginInfo(0, 1, 0, 1);
        }

        for (int i = 0; i < 8; i++)
        {
            var x = table.Rows.Add();
            x.DefaultCellPadding = new MarginInfo(0, 0, 0, 0);
            x.Cells.Add("Pouch Barcode");
            x.Cells.Add("Pooled Swab Barcode");
            x.Cells.Add("Pouch Type");
            x.Cells.Add("Pouch S/N");
            x.Cells.Add("Swab Event");
            for (int j = 0; j < 5; j++)
            {
                x.Cells[j].DefaultCellTextState = new TextState(fontSize: 10);
                x.Cells[j].Alignment = HorizontalAlignment.Center;
                x.Cells[j].ColSpan = 2;
            }
        }

        

        AddWhiteSpace(table);


        var initialDate = table.Rows.Add();
        initialDate.Cells.Add();
        initialDate.Cells.Add("Initial/Date");
        initialDate.Cells.Add();
        initialDate.Cells[0].ColSpan = 5;
        initialDate.Cells[1].ColSpan = 2;
        initialDate.Cells[2].ColSpan = 3;
        initialDate.Cells[0].IsNoBorder = true;

        AddWhiteSpace(table);

        var completed = table.Rows.Add();
        completed.Cells.Add();
        completed.Cells.Add("QC Completed By");
        completed.Cells.Add();
        completed.Cells.Add("Date");
        completed.Cells.Add();
        completed.Cells[0].ColSpan = 1;
        completed.Cells[1].ColSpan = 2;
        completed.Cells[2].ColSpan = 3;
        completed.Cells[3].ColSpan = 1;
        completed.Cells[4].ColSpan = 2;
        completed.Cells[0].IsNoBorder = true;


        page.Paragraphs.Add(table);

        return document;

@tyrusdraper

Would you please share the PDF file generated at your end using this code snippet? We will compare it with the one generated at our end and share our findings with you.

Screenshot (240).png (71.5 KB)

Area_ARRAY LINES 20-25 _Batch_Record (3).pdf (167.5 KB)

Here’s a screenshot and the file generated.

You can see the rightmost column labeled “Swab Event” is cutoff and all centered text shifts to the left, away from the middle.

@tyrusdraper

You need to consider the default margins of the page as well while generating the PDF. API adds 72 point of margin by default if you do not specify them. Please try to add the margins of PDF Page as per your table width so that it could fit properly within page boundaries. We obtained attached PDF after adding below line:

Document document = new Document();
Page page = document.Pages.Add();
page.PageInfo.Margin = new MarginInfo(0, 0, 0, 0); // Added this line

current.pdf (165.7 KB)

1 Like

Ah, I see. This is great. Thank you for your help and timely responses.

1 Like

@tyrusdraper

Thanks for your feedback. Please keep using our API and feel free to create a new topic in case you need further assistance.

1 Like