This is a migrated thread and some comments may be shown as answers.

ExportToPdf and then add additional content

2 Answers 284 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 17 Jan 2018, 04:49 PM

Hi guys,

I'm desperately trying to find the easiest way of accomplishing this. In short I have a RadGridView of which I have used the ExportToPdf method successfully to export the grid in a landscape format to PDF.

 

GridDetails.ExportToPdf(stream, new GridViewPdfExportOptions()
{
  ShowColumnHeaders = true,
  ShowColumnFooters = true,
  ShowGroupFooters = true,
  PageOrientation = PageOrientation.Landscape,
  ExportDefaultStyles = true,
  AutoFitColumnsWidth = true
});

 

I have been asked whether I can now include the company logo and title to the top, as well as additional text at the bottom. I have looked at trying to use the ExportToRadFixedDocument method, however I cannot seem to get the grid to appear in landscape.
I have tried the following code only to find the page rotated to be landscape, but it's contents appearing as if it were still portrait:

GridViewDocumentExportOptions options = new GridViewDocumentExportOptions();
options.AutoFitColumnsWidth = true;
options.ExportDefaultStyles = true;
options.ShowColumnHeaders = true;
 
RadFixedDocument fixedDoc = GridDetails.ExportToRadFixedDocument(options);
RadFixedPage page = fixedDoc.Pages[0];
page.Rotation = Telerik.Windows.Documents.Fixed.Model.Data.Rotation.Rotate270;

 

This makes sense as the Fixed document is no doubt generated in portrait by the ExportToRadFixedDocument method and unlike GridViewPdfExportOptions, GridViewDocumentExportOptions does not have a PageOrientation property to specify otherwise.

My last remaining option was to use RadFixedDocumentEditor and draw the whole thing from scratch, however if I can avoid this I would rather not spend the time trying to figure out where to draw each row of the grid and whether it needs to be split across multiple pages.

Am I missing something? Is there an easy way to generate a FixedDocument from a RadGridView that has it correctly rotated from which I can then add additional items using the FixedContentEditor.

Thanks
Marc

2 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 22 Jan 2018, 12:02 PM
Hello Marc,

To add content to the exported PDF document, you can use the ExportToWorkbook extension method, modify the exported workbook and set the orientation of the printed document through the WorksheetPageSetup property. You can then use the PdfFormatProvider class from the Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf namespace to export the workbook to PDF.

For your convenience, I've prepared a small sample project with the implementation. You can utilize the RadSpreadProcessing library to insert content other than plain text (shapes and images for example) and further modify the layout to your liking.

Please have a look and let me know if you find it helpful.

Regards,
Dilyan Traykov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Marc
Top achievements
Rank 1
answered on 24 Jan 2018, 12:56 PM

Hi Dilyan,

I've had a quick play with the code provided and it looks like this is what I was after! I'll have to fiddle a bit with formatting in terms of getting things looking the way I need, but the links to the documentation plus the demo project was exactly what I needed.

Many thanks!
Marc

Tags
GridView
Asked by
Marc
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Marc
Top achievements
Rank 1
Share this question
or