示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.Cursor       = Cursors.WaitCursor;
            lblConversao.Text = "";
            lblCaminho.Text   = "";
            try
            {
                SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
                caminho = @escolherArquivo();
                f.OpenPdf(@caminho);
                //string caminho = (Environment.GetFolderPath caminho);

                if (f.PageCount > 0)
                {
                    string destino = @Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).ToString() + @"\Conversao"
                                     + nomeArquivo.Replace(".", "") + ".docx";
                    f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx;
                    f.ToWord(destino);

                    lblConversao.ForeColor = Color.Green;
                    lblConversao.Text      = destino;
                }
            }
            catch (Exception ex)
            {
                lblConversao.ForeColor = Color.Red;
                lblConversao.Text      = "Erro:  " + ex.Message;
            }
            this.Cursor = Cursors.Default;
        }
示例#2
0
        /// <summary>
        /// Converts PDF to DOCX, RTF, HTML, Text with OCR engine.
        /// </summary>
        public void ConvertPdfToAllWithOCR(string pdfPath)
        {
            // To perform OCR we'll use free OCR library by Nicomsoft.
            // https://www.nicomsoft.com/products/ocr/download/
            // The library is freeware and can be used in commercial application.
            // Also you have to insert this key:  AB2A4DD5FF2A.
            NsOCR = new NSOCRLib.NSOCRClass();
            NsOCR.Engine_SetLicenseKey("AB2A4DD5FF2A"); //required for licensed version only
            NsOCR.Engine_InitializeAdvanced(out CfgObj, out OcrObj, out ImgObj);

            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            f.OCROptions.Method += PerformOCRNicomsoft;
            f.OCROptions.Mode    = PdfFocus.COCROptions.eOCRMode.AllImages;
            f.WordOptions.KeepCharScaleAndSpacing = false;

            string pdfFile = pdfPath;
            string outFile = String.Empty;

            f.OpenPdf(pdfFile);
            if (f.PageCount > 0)
            {
                // To Docx.
                outFile = "Result.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 HTML.
                outFile = "Result.html";
                f.HtmlOptions.KeepCharScaleAndSpacing = false;
                if (f.ToHtml(outFile) == 0)
                {
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
                    {
                        UseShellExecute = true
                    });
                }
            }
            else
            {
                Console.WriteLine("Error: {0}!", f.Exception.Message);
                Console.ReadLine();
            }
        }
示例#3
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (file.HasFile)
            {
                try
                {
                    if (file.PostedFile.FileName.Length == 0 || file.FileBytes.Length == 0)
                    {
                        Result.Text = "Please select PDF file at first!";
                        return;
                    }
                    byte[] rtf = null;

                    SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
                    f.OpenPdf(file.FileBytes);

                    if (f.PageCount > 0)
                    {
                        //Let's whole PDF document to Word (RTF)
                        f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Rtf;

                        // You may also set an output format to Docx.
                        //f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx;
                        rtf = f.ToWord();
                    }

                    //show Word/rtf
                    if (rtf != null)
                    {
                        ShowResult(rtf, "Result.rtf", "application/msword");
                    }
                    else
                    {
                        Result.Text = "Converting failed!";
                    }
                }
                catch (Exception ex)
                {
                    Response.Write("Error: " + ex.Message);
                }
            }
            else
            {
                Result.Text = "Please choose a file to upload!";
            }
        }
示例#4
0
        public static void ConvertToWord(object targ)
        {
            TArgument targum  = (TArgument)targ;
            string    pdfFile = targum.PdfFile;
            int       page    = targum.PageNumber;

            string docxFile = Path.GetFileNameWithoutExtension(pdfFile) + ".docx";

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

            f.WordOptions.Format     = PdfFocus.CWordOptions.eWordDocument.Docx;
            f.WordOptions.RenderMode = PdfFocus.CWordOptions.eRenderMode.Flowing;

            f.OpenPdf(pdfFile);

            bool done = false;

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

                if (f.ToWord(docxFile, 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(docxFile)
                {
                    UseShellExecute = true
                });
            }
            else
            {
                Console.WriteLine("{0}\t - Error!", Path.GetFileName(pdfFile));
            }
        }
示例#5
0
        public override void convertToWord(string path, string tempFolder)
        {
            nameDocFile     = Path.GetFileNameWithoutExtension(path) + extension;
            convertFileName = nameDocFile;
            string pathDocFile = Path.Combine(tempFolder, nameDocFile);

            pathWordFile = pathDocFile;
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            if (File.Exists(pathDocFile))
            {
                File.Delete(pathDocFile);
            }
            f.OpenPdf(path);
            if (f.PageCount > 0)
            {
                f.WordOptions.Format = SautinSoft.PdfFocus.CWordOptions.eWordDocument.Docx;
                f.ToWord(pathDocFile);
            }
        }
        static void Main(string[] args)
        {
            string pathToPdf  = @"d:\simple text.pdf";
            string pathToWord = @"d:\result.doc";

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

            f.OpenPdf(pathToPdf);

            if (f.PageCount > 0)
            {
                int result = f.ToWord(pathToWord);

                //Show Word document
                if (result == 0)
                {
                    System.Diagnostics.Process.Start(pathToWord);
                }
            }
        }
 private void btnPDF2Doc_Click(object sender, EventArgs e) // PDF convert to Doc Function
 {
     SautinSoft.PdfFocus doc = new SautinSoft.PdfFocus();  // 呼叫SautinSoft中的Doc Convert Function
     doc.OpenPdf(@"C:\Users\施宗佑\OneDrive\桌面\期末報告 - 物件導向程式設計\測試用文檔\Graph.pdf");
     doc.ToWord(@"C:\Users\施宗佑\OneDrive\桌面\期末報告 - 物件導向程式設計\NewGraph.docx");
 }
示例#8
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();
            }
        }