예제 #1
0
        protected override void InternalExecute(object data)
        {
            PdfToWordData pdfToWord = data as PdfToWordData;
            pdfToWord.Exception = null;

            try
            {
                Logger.LogDebug(String.Format("Convert PDF to RTF. Source=[{0}]", pdfToWord.Source));

                if (pdfToWord.PerformOCR)
                {
                    LicenseCode = _licenseCodeSolidOcrRestrictedToCompare;
                }

                License.Import(LicenseCode);

                using (PdfToWordConverter pdfToWordConverter = new PdfToWordConverter())
                {
                    pdfToWordConverter.AddSourceFile(pdfToWord.Source);
                    pdfToWordConverter.ReconstructionMode = Translate(pdfToWord.Mode);
                    pdfToWordConverter.TextRecoveryEngine = GetTextRecoveryEngine();
                    if (pdfToWord.PerformOCR)
                    {
                        // Changing TextRecoveryType will effect output and comparison results
                        pdfToWordConverter.TextRecoveryType = TextRecovery.Automatic;                        
                    }
                    else
                    {
                        pdfToWordConverter.TextRecoveryType = TextRecovery.Never;
                    }
					pdfToWordConverter.UserProperties = "<< /Description (Solid Converter PDF) >>"; // might overwrite what is already there - does it matter?
                    ConversionStatus status = pdfToWordConverter.ConvertTo(pdfToWord.Target, true);
                    
                    if (status != ConversionStatus.Success)
                    {
                        var error = String.Format("Error converting PDF to RTF. Error: {0}", Translate(status));
                        Logger.LogError(error);
                        pdfToWord.Exception = new Exception(error);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                var error = String.Format("Error converting PDF to RTF. Error: {0}", ex.Message);
                pdfToWord.Exception = new Exception(error, ex);
            }
        }
        /*
         * convert document
         */
        public static bool ConvertPDFDocument(string pdfPath, string docxPath, string licensePath)
        {
            // Set the location of your the file you want to convert
            // string pdfPath = @"C:\transfer\solid-conversions\one-page-c1.pdf";

            SolidFramework.License.Import(licensePath);
            bool ok = true;

            // *PDF to DOCX*//
            using (PdfToWordConverter converter = new PdfToWordConverter())
            {
                // Add files to convert.
                converter.AddSourceFile(pdfPath);

                //Set the preferred conversion properties

                // Detect Headers and Footers
                converter.HeaderAndFooterMode = HeaderAndFooterMode.Remove;

                // Set a specific page range to convert
                // converter.PageRange = new SolidFramework.PageRange(new int[] { 1 });

                // Turn on Solid Documents Optical Character Recognition (OCR) for Scanned Files
                // converter.TextRecoveryEngine = TextRecoveryEngine.SolidOCR; //Only with Pro+OCR and OCR license
                // converter.TextRecoveryType = TextRecovery.Automatic;

                // Set the layout of the reconstruction (Exact for Forms)
                converter.ReconstructionMode = ReconstructionMode.Flowing;

                // Convert the File.
                converter.ConvertTo(docxPath, true);

                // Show the status of the PDF file in the Console Window
                logger.Debug("Starting conversion");
                SolidFramework.Converters.Plumbing.ConversionStatus status = converter.ConvertTo(docxPath, true);
                if (status != ConversionStatus.Success)
                {
                    logger.Error("problem converting" + status);
                    ok = false;
                }

                return(ok);
            }
        }