locked
converting pdf file into excel file using c# RRS feed

  • Question

  • Dear sir,

    Is it possible to convert the pdf file into excel file without using third party in C#?

    Thanks in advance.

    M.Sumathi.


    Sumathi

    Tuesday, May 7, 2013 10:23 AM

Answers

  • //////////////////////////////////////////////////////////////////////////////////////////////////// // This example was designed for using in Microsoft Visual C# from // Microsoft Visual Studio 2003 or above. // // 1. Microsoft Excel 97 or above should be installed and activated on your PC. // // 2. Before using this example, please read this article from Microsoft Excel 2003 knowledge base: // http://support.microsoft.com/kb/320369/en-us/ // A workaround for this issue is available in this example. // // 3. Universal Document Converter 5.2 or above should be installed, too. // // 4. Add references to "Microsoft Excel XX.0 Object Library" and "Universal Document Converter Type Library" // using the Project | Add Reference menu > COM tab. // XX is the Microsoft Office version installed on your computer. //////////////////////////////////////////////////////////////////////////////////////////////////// using System; using System.IO; using UDC; using Excel = Microsoft.Office.Interop.Excel; //using Excel; in VS2003 namespace ExcelToPDF { class Program { static void PrintExcelToPDF(string ExcelFilePath) { //Create a UDC object and get its interfaces IUDC objUDC = new APIWrapper(); IUDCPrinter Printer = objUDC.get_Printers("Universal Document Converter"); IProfile Profile = Printer.Profile; //Use Universal Document Converter API to change settings of converterd document Profile.PageSetup.ResolutionX = 600; Profile.PageSetup.ResolutionY = 600; Profile.FileFormat.ActualFormat = FormatID.FMT_PDF; Profile.FileFormat.PDF.ColorSpace = ColorSpaceID.CS_TRUECOLOR; Profile.FileFormat.PDF.Multipage = MultipageModeID.MM_MULTI; Profile.OutputLocation.Mode = LocationModeID.LM_PREDEFINED; Profile.OutputLocation.FolderPath = @"c:\UDC Output Files"; Profile.OutputLocation.FileName = @"&[DocName(0)] -- &[Date(0)] -- &[Time(0)].&[ImageType]"; Profile.OutputLocation.OverwriteExistingFile = false; Profile.PostProcessing.Mode = PostProcessingModeID.PP_OPEN_FOLDER; //Create a Excel's Application object Excel.Application ExcelApp = new Excel.ApplicationClass(); Object ReadOnly = true; Object Missing = Type.Missing; //This will be passed when ever we don’t want to pass value //If you run an English version of Excel on a computer with the regional settings are configured for a non-English language, you must set the CultureInfo prior calling Excel methods. System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); //Open the document from a file Excel.Workbook Workbook = ExcelApp.Workbooks.Open(ExcelFilePath, Missing, ReadOnly, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing); //Change active worksheet settings and print it Excel.Worksheet Worksheet = (Excel.Worksheet)Workbook.ActiveSheet; Excel.PageSetup PageSetup = Worksheet.PageSetup; PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape; Object Preview = false; Worksheet.PrintOut(Missing, Missing, Missing, Preview, "Universal Document Converter", Missing, Missing, Missing); //Close the spreadsheet without saving changes Object SaveChanges = false; Workbook.Close(SaveChanges, Missing, Missing); //Close Microsoft Excel ExcelApp.Quit(); } static void Main(string[] args) { string TestFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFile.xls"); PrintExcelToPDF(TestFilePath); } } }

    As Kushwaha

    Tuesday, May 7, 2013 1:58 PM
  • xporting a DataGridView to an Excel/PDF/image file by using Reporting Services report generation: 
    http://www.codeproject.com/KB/reporting-services/ReportExporters_WinForms.aspx

    100% .NET component for rendering PDF documents: 
    http://www.codeproject.com/KB/showcase/pdfrasterizer.aspx

    Exporting Data to Excel: 
    http://www.codeproject.com/KB/office/largedatatoexcel.aspx

    Code to extract plain text from a PDF file:
    http://www.codeproject.com/KB/cpp/ExtractPDFText.aspx

    On the other hand, maybe you can get supports from the adobe reader forum which there are experts who can help you to get the PDF API:

    http://forum.planetpdf.com/default.asp?action=10&fid=3 


    As Kushwaha

    Tuesday, May 7, 2013 2:02 PM

All replies

  • I suppose it is possible to do this without using ITextSharp or some other tool, but you would need to write your own code to accomplish much of what that tool already does.  Bear in mind I am of the opinion that ITextSharp will help, but do not have code to accomplish your goal with it.  I have only heard it being highly regarded by colleagues.

    Mike

    Tuesday, May 7, 2013 11:18 AM
  • //////////////////////////////////////////////////////////////////////////////////////////////////// // This example was designed for using in Microsoft Visual C# from // Microsoft Visual Studio 2003 or above. // // 1. Microsoft Excel 97 or above should be installed and activated on your PC. // // 2. Before using this example, please read this article from Microsoft Excel 2003 knowledge base: // http://support.microsoft.com/kb/320369/en-us/ // A workaround for this issue is available in this example. // // 3. Universal Document Converter 5.2 or above should be installed, too. // // 4. Add references to "Microsoft Excel XX.0 Object Library" and "Universal Document Converter Type Library" // using the Project | Add Reference menu > COM tab. // XX is the Microsoft Office version installed on your computer. //////////////////////////////////////////////////////////////////////////////////////////////////// using System; using System.IO; using UDC; using Excel = Microsoft.Office.Interop.Excel; //using Excel; in VS2003 namespace ExcelToPDF { class Program { static void PrintExcelToPDF(string ExcelFilePath) { //Create a UDC object and get its interfaces IUDC objUDC = new APIWrapper(); IUDCPrinter Printer = objUDC.get_Printers("Universal Document Converter"); IProfile Profile = Printer.Profile; //Use Universal Document Converter API to change settings of converterd document Profile.PageSetup.ResolutionX = 600; Profile.PageSetup.ResolutionY = 600; Profile.FileFormat.ActualFormat = FormatID.FMT_PDF; Profile.FileFormat.PDF.ColorSpace = ColorSpaceID.CS_TRUECOLOR; Profile.FileFormat.PDF.Multipage = MultipageModeID.MM_MULTI; Profile.OutputLocation.Mode = LocationModeID.LM_PREDEFINED; Profile.OutputLocation.FolderPath = @"c:\UDC Output Files"; Profile.OutputLocation.FileName = @"&[DocName(0)] -- &[Date(0)] -- &[Time(0)].&[ImageType]"; Profile.OutputLocation.OverwriteExistingFile = false; Profile.PostProcessing.Mode = PostProcessingModeID.PP_OPEN_FOLDER; //Create a Excel's Application object Excel.Application ExcelApp = new Excel.ApplicationClass(); Object ReadOnly = true; Object Missing = Type.Missing; //This will be passed when ever we don’t want to pass value //If you run an English version of Excel on a computer with the regional settings are configured for a non-English language, you must set the CultureInfo prior calling Excel methods. System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); //Open the document from a file Excel.Workbook Workbook = ExcelApp.Workbooks.Open(ExcelFilePath, Missing, ReadOnly, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing); //Change active worksheet settings and print it Excel.Worksheet Worksheet = (Excel.Worksheet)Workbook.ActiveSheet; Excel.PageSetup PageSetup = Worksheet.PageSetup; PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape; Object Preview = false; Worksheet.PrintOut(Missing, Missing, Missing, Preview, "Universal Document Converter", Missing, Missing, Missing); //Close the spreadsheet without saving changes Object SaveChanges = false; Workbook.Close(SaveChanges, Missing, Missing); //Close Microsoft Excel ExcelApp.Quit(); } static void Main(string[] args) { string TestFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFile.xls"); PrintExcelToPDF(TestFilePath); } } }

    As Kushwaha

    Tuesday, May 7, 2013 1:58 PM
  • xporting a DataGridView to an Excel/PDF/image file by using Reporting Services report generation: 
    http://www.codeproject.com/KB/reporting-services/ReportExporters_WinForms.aspx

    100% .NET component for rendering PDF documents: 
    http://www.codeproject.com/KB/showcase/pdfrasterizer.aspx

    Exporting Data to Excel: 
    http://www.codeproject.com/KB/office/largedatatoexcel.aspx

    Code to extract plain text from a PDF file:
    http://www.codeproject.com/KB/cpp/ExtractPDFText.aspx

    On the other hand, maybe you can get supports from the adobe reader forum which there are experts who can help you to get the PDF API:

    http://forum.planetpdf.com/default.asp?action=10&fid=3 


    As Kushwaha

    Tuesday, May 7, 2013 2:02 PM
  • He asked for PDF to EXCEL not From EXCEL to PDF 

    Dear sir,

    Is it possible to convert the pdf file into excel file without using third party in C#?

    Thanks in advance.


    Wednesday, March 12, 2014 12:12 PM
  • I agree with Mohs_shadhid, this post provides several ways to convert PDF to Excel using freeware dll

    https://social.msdn.microsoft.com/Forums/en-US/db6c6c05-0531-4723-824f-36a8acf94955/how-to-convert-pdf-to-excel-file-using-freeware-dll?forum=csharpgeneral&prof=required

    _____________________

    Free C# PowerPoint component is under evaluation, any suggestions.

    Monday, December 8, 2014 7:20 AM