After giving this commands, followings pdf functions are not working
1.Page size, page orientation is not working
2. Margins not working
3. Export to PDF, how can change the boarder of the box.. currently its gray color with dotted lines which want to change to black color thin line.
4. If Any column in sfdatagrid resized to zero/hide, how can the same column exclude to pdf export ?
Please reply me at the earliest.
commands :
PdfExportingOptions options = new PdfExportingOptions();
//var page = document.Pages.Add();options.AutoColumnWidth = true;
options.AutoRowHeight = true;
options.RepeatHeaders = true;
options.ExportFormat = true;
options.FitAllColumnsInOnePage = true;
foreach (var column in this.sfDataGrid1.Columns)
{
if (column.Width != 0)
column.Width = 0;
//options.ExcludeColumns.Add("CustomerID");
}
this.sfDataGrid1.AutoSizeController.ResetAutoSizeWidthForAllColumns();
//this.sfDataGrid1.AutoSizeController.Refresh();
var document = sfDataGrid1.ExportToPdf(options);
//Set document information.
document.PageSettings.Size = PdfPageSize.A3;
document.PageSettings.Orientation = PdfPageOrientation.Landscape;
document.PageSettings.Margins.Left = 20;
document.PageSettings.Margins.Right = 20;
document.PageSettings.Margins.Top = 100;
document.PageSettings.Margins.Bottom = 20;
document.PageSettings.Orientation = PdfPageOrientation.Landscape;
//document information ... this is working fine
document.DocumentInformation.Author = "TESTING INDIA ";
document.DocumentInformation.CreationDate = DateTime.Now;
document.DocumentInformation.Creator = "SAMPLE TESTING";
document.DocumentInformation.Keywords = "PDF";
document.DocumentInformation.Subject = "Document information DEMO";
document.DocumentInformation.Title = "Essential PDF Sample";
var PDFGrid = sfDataGrid1.ExportToPdfGrid(sfDataGrid1.View, options);
/*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);
}
//Message box confirmation to view the created Pdf file.
if (MessageBox.Show("Do you want to view the Pdf file?", "Pdf file has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
//Launching the Pdf file using the default Application.
System.Diagnostics.Process.Start(saveFileDialog.FileName);
}
}
|
Query |
Response | |
|
1.Page size, page orientation is not working |
You can change the page orientation by get the exported PdfGrid by using ExportToPdfGrid method and then draw that PdfGrid into a PdfDocument by changing the PageSettings.Orientation property of PdfDocument.
You can able to set the Page size Pdf document when exporting. Please refer the below code example
Code Example
| |
|
2. Margins not working |
You can set the margin for exported pdf document, please refer the below code example,
Code Example
| |
|
3. Export to PDF, how can change the boarder of the box.. currently its gray color with dotted lines which want to change to black color thin line. |
We are little bit unclear about your query. Can you please provide the following details?
· Are you mentioning the SfDataGrid control’s outer border in PDF document? If yes, its already drawn with Gray and thin line.
· Share any additional details or screenshot about your query.
| |
|
4. If Any column in sfdatagrid resized to zero/hide, how can the same column exclude to pdf export ? |
You can exclude the hidden 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
UG Link : https://help.syncfusion.com/windowsforms/sfdatagrid/exporttopdf#exclude-columns-while-exporting
|
Hi Deepak,Thanks for contacting Syncfusion support.Please find the updated in the below table,
Query Response 1.Page size, page orientation is not working You can change the page orientation by get the exported PdfGrid by using ExportToPdfGrid method and then draw that PdfGrid into a PdfDocument by changing the PageSettings.Orientation property of PdfDocument.You can able to set the Page size Pdf document when exporting. Please refer the below code exampleCode Example
private void ExportDataGridPageSize(object sender, EventArgs e){PdfDocument document = new PdfDocument();document.PageSettings.Orientation = PdfPageOrientation.Landscape;document.PageSettings.Size = PdfPageSize.A3;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);}} 2. Margins not working You can set the margin for exported pdf document, please refer the below code example,Code Example
private void ExportDataGridMargin(object sender, EventArgs e){PdfDocument document = new PdfDocument();document.PageSettings.Margins.All = 20;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);}} 3. Export to PDF, how can change the boarder of the box.. currently its gray color with dotted lines which want to change to black color thin line. We are little bit unclear about your query. Can you please provide the following details?· Are you mentioning the SfDataGrid control’s outer border in PDF document? If yes, its already drawn with Gray and thin line.· Share any additional details or screenshot about your query. 4. If Any column in sfdatagrid resized to zero/hide, how can the same column exclude to pdf export ? You can exclude the hidden columns when export the SfDataGrid to Pdf document by adding the columns in PdfExportingOptions.ExcludeColumns collection, please refer the below code and UG linkCode Example
private void ExportDataGridExcludeColumns(object sender, EventArgs e){sfDataGrid1.Columns[0].Visible = false;PdfExportingOptions options = new PdfExportingOptions();foreach (var columns in sfDataGrid1.Columns){if (!columns.Visible)options.ExcludeColumns.Add(columns.MappingName);}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);}}UG Link : https://help.syncfusion.com/windowsforms/sfdatagrid/exporttopdf#exclude-columns-while-exportingSample Location: http://www.syncfusion.com/downloads/support/forum/139211/ze/SfDataGrid_PDF_Exporting-1927292040Regards,Farjana Parveen A
Hi,
Thanks for your fast reply.
More info about the queries
Query no. 3. How can I change color and thin line of SfDataGrid control’s outer border in PDF document which drawn with Gray and thin line ?
Query 4. : If Columns mapping name is not given then How Can I exclude columns ? As per your below suggestion there was mapping name.
|
Query |
Response |
|
How can I change color and thin line of SfDataGrid control’s outer border in PDF document which drawn with Gray and thin line ? |
You can achieve your requirement by drawing the border with the use of the PdfGridLayoutResult. Please make use of the following code.
Code Example:
PdfGridLayoutResult layoutResult = pdfGrid.Draw(page, new PointF());
layoutResult.Page.Graphics.DrawRectangle(PdfPens.Blue, layoutResult.Bounds);
Sample Location:
|
|
If Columns mapping name is not given then How Can I exclude columns ? As per your below suggestion there was mapping name. |
MappingName for a column must be given for binding columns in SfDataGrid, otherwise default mapping names with column index will be initialized. So MappingName will not be empty at any point of execution, so you can exclude columns with its MappingName safely. |
|
Query |
Response | |
|
SFDataGrid Control's outer border as per your sample is working, but in the same way inner boarder how can I change ? |
If you want to change the border color of the exported grid cell, you can use the CellExporting event. In which you can change the border color for the exported pdf cell.
Code Sample:
Sample:
| |
|
Layout results all commands list required.. so that I can change my layout as per my requirements. |
Refer to the following API reference link for the PDFGridLayoutResult,
| |
|
In my app, default mapping names are initialized, Is it Field name is the default mapping name ? How auto mapping names are initialized ? |
If the AutoGenerateColumns is set to true, the SfDataGrid will create the columns with the property name as the mapping name.
If you are binding the collection of entity object to the SfDataGrid. (eg: List<OrderInfo>). The columns will be generated for all the public properties with the property name as the mapping name.
If you want to restrict some of the properties from the auto generating columns, set the Bindable or AutoGenerateFields attribute as false for that properties.
Code Sample:
UG Link:
|
|
void OnCellExporting(object sender, DataGridCellPdfExportingEventArgs e)
{
if (e.CellValue == null)
e.CellValue = string.Empty;
//Set the border color for the pdf cell
e.PdfGridCell.Style.Borders.All = new PdfPen(Color.Blue);
} |
|
void OnCellExporting(object sender, DataGridCellPdfExportingEventArgs e)
{
if (e.CellValue == null)
e.CellValue = string.Empty;
//Set the border color for the pdf cell
e.PdfGridCell.Style.Borders.All = new PdfPen(Color.Black, 0.2f);
} |