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.

Sun Mar 15, 2015 5:12 pm

I have an image in a cell within a grid.

I want to make the image position central within the cell.

I know how to set the cell paddings for ALL cells within a grid i.e.
Code: Select all
grid.Style.CellPadding = new PdfPaddings(2, 0, 0, 0);


Is it possible to set the padding for an individual cell within a grid? or is there a better way to centralise the image?

dh29
 
Posts: 9
Joined: Mon Mar 02, 2015 9:03 am

Mon Mar 16, 2015 9:45 am

Hello,

Thanks for your inquiry.

Sorry that at present Spire.PDF can’t support the feature sets the padding for an individual cell within a grid. But according to the cell’s weight and height, you can set the padding manually. You can refer to the codes as below:
Code: Select all
   
            PdfDocument doc = new PdfDocument();
            PdfPageBase page = doc.Pages.Add();
            PdfGrid grid = new PdfGrid();
            //set the cell paddings for all cells
            grid.Style.CellPadding = new PdfPaddings(20, 20, 20, 20);
            PdfGridRow row = grid.Rows.Add();
            grid.Columns.Add(3);
            //set an cell's width and height   
            grid.Columns[0].Width = 100;
            grid.Rows[0].Height = 100;
            //insert the image
            PdfGridCellTextAndStyleList lst2 = new PdfGridCellTextAndStyleList();
            PdfGridCellTextAndStyle textAndStyle = new PdfGridCellTextAndStyle();
            textAndStyle = new PdfGridCellTextAndStyle();
            PdfImage image = PdfImage.FromFile(@"F:\download\image1.jpg");
            textAndStyle.Image = image;
            textAndStyle.ImageNewline = true;
            //set the image size wants to be diaplayed
            textAndStyle.ImageSize = new SizeF(60, 60);
            lst2.List.Add(textAndStyle);
            row.Cells[0].Value = lst2;
            grid.Draw(page, new PointF(10, 20));

If there are any questions, welcome to get it back to us.
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Tue Mar 17, 2015 7:55 am

Hello,

Has your issue been resolved? Could you please give us some feedback at your convenience?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Sun Mar 22, 2015 5:31 pm

Thank you for your reply.

I am aware of manually setting cells padding using PdfPaddings(20, 20, 20, 20), however I require different padding for the image cell (which is a merge of 3 row-cells) than for the rest of the table.

From your reply, it looks like this is not possible.

I have solved my problem by re-drawing my image to the correct size to fit my cell.

As part of your reply you show code using PdfGridCellTextAndStyle(). I cannot find any reference to this in the help/documentation. I am using the 'free' version. Am I using an out-of-date help?

dh29
 
Posts: 9
Joined: Mon Mar 02, 2015 9:03 am

Mon Mar 23, 2015 2:24 am

Hello,

There is a PdfGridCellTextAndStyle class in Free Spire.PDF. Please download the latest version( Free Spire.PDF version:3.2) from the following link and have a try:
http://www.e-iceblue.com/Download/downl ... t-now.html
If there are any questions, welcome to get it back to us.

Best Regards,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Tue Mar 24, 2015 9:48 am

Hello,

Has your issue been resolved? Could you please give us some feedback?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Return to Spire.PDF