EXPORTING TO PDF

Dear Sir,

While Exporting to pdf, I have following queries.

a.       PDF page Landscape is not working.

 var document = sfDataGrid1.ExportToPdf(options);

document.PageSettings.Orientation = PdfPageOrientation.Landscape;

b.      How to set PDF Page size and left, right, top, bottom margins ?

c.       Before exporting to Pdf, is selection of Fields possible ? Field Chooser possible ?

d.      How to Change Fonts for export to pdf ?

e. While Exporting to PDF, options.FitAllColumnsInOnePage = true; is given, then all columns shrink to fit page, can we get different results as per below

1. All columns in standard size with fonts and font size, but page width auto increase as per all columns size. So that all columns will fit to one page but page size will increase.

2. All Columns in one page where all columns size remains as per columns size, but font size will adjusted.

Please help me for the above solutions.





9 Replies

FP Farjana Parveen Ayubb Syncfusion Team August 13, 2018 10:35 AM UTC

Hi Deepak, 
 
Thanks for contacting Syncfusion support. 
 
Please find the updated in the below table, 
 
Query 
Response 
a.       PDF page Landscape is not working.  
You can change the page orientation by using PdfGridLayoutFormat.Layout property of exported grid and draw that PdfGrid into a PdfDocument. Please refer the below code example and UG link, 
 
 
Code Example 
void ExportDataGridLandscape(object sender, System.EventArgs e) 
{ 
    var document = new PdfDocument(); 
    document.PageSettings.Orientation = PdfPageOrientation.Landscape; 
    var page = document.Pages.Add(); 
    var PDFGrid = sfDataGrid1.ExportToPdfGrid(sfDataGrid1.View, new PdfExportingOptions()); 
    var format = new PdfGridLayoutFormat() 
    { 
        Layout = PdfLayoutType.Paginate, 
        Break = PdfLayoutBreakType.FitPage 
    }; 
 
    PDFGrid.Draw(page, new PointF(), format); 
    SaveFileDialog saveFileDialog = new SaveFileDialog 
    { 
        Filter = "PDF Files(*.pdf)|*.pdf" 
    }; 
    if (saveFileDialog.ShowDialog() == DialogResult.OK) 
    { 
        using (Stream stream = saveFileDialog.OpenFile()) 
            document.Save(stream); 
        if (MessageBox.Show("Do you want to view the Pdf file?", "Pdf file has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) 
            System.Diagnostics.Process.Start(saveFileDialog.FileName); 
    } 
} 
 
b.      How to set PDF Page size and left, right, top, bottom margins ? 
You can set the Page size and margins for Pdf document by using PdfDocument.PageSettings. Please refer the below code example 
 
Code Example  
private void ExportDataGridPageSize(object sender, EventArgs e) 
{ 
    PdfDocument document = new PdfDocument(); 
    document.PageSettings.Margins.All = 10; 
    document.PageSettings.Size = new SizeF(500, 500); 
    var page = document.Pages.Add(); 
    var PDFGrid = sfDataGrid1.ExportToPdfGrid(sfDataGrid1.View, new PdfExportingOptions()); 
    PDFGrid.Draw(page, new PointF()); 
    SaveFileDialog sfd = new SaveFileDialog 
    { 
        Filter = "PDF Files(*.pdf)|*.pdf", 
        FileName = "document1" 
    }; 
 
    if (sfd.ShowDialog() == DialogResult.OK) 
    { 
        using (Stream stream = sfd.OpenFile()) 
            document.Save(stream); 
 
        if (MessageBox.Show("Do you want to view the workbook?", "Workbook has been created", MessageBoxButtons.OKCancel) == DialogResult.OK) 
            System.Diagnostics.Process.Start(sfd.FileName); 
    } 
} 
 
 
c.       Before exporting to Pdf, is selection of Fields possible ? Field Chooser possible ? 
You can exclude the columns when export the SfDataGrid to Pdf document by adding the columns in PdfExportingOptions.ExcludeColumns collection. Please refer the below code and UG link 
 
Code Example 
 
private void ExportDataGridExcludeColumns(object sender, EventArgs e) 
{ 
    PdfExportingOptions options = new PdfExportingOptions(); 
    options.ExcludeColumns.Add("ProductID"); 
    options.ExcludeColumns.Add("ProductName"); 
 
    var document = sfDataGrid1.ExportToPdf(options); 
    SaveFileDialog saveFileDialog = new SaveFileDialog 
    { 
        Filter = "PDF Files(*.pdf)|*.pdf" 
    }; 
    if (saveFileDialog.ShowDialog() == DialogResult.OK) 
    { 
        using (Stream stream = saveFileDialog.OpenFile()) 
            document.Save(stream); 
        if (MessageBox.Show("Do you want to view the Pdf file?", "Pdf file has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) 
            System.Diagnostics.Process.Start(saveFileDialog.FileName); 
    }  
} 
 
 
d.      How to Change Fonts for export to pdf ?  
You could change the font while exporting the SfDataGrid into Pdf document by using PdfExportingOptions.Exporting event. Please refer the below code example and UG link,  
 
Code Example 
 
private void ExportDataGridFontChages(object sender, EventArgs e) 
{ 
    PdfExportingOptions options = new PdfExportingOptions(); 
    options.Exporting += options_Exporting; 
    var document = sfDataGrid1.ExportToPdf(options); 
    SaveFileDialog saveFileDialog = new SaveFileDialog 
    { 
        Filter = "PDF Files(*.pdf)|*.pdf" 
    }; 
    if (saveFileDialog.ShowDialog() == DialogResult.OK) 
    { 
        using (Stream stream = saveFileDialog.OpenFile()) 
            document.Save(stream); 
        if (MessageBox.Show("Do you want to view the Pdf file?", "Pdf file has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) 
            System.Diagnostics.Process.Start(saveFileDialog.FileName); 
    }  
} 
 
void options_Exporting(object sender, DataGridPdfExportingEventArgs e) 
{ 
    PdfTrueTypeFont font = new PdfTrueTypeFont(new System.Drawing.Font("Algerian", 9f)); 
    e.CellStyle.Font = font; 
} 
 
 
e. While Exporting to PDF, options.FitAllColumnsInOnePage = true; is given, then all columns shrink to fit page, can we get different results as per below 
You can change the exported Pdf document page width by calculating the SfDataGrid.Columns.ActualWidth and set to Pdf document page width, and you can  change the font while exporting the SfDataGrid into Pdf document by using PdfExportingOptions.Exporting event based on your requirement. Please refer the below code example, 
 
Code Example 
private void ExportDataGridFitAllColumns(object sender, EventArgs e) 
{ 
    double width = 0; 
    foreach (var columns in sfDataGrid1.Columns) 
        width += columns.ActualWidth; 
    PdfDocument document = new PdfDocument(); 
    document.PageSettings.Width = (float)width; 
    var pdfOptions = new PdfExportingOptions(); 
    pdfOptions.FitAllColumnsInOnePage = true; 
    pdfOptions.Exporting += pdfOptions_Exporting; 
    var page = document.Pages.Add(); 
    var PDFGrid = sfDataGrid1.ExportToPdfGrid(sfDataGrid1.View, pdfOptions); 
    PDFGrid.Draw(page, new PointF()); 
    SaveFileDialog sfd = new SaveFileDialog 
    { 
        Filter = "PDF Files(*.pdf)|*.pdf", 
        FileName = "document1" 
    }; 
 
    if (sfd.ShowDialog() == DialogResult.OK) 
    { 
        using (Stream stream = sfd.OpenFile()) 
            document.Save(stream); 
 
        if (MessageBox.Show("Do you want to view the workbook?", "Workbook has been created", MessageBoxButtons.OKCancel) == DialogResult.OK) 
            System.Diagnostics.Process.Start(sfd.FileName); 
    } 
} 
 
void pdfOptions_Exporting(object sender, DataGridPdfExportingEventArgs e) 
{ 
    PdfTrueTypeFont font = new PdfTrueTypeFont(new System.Drawing.Font("Segoe UI", 6f)); 
    e.CellStyle.Font = font; 
} 
 
 
 
  
Regards, 
Farjana Parveen A 
 



DE Deepak August 18, 2018 03:26 PM UTC

query : 1

e. While Exporting to PDF, options.FitAllColumnsInOnePage = true; is given, then all columns shrink to fit page but there was no proper result

PFA Three Different Results
1. In first pdf shrink-1.pdf file,

double width = 0;
                foreach (var columns in sfDataGrid1.Columns)
                    width += columns.ActualWidth;
                

pdfOptions.FitAllColumnsInOnePage = false;

2. In Second pdf shrink-2.pdf file,

double width = 0;
                foreach (var columns in sfDataGrid1.Columns)
                    width += columns.ActualWidth;
                 

pdfOptions.FitAllColumnsInOnePage = True;

In first example, after last columns there was extra space which does not required. In Second Example, all columns set fit to page, but columns are equal sized. Where as final requirement is as per column size (As per example 1) column will show, but after the end of the last columns there was only right margin and no other space. Result required as per exmple 3  i.e. pdf shrink-3.pdf

Query : 2
Secondly, for below command
width += columns.ActualWidth;

How Actualwidth is calculating.. in my database first  Id has int(11) value and flag has int(2) value.. but as per said formula it is showing different value. How Actualwidth is calculating. as per pixel size, field value size or any other ?


Attachment: pdf_shrink_33da9e1b.zip


AA Arulraj A Syncfusion Team August 20, 2018 12:27 PM UTC

Hi Deepak, 

Thanks for your update. 

The ActualWidth of the columns in the SfDataGrid is calculated in pixels. You need to convert the value in pixels to points before setting the width of the pdf document page and disable the FitAllColumnsInOnePage property, in order to achieve your requirement. Please refer to the below code example and sample from the given location. 

Code Example: 

double width = 0; 
foreach (var columns in sfDataGrid1.Columns) 
    width += columns.ActualWidth; 
 
PdfDocument document = new PdfDocument(); 
 
Graphics g = this.sfDataGrid1.CreateGraphics(); 
width = (float)width * 72 / g.DpiX; 
g.Dispose(); 
document.PageSettings.Width = (float)width;    
 
 
var pdfOptions = new PdfExportingOptions(); 
pdfOptions.FitAllColumnsInOnePage = false; 
pdfOptions.Exporting += pdfOptions_Exporting; 
var page = document.Pages.Add(); 
var PDFGrid = sfDataGrid1.ExportToPdfGrid(sfDataGrid1.View, pdfOptions); 
PDFGrid.Draw(page, new PointF());          

 
Regards, 
Arulraj A 



DE Deepak September 10, 2018 01:47 PM UTC

Hi,


While Exporting to PDF, Can we get result as per below ?

Example : I have 10 Rows and 12 columns but as per page size (A4 SIZE) In Page I am getting only 3 columns, and next 4 columns in Page no.2 and remaining 5 columns in page No.3

Requirement is :

After adding 3 columns for First Row, next columns (4 columns) will show in next Row instead of Next Page and after that again 5 columns will show in again in next Row instead of Next Page No. 3... In short for one Record it will show in Three Rows,

ACTUAL COLUMNS RECORDS
SR NO. MICR CODE IFSC CODE BANK NAME BRANCH ADDRESS CONTACT NO CITY DISTRICT
1 400065001 ABHY0065001 ABHYUDAYA COOPERATIVE BANK LIMITED RTGS-HO ABHYUDAYA BANK BLDG., B.NO.71, NEHRU NAGAR, KURLA (E), MUMBAI-400024 25260173 MUMBAI GREATER MUMBAI
2 400065002 ABHY0065002 ABHYUDAYA COOPERATIVE BANK LIMITED ABHYUDAYA NAGAR ABHYUDAYA EDUCATION SOCIETY, OPP. BLDG. NO. 18, ABHYUDAYA NAGAR, KALACHOWKY, MUMBAI - 400033 24702643 MUMBAI GREATER MUMBAI
3 400065003 ABHY0065003 ABHYUDAYA COOPERATIVE BANK LIMITED BAIL BAZAR KMSPM'S SCHOOL, WADIA ESTATE, BAIL BAZAR-KURLA(W), MUMBAI-400070 25032202 MUMBAI GREATER MUMBAI
4 400065004 ABHY0065004 ABHYUDAYA COOPERATIVE BANK LIMITED BHANDUP CHETNA APARTMENTS, J.M.ROAD, BHANDUP, MUMBAI-400078 25963157 MUMBAI GREATER MUMBAI
5 400065005 ABHY0065005 ABHYUDAYA COOPERATIVE BANK LIMITED DARUKHANA POTIA IND.ESTATE, REAY ROAD (E), DARUKHANA, MUMBAI-400010 23778164 MUMBAI GREATER MUMBAI
6 400065006 ABHY0065006 ABHYUDAYA COOPERATIVE BANK LIMITED FORT ABHYUDAYA BANK BLDG., 251, PERIN NARIMAN STREET, FORT, MUMBAI-400001 22614468 MUMBAI GREATER MUMBAI
7 400065007 ABHY0065007 ABHYUDAYA COOPERATIVE BANK LIMITED GHATKOPAR UNIT NO 2 & 3, SILVER HARMONY BLDG,NEW MANIKLAL ESTATE, GHATKOPAR (WEST), MUMBAI-400086 25116673 MUMBAI GREATER MUMBAI
8 400065008 ABHY0065008 ABHYUDAYA COOPERATIVE BANK LIMITED KANJUR BHANDARI CO-OP. HSG. SOCIETY, KANJUR VILLAGE, KANJUR (EAST), MUMBAI-400078 25783519 MUMBAI GREATER MUMBAI
9 400065009 ABHY0065009 ABHYUDAYA COOPERATIVE BANK LIMITED NEHRU NAGAR ABHYUDAYA BANK BLDG., B.NO.71, NEHRU NAGAR, KURLA (E), MUMBAI-400024 25222386 MUMBAI GREATER MUMBAI
10 400065010 ABHY0065010 ABHYUDAYA COOPERATIVE BANK LIMITED PAREL SHRAMA SAFALYA, 63 G.D.AMBEKAR MARG, PAREL VILLAGE, MUMBAI-400012 24137707 MUMBAI GREATER MUMBAI
11 400065011 ABHY0065011 ABHYUDAYA COOPERATIVE BANK LIMITED SEWRI NAVNIDHI INDUSTRIAL ESTATE, ACHARYA DONDHE MARG, SEWRI, MUMBAI-400015 24136008 MUMBAI GREATER MUMBAI
12 400065012 ABHY0065012 ABHYUDAYA COOPERATIVE BANK LIMITED WADALA B.P.T.MARKET BLDG., NADKARNI PARK, WADALA (EAST), MUMBAI-400037 24184512 MUMBAI GREATER MUMBAI
13 400065013 ABHY0065013 ABHYUDAYA COOPERATIVE BANK LIMITED WORLI LANDMARK,NEXT TO MAHINDRA TOWERS, PLOT NO.1, J M BHOSLE MARG, WORLI, MUMBAI-400018 24921104 MUMBAI GREATER MUMBAI
14 400065014 ABHY0065014 ABHYUDAYA COOPERATIVE BANK LIMITED MUMBRA RIZVI APARTMENTS, OPP. RAILWAY STATION, MUMBRA-400612 25462172 MUMBAI GREATER MUMBAI
15 400065015 ABHY0065015 ABHYUDAYA COOPERATIVE BANK LIMITED TURBHE A.P.M.C.MARKET, ADMINISTRATIVE BLDG, TURBHE, NAVI MUMBAI-400705 27888044 MUMBAI GREATER MUMBAI
16 400065016 ABHY0065016 ABHYUDAYA COOPERATIVE BANK LIMITED VASHI ABHYUDAYA BANK BLDG., SECTOR 17, VASHI, NAVI MUMBAI-400705 27892458 MUMBAI GREATER MUMBAI
17 400065017 ABHY0065017 ABHYUDAYA COOPERATIVE BANK LIMITED MOBILE BANK ABHYUDAYA BANK BLDG., SECTOR 17, VASHI, NAVI MUMBAI-400703 27892444 MUMBAI GREATER MUMBAI
18 400065018 ABHY0065018 ABHYUDAYA COOPERATIVE BANK LIMITED NEW PANVEL ABHYUDAYA BANK BLDG., SECTOR 17, NEW PANVEL-410206 27453585 MUMBAI GREATER MUMBAI
19 400065019 ABHY0065019 ABHYUDAYA COOPERATIVE BANK LIMITED KALAMBOLI BLDG F-4, SHOP NO 17-20, SECTOR 3 EB, KALAMBOLI, NAVI MUMBAI-410218 27420148 MUMBAI GREATER MUMBAI
20 400065020 ABHY0065020 ABHYUDAYA COOPERATIVE BANK LIMITED DHARAVI WESTERN INDIA TANNERIES, SION DHARAVI ROAD, MUMBAI-400017 24077126 MUMBAI GREATER MUMBAI
21 400065021 ABHY0065021 ABHYUDAYA COOPERATIVE BANK LIMITED MALAD EAST 148 ELLORA SHOPPING CENTRE, DAFTARY ROAD, MALAD (EAST), MUMBAI-400097 28800272 MUMBAI GREATER MUMBAI
22 400065022 ABHY0065022 ABHYUDAYA COOPERATIVE BANK LIMITED CBD BELAPUR SECTOR-3, CHANAKYA SHOPPING CENTRE, BELAPUR (CBD), NAVI MUMBAI-400614 27572179 MUMBAI GREATER MUMBAI
23 400065023 ABHY0065023 ABHYUDAYA COOPERATIVE BANK LIMITED BHIWANDI BLDG F-1,GOPAL NAGAR,BHIWANDI-KALYAN ROAD, BHIWANDI, 421302 251852 MUMBAI GREATER MUMBAI
24 400065024 ABHY0065024 ABHYUDAYA COOPERATIVE BANK LIMITED BORIVALI RATNADEEP APARTMENTS, CARTER ROAD NO.1, BORIVLI (EAST), MUMBAI-400066 28636529 MUMBAI GREATER MUMBAI
25 400065025 ABHY0065025 ABHYUDAYA COOPERATIVE BANK LIMITED HILL ROAD HILL-N-DALE, HILL ROAD, NR.BANDRA POLICE STATION, BANDRA (W), MUMBAI-400050 26402597 MUMBAI GREATER MUMBAI
26 400065026 ABHY0065026 ABHYUDAYA COOPERATIVE BANK LIMITED KHER NAGAR JANATA EDUCATION SOC. PREMISES, KHER NAGAR, BANDRA (E), MUMBAI-400051 26473470 MUMBAI GREATER MUMBAI
27 400065027 ABHY0065027 ABHYUDAYA COOPERATIVE BANK LIMITED KANDIVLI-EAST GUNDECHA INDL.COMPLEX, AKURLI RD, KANDIVLI (E), MUMBAI-400101 28851962 MUMBAI GREATER MUMBAI
28 400065028 ABHY0065028 ABHYUDAYA COOPERATIVE BANK LIMITED SHERLY RAJAN KHAIR HOUSE, SHERLY RAJAN RD, BANDRA (WEST), MUMBAI-400050 26047905 MUMBAI GREATER MUMBAI

REQUIREMENTS RESULT :
SR NO. MICR CODE IFSC CODE BANK NAME BRANCH
  ADDRESS
  CONTACT NO CITY DISTRICT  
1 400065001 ABHY0065001 ABHYUDAYA COOPERATIVE BANK LIMITED RTGS-HO
  ABHYUDAYA BANK BLDG., B.NO.71, NEHRU NAGAR, KURLA (E), MUMBAI-400024
  25260173 MUMBAI GREATER MUMBAI  
2 400065002 ABHY0065002 ABHYUDAYA COOPERATIVE BANK LIMITED ABHYUDAYA NAGAR
  ABHYUDAYA EDUCATION SOCIETY, OPP. BLDG. NO. 18, ABHYUDAYA NAGAR, KALACHOWKY, MUMBAI - 400033
  24702643 MUMBAI GREATER MUMBAI  
3 400065003 ABHY0065003 ABHYUDAYA COOPERATIVE BANK LIMITED BAIL BAZAR
  KMSPM'S SCHOOL, WADIA ESTATE, BAIL BAZAR-KURLA(W), MUMBAI-400070
  25032202 MUMBAI GREATER MUMBAI  
4 400065004 ABHY0065004 ABHYUDAYA COOPERATIVE BANK LIMITED BHANDUP
  CHETNA APARTMENTS, J.M.ROAD, BHANDUP, MUMBAI-400078  
  25963157 MUMBAI GREATER MUMBAI  

    



MA Mohanram Anbukkarasu Syncfusion Team September 12, 2018 01:03 PM UTC

Hi Deepak, 

Thanks for your update. 

Currently we don’t have direct support to achieve your requirement. The exported grid will be same as the SfDataGrid. It also cannot achieved by any workaround which requires manual drawing of each cells and also have certain limitations. We have created a workaround sample of PDfGrid for your reference. 
In the sample we have manually drawn the each and individual cell in the page. This workaround has certain limitation the nested grid will not work. 
Please find the following sample for your reference. 

Regards, 
Mohanram A. 



DE Deepak replied to Arulraj A December 28, 2018 03:42 PM UTC

Hi Deepak, 

Thanks for your update. 

The ActualWidth of the columns in the SfDataGrid is calculated in pixels. You need to convert the value in pixels to points before setting the width of the pdf document page and disable the FitAllColumnsInOnePage property, in order to achieve your requirement. Please refer to the below code example and sample from the given location. 

Code Example: 

double width = 0; 
foreach (var columns in sfDataGrid1.Columns) 
    width += columns.ActualWidth; 
 
PdfDocument document = new PdfDocument(); 
 
Graphics g = this.sfDataGrid1.CreateGraphics(); 
width = (float)width * 72 / g.DpiX; 
g.Dispose(); 
document.PageSettings.Width = (float)width;    
 
 
var pdfOptions = new PdfExportingOptions(); 
pdfOptions.FitAllColumnsInOnePage = false; 
pdfOptions.Exporting += pdfOptions_Exporting; 
var page = document.Pages.Add(); 
var PDFGrid = sfDataGrid1.ExportToPdfGrid(sfDataGrid1.View, pdfOptions); 
PDFGrid.Draw(page, new PointF());          

 
Regards, 
Arulraj A 


After using this commands, where my columns are not fixed, ex. First time selected all columns, then trying to removing some columns etc.. and on the same page trying to export... the same but right side margin change every time. in your sample, please give option for Column Chooser and hidden columns remove from export in pdf and try the same you will get the different result.


MA Mohanram Anbukkarasu Syncfusion Team January 2, 2019 01:00 PM UTC

Hi Deepak,  
 
Thanks for your update. 
 
We can able to reproduce the reported scenario in our end. To achieve your requirement you have to calculate the width for the page from the PdfGrid.Columns instead of calculating it from the SfDataGrid.Columns. Please refer the following code example and sample from the given link. 
 
Code Example :  
 
var pdfOptions = new PdfExportingOptions(); 
 
foreach (var column in sfDataGrid1.Columns) 
{ 
    if (!column.Visible) 
        pdfOptions.ExcludeColumns.Add(column.MappingName); 
} 
 
pdfOptions.FitAllColumnsInOnePage = false; 
pdfOptions.Exporting += pdfOptions_Exporting; 
PdfDocument document = new PdfDocument(); 
var pdfGrid = new PdfGrid(); 
pdfGrid.AllowRowBreakAcrossPages = false; 
pdfGrid = sfDataGrid1.ExportToPdfGrid(sfDataGrid1.View, pdfOptions); 
 
var padding = 100; 
var width = (float)Syncfusion.WinForms.Core.Utils.ReflectionHelper.GetProperty(pdfGrid.Columns.GetType(), "Width").GetValue(pdfGrid.Columns) + padding; 
document.PageSettings.Width = width; 
var page = document.Pages.Add(); 
pdfGrid.Draw(page, new PointF()); 
 
 
Regards, 
Mohanram A. 



JI Jignesh replied to Mohanram Anbukkarasu January 5, 2019 01:01 PM UTC

Hi Deepak,  
 
Thanks for your update. 
 
We can able to reproduce the reported scenario in our end. To achieve your requirement you have to calculate the width for the page from the PdfGrid.Columns instead of calculating it from the SfDataGrid.Columns. Please refer the following code example and sample from the given link. 
 
Code Example :  
 
var pdfOptions = new PdfExportingOptions(); 
 
foreach (var column in sfDataGrid1.Columns) 
{ 
    if (!column.Visible) 
        pdfOptions.ExcludeColumns.Add(column.MappingName); 
} 
 
pdfOptions.FitAllColumnsInOnePage = false; 
pdfOptions.Exporting += pdfOptions_Exporting; 
PdfDocument document = new PdfDocument(); 
var pdfGrid = new PdfGrid(); 
pdfGrid.AllowRowBreakAcrossPages = false; 
pdfGrid = sfDataGrid1.ExportToPdfGrid(sfDataGrid1.View, pdfOptions); 
 
var padding = 100; 
var width = (float)Syncfusion.WinForms.Core.Utils.ReflectionHelper.GetProperty(pdfGrid.Columns.GetType(), "Width").GetValue(pdfGrid.Columns) + padding; 
document.PageSettings.Width = width; 
var page = document.Pages.Add(); 
pdfGrid.Draw(page, new PointF()); 
 
 
Regards, 
Mohanram A. 


var padding = 100; 
var width = (float)Syncfusion.WinForms.Core.Utils.ReflectionHelper.GetProperty(pdfGrid.Columns.GetType(), "Width").GetValue(pdfGrid.Columns) + padding;

Error    1    No overload for method 'GetValue' takes 1 arguments   

Above error occurs on using the highlighted command, this is checked with framework 4.6, VS 2012 and DLL(Syncfusion.Pdf.Base) version:16.4460.042
Secondly the above command doesn't works on framework 4.0, VS 2012 and DLL(Syncfusion.Pdf.Base) version:16.4400.042

Please check and update, our working environment is framework 4.0, VS 2012/VS 2010


JN Jayaleshwari N Syncfusion Team January 7, 2019 12:15 PM UTC

Hi Deepak, 

Thanks for your update. 

We regret for the inconvenience. Please make use of the following code snippet and sample with framework 4.0 from the given link. 

document.PageSettings.SetMargins(10); 
var width = (float)Syncfusion.WinForms.Core.Utils.ReflectionHelper.GetProperty(pdfGrid.Columns.GetType(), "Width").GetValue(pdfGrid.Columns, null); 
 
// Add the PdfBorder default right width to the total width of page 
document.PageSettings.Width = width + PdfBorders.Default.Right.Width / 2; 
document.PageSettings.Width += document.PageSettings.Margins.Left + document.PageSettings.Margins.Right; 
 
We have attached the modifed sample for your reference and you can download the same from the following location. 

Please let us know if the given solution doesn’t meet your requirement. 

Regards, 
Jayaleshwari N 


Loader.
Up arrow icon