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.

Wed Mar 18, 2015 9:47 pm

I am using Free Spire.PDF

Very oddly, every time I use grid.Draw I am unable to add text or grids to this page. It is not about x/y placement. For example, I may have text up to y-position 30 and create a grid. Then try to render text at 250 and will not see the text (though my grid ends at y position 70).

If I reverse the order, add text at position 250, then create my grid, I will see the grid above the text. Change the order again so that I add the text AFTER grid.Draw, and the text is missing.

I am also able to add text to page 2 after adding a grid to page 1. So, to summarize, as soon as I use grid.Draw, I am unable to add any content to current page. If I add text lower down in the page before using grid.Draw, this will succeed. If I create a new page, I will be able to add content to new page. Here is my code for grid generation


Code: Select all
            PdfGrid grid = new PdfGrid();
            PdfGridRow row;
            PdfLayoutResult result;
            grid.Columns.Add(1);
            grid.Columns[0].Width = page.Canvas.ClientSize.Width - 70;

            PdfBorders noBorder = new PdfBorders();
            noBorder.All = new PdfPen(new PdfTilingBrush(new SizeF(0, 0)), 0);


            foreach (var objective in newResume.objectives)
            {
                row = grid.Rows.Add();
                row.Cells[0].Style.Borders = noBorder;
                text = String.Format("{0} ", objective.description);
                row.Cells[0].Value = text;
            }


            //grid.Style.BorderOverlapStyle = PdfBorderOverlapStyle.Inside;
            //grid.Style.BackgroundBrush = new PdfSolidBrush(Color.FromArgb(220, 220, 220)); //Color.FromArgb(220, 220, 220);
            //grid.Style.CellPadding.All = 20f;
            result = grid.Draw(page, new PointF(30, y));

            y += result.Bounds.Height + 40f;
            // does not render
            text = String.Format("{0} {1} {2}", newResume.contactInfo.firstName, newResume.contactInfo.middleName, newResume.contactInfo.lastName);
            page.Canvas.DrawString(text, nameTrueTypeFont, blueBrush,
                        pageWidth / 2, 250, formatCenter);


            page = doc.Pages.Add(PdfPageSize.A4);
            y = 30;

            // renders
            text = String.Format("{0} {1} {2}", newResume.contactInfo.firstName, newResume.contactInfo.middleName, newResume.contactInfo.lastName);
            page.Canvas.DrawString(text, nameTrueTypeFont, blueBrush,
                        pageWidth / 2, 250, formatCenter);



dalper02
 
Posts: 10
Joined: Tue Mar 17, 2015 7:18 pm

Thu Mar 19, 2015 7:25 am

Hello dalper02,

Thanks for your inquiry.

Actually, all contents are drawn to the page, but they are invisible because you set the wrong cell borders.
Please change this line of code:
Code: Select all
noBorder.All = new PdfPen(new PdfTilingBrush(new SizeF(0, 0)), 0);

to:
Code: Select all
noBorder.All = PdfPens.Transparent;

Then you will get the correct document.
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Thu Mar 19, 2015 3:20 pm

that worked for whitebackground. When table has background a color, I set border color to background color.

dalper02
 
Posts: 10
Joined: Tue Mar 17, 2015 7:18 pm

Fri Mar 20, 2015 10:17 am

Hello,

Yes, you can set the border color to background color, and here is the sample code:
Code: Select all
noBorder.All = PdfPens.Red // Red color
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Return to Spire.PDF