3
Vote

Itextsharp pdfwriter cell width cannot be set.

description

When using the itextsharp plugin setting the reportstyle width fails.
The exception says:"The width cannot be set."
I'm using the Feb 23 changeset.

I try setting the width like this:
report.DataFields["name"].DataStyle = new ReportStyle { Width = 1};
report.DataFields["price"].DataStyle = new ReportStyle { Width = 1 };

The exception occurs on line 266 of itextsharp's pdfreportwriter in CopyStyleToCell.

comments

mhidinger wrote Jul 31, 2012 at 7:30 PM

Thanks for reporting, I've noticed this too. It's coming from iTextSharp and I don't know the root cause. In 1.3 which is about to published I have removed the offending line, which means these PDFs will have automatic widths until a solution is found.

DefconDotNet wrote Apr 12, 2013 at 11:42 AM

fix for this is:
                ...
                PdfPTable table = new PdfPTable(fieldsCount)
                {
                    HeaderRows = 1,
                    WidthPercentage = 100f
                };


                if (fieldsCount > 0)
                    table.SetWidths(report.DataFields
                                        .Where(field => !field.Hidden)
                                        .Select(field => field.DataStyle.Width == 0
                                                            ? (pageSize.Width / fieldsCount) * 2
                                                            : field.DataStyle.Width)
                                        .ToArray());

                PdfPTable pdfPtable = globalTable;
                ...