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

Export to PDF error

3 Answers 55 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hakki
Top achievements
Rank 1
Hakki asked on 14 May 2013, 09:21 AM
Hello,

I get the following error when trying to export to PDF:

http://i230.photobucket.com/albums/ee248/masteratt/exportPDFerror.png


Here is my code:

var saveDialog = new SaveFileDialog
               {
                   DefaultExt = "*.pdf",
                   Filter = "Adobe PDF Document (*.pdf)|*.pdf"
               };
 
           if (saveDialog.ShowDialog() != true) return;
 
           var table = new Table(1, CheckGrid1.Columns.Count);
 
           var document = new RadDocument();
           document.Sections.Add(new Section());
           document.Sections.First.Blocks.Add(table);
 
           TableCell headerCell = table.Rows.First.Cells.First;
           AddCellDataSpan(headerCell, "ID", Colors.DarkGray, Colors.White, RadTextAlignment.Center);
           headerCell = (TableCell) headerCell.NextSibling;
           AddCellDataSpan(headerCell, "Check Date", Colors.DarkGray, Colors.White, RadTextAlignment.Center);
           headerCell = (TableCell) headerCell.NextSibling;
           AddCellDataSpan(headerCell, "Check Description", Colors.DarkGray, Colors.White, RadTextAlignment.Center);
 
           var everyTwo = 0;
           var doubleChecker = 1;
 
           foreach (var item in CheckGrid1.Items.OfType<GridBinding>())
           {
               var row = table.AddRow();
 
               var index = 0;
               foreach (var cell in row.Cells)
               {
                   switch (index)
                   {
                       case 0:
                           AddCellDataSpan(cell, item.CheckIDColumn.ToString(CultureInfo.InvariantCulture),
                                           everyTwo == doubleChecker ? Colors.LightGray : Colors.White, Colors.Black,
                                           RadTextAlignment.Center);
                           break;
                       case 1:
                           AddCellDataSpan(cell, item.checkDateColumn,
                                           everyTwo == doubleChecker ? Colors.LightGray : Colors.White, Colors.Black,
                                           RadTextAlignment.Center);
                           break;
                       case 2:
                           AddCellDataSpan(cell, item.CheckDescColumn,
                                           everyTwo == doubleChecker ? Colors.LightGray : Colors.White, Colors.Black,
                                           RadTextAlignment.Center);
                           break;
                   }
 
                   index++;
               }
 
               if (everyTwo == doubleChecker)
                   doubleChecker += 2;
 
               everyTwo++;
           }
 
           document.LayoutMode = DocumentLayoutMode.Paged;
           document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
           document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));
 
           var extension = Path.GetExtension(saveDialog.SafeFileName);
 
           var provider = DocumentFormatProvidersManager.GetProviderByExtension(extension);
 
           if (provider == null)
           {
               MessageBox.Show("Unsupported file format.");
               return;
           }
 
           try
           {
               using (var output = saveDialog.OpenFile())
               {
                   provider.Export(document, output);
               }
 
               MessageBox.Show("File '" + provider.Name + "' has been saved.", "PDF Success", MessageBoxButton.OK);
           }
           catch (Exception ex)
           {
               MessageBox.Show("Unable to save the file: " + ex);
           }


I have referenced all FormatProviders and document and documentFixed. Is it a case of missing reference or is something else going on?

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 15 May 2013, 09:19 AM
Hello,

Would you please Clean and Rebuild your solution and try again? You should also check if all the references are with the same versions.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Hakki
Top achievements
Rank 1
answered on 15 May 2013, 12:17 PM
Ah, yes....a couple of references were outdated. A simple run of Upgrade Wizard from the Telerik toolbar solved the problem.

Thanks.

However I am curious as I thought it picked up outdated references when launching the project and prompted you to update?
0
Dimitrina
Telerik team
answered on 16 May 2013, 03:22 PM
Hi,

Thank you for the update. Sometimes the Visual Studio seems to run the older code and that is why Cleaning the project help. 

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Hakki
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Hakki
Top achievements
Rank 1
Share this question
or