Пример #1
0
        static void Main(string[] args)
        {
            //foreach (string file in Directory.EnumerateFiles(@"C:\Users\yanswong\source\repos\Convert PDF file to Excel file\C#\SW\", "*.pdf"))
            foreach (string file in Directory.EnumerateFiles(@"C:\Users\yanswong\Desktop\CMM\May-2017\", "*.pdf", SearchOption.AllDirectories))
            //foreach (string [] file in Directory.GetDirectories(@"\\pngnas2.mys.agilent.com\EUC_Gshare\vpdpenang\VPD LDA\VPD LDA\CMM MEASUREMENT RESULT\2018\","*",SearchOption.AllDirectories))
            {
                //string pathToPdf = @"C:\Users\yanswong\source\repos\Convert PDF file to Excel file\C#\SW\3700391-115-01-18-2.pdf";
                //string pathToExcel = Path.ChangeExtension(pathToPdf, ".xls");
                string pathToExcel = Path.ChangeExtension(file, ".xls");
                // Convert PDF file to Excel file
                SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

                // 'true' = Convert all data to spreadsheet (tabular and even textual).
                // 'false' = Skip textual data and convert only tabular (tables) data.
                f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = true;

                // 'true'  = Preserve original page layout.
                // 'false' = Place tables before text.
                f.ExcelOptions.PreservePageLayout = true;

                //f.OpenPdf(pathToPdf);
                f.OpenPdf(file);
                if (f.PageCount > 0)
                {
                    int result = f.ToExcel(pathToExcel);

                    //Open a produced Excel workbook
                    //if (result==0)
                    //{
                    //    System.Diagnostics.Process.Start(pathToExcel);
                    //}
                }
            }
        }
        static void Main(string[] args)
        {
            string pathToPdf   = @"d:\Tempos\Table.pdf";
            string pathToExcel = Path.ChangeExtension(pathToPdf, ".xls");

            // Convert PDF file to Excel file
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

            // 'true' = Convert all data to spreadsheet (tabular and even textual).
            // 'false' = Skip textual data and convert only tabular (tables) data.
            f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = true;

            // 'true'  = Preserve original page layout.
            // 'false' = Place tables before text.
            f.ExcelOptions.PreservePageLayout = true;

            f.OpenPdf(pathToPdf);

            if (f.PageCount > 0)
            {
                int result = f.ToExcel(pathToExcel);

                //Open a produced Excel workbook
                if (result == 0)
                {
                    System.Diagnostics.Process.Start(pathToExcel);
                }
            }
        }
Пример #3
0
        public static void ConvertToExcel(object targ)
        {
            TArgument targum  = (TArgument)targ;
            string    pdfFile = targum.PdfFile;
            int       page    = targum.PageNumber;

            string excelFile = Path.GetFileNameWithoutExtension(pdfFile) + ".xls";

            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

            // 'true' = Convert all data to spreadsheet (tabular and even textual).
            // 'false' = Skip textual data and convert only tabular (tables) data.
            f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = true;

            // 'true'  = Preserve original page layout.
            // 'false' = Place tables before text.
            f.ExcelOptions.PreservePageLayout = true;

            // The information includes the names for the culture, the writing system,
            // the calendar used, the sort order of strings, and formatting for dates and numbers.
            System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
            ci.NumberFormat.NumberDecimalSeparator = ",";
            ci.NumberFormat.NumberGroupSeparator   = ".";
            f.ExcelOptions.CultureInfo             = ci;

            f.OpenPdf(pdfFile);

            bool done = false;

            if (f.PageCount > 0)
            {
                if (page >= f.PageCount)
                {
                    page = 1;
                }

                if (f.ToExcel(excelFile, page, page) == 0)
                {
                    done = true;
                }
                f.ClosePdf();
            }

            if (done)
            {
                Console.WriteLine("{0}\t - Done!", Path.GetFileName(pdfFile));
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(excelFile)
                {
                    UseShellExecute = true
                });
            }
            else
            {
                Console.WriteLine("{0}\t - Error!", Path.GetFileName(pdfFile));
            }
        }
Пример #4
0
        public static void ConvertToExcel(object targ)
        {
            TArgument targum  = (TArgument)targ;
            string    pdfFile = targum.PdfFile;
            int       page    = targum.PageNumber;

            string excelFile = Path.ChangeExtension(pdfFile, ".xls");

            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

            // 'true' = Convert all data to spreadsheet (tabular and even textual).
            // 'false' = Skip textual data and convert only tabular (tables) data.
            f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = true;

            // 'true'  = Preserve original page layout.
            // 'false' = Place tables before text.
            f.ExcelOptions.PreservePageLayout = true;

            f.OpenPdf(pdfFile);

            bool done = false;

            if (f.PageCount > 0)
            {
                if (page >= f.PageCount)
                {
                    page = 1;
                }

                if (f.ToExcel(excelFile, page, page) == 0)
                {
                    done = true;
                }
                f.ClosePdf();
            }

            if (done)
            {
                Console.WriteLine("{0}\t - Done!", Path.GetFileName(pdfFile));
            }
            else
            {
                Console.WriteLine("{0}\t - Error!", Path.GetFileName(pdfFile));
            }
        }
 private void btnPDF2Excel_Click(object sender, EventArgs e) // PDF convert to Excel Function
 {
     SautinSoft.PdfFocus excel = new SautinSoft.PdfFocus();  // 呼叫SautinSoft中的Excel Convert Function
     excel.OpenPdf(@"C:\Users\施宗佑\OneDrive\桌面\期末報告 - 物件導向程式設計\測試用文檔\Order.pdf");
     excel.ToExcel(@"C:\Users\施宗佑\OneDrive\桌面\期末報告 - 物件導向程式設計\NewOrder.xls");
 }
Пример #6
0
        /// <summary>
        /// Converts PDF to DOCX, RTF, HTML, XML, Excel (XLS), PNG, Multipage TIFF, Text.
        /// </summary>
        public static void ConvertPdfToAll()
        {
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

            string pdfFile = @"..\..\..\..\simple text.pdf";
            string outFile = String.Empty;

            f.OpenPdf(pdfFile);
            if (f.PageCount > 0)
            {
                // To Docx.
                outFile = Path.ChangeExtension(pdfFile, ".docx");
                f.WordOptions.Format = PdfFocus.CWordOptions.eWordDocument.Docx;
                if (f.ToWord(outFile) == 0)
                {
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                    {
                        UseShellExecute = true
                    });
                }

                // To Rtf.
                outFile = Path.ChangeExtension(pdfFile, ".rtf");
                f.WordOptions.Format = PdfFocus.CWordOptions.eWordDocument.Rtf;
                if (f.ToWord(outFile) == 0)
                {
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                    {
                        UseShellExecute = true
                    });
                }

                // To Excel.
                outFile = Path.ChangeExtension(pdfFile, ".xls");
                f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = true;
                if (f.ToExcel(outFile) == 0)
                {
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                    {
                        UseShellExecute = true
                    });
                }

                // To HTML.
                outFile = Path.ChangeExtension(pdfFile, ".html");
                f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = true;
                if (f.ToHtml(outFile) == 0)
                {
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                    {
                        UseShellExecute = true
                    });
                }

                // To XML.
                outFile = Path.ChangeExtension(pdfFile, ".xml");
                f.XmlOptions.ConvertNonTabularDataToSpreadsheet = true;
                if (f.ToXml(outFile) == 0)
                {
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                    {
                        UseShellExecute = true
                    });
                }

                // To Image.
                outFile                    = Path.ChangeExtension(pdfFile, ".png");
                f.ImageOptions.Dpi         = 300;
                f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
                if (f.ToImage(outFile, 1) == 0)
                {
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                    {
                        UseShellExecute = true
                    });
                }

                // To Multipage Tiff (Black & White).
                outFile = Path.ChangeExtension(pdfFile, ".tiff");
                f.ImageOptions.ColorDepth = PdfFocus.CImageOptions.eColorDepth.BlackWhite1bpp;
                if (f.ToMultipageTiff(outFile, System.Drawing.Imaging.EncoderValue.CompressionCCITT4) == 0)
                {
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                    {
                        UseShellExecute = true
                    });
                }

                // To Text.
                outFile = Path.ChangeExtension(pdfFile, ".txt");
                if (f.ToText(outFile) == 0)
                {
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                    {
                        UseShellExecute = true
                    });
                }
            }
            else
            {
                Console.WriteLine("Error: {0}!", f.Exception.Message);
                Console.ReadLine();
            }
        }