无法从单词

时间:2015-08-19 13:24:41

标签: c# pdf

我们正在从WORD文档生成PDF,我们正在使用“Microsoft.Office.Interop.Word.Application”我们的代码。问题是当我们打开生成的PDF并搜索文本时,虽然该文本存在但却说没有找到。我认为PDF中的内容是图像而不是文本,其他的东西,如显示表格,图像都非常好。有没有办法让PDF可搜索?

我也在这里附上我的代码。请调查一下让我知道你的想法。感谢您的帮助。

由于 斯

CODE:

using System;
using System.Collections.Generic;
using System.Collections;
using System.Diagnostics;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Word = Microsoft.Office.Interop.Word;
using System.IO;
using Microsoft.Office.Interop.Word;
namespace DocToPdfConverter
{

    public class DocToPdfConverter
    {

        static int Main(string[] args)
        {
            String inputFileName = args[0];
            String outputFileName = args[1];
            Console.WriteLine("Started Converting Word Document To Pdf >> .....");
            DocToPdfConverter dc = new DocToPdfConverter();
            Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application();
            dc.ConvertToPdf(inputFileName, outputFileName, application);
            Console.WriteLine("Successfully Done With PDF Conversion.");
            return 0;
        }

        public void ConvertToPdf(String inputFileName, String outputFileName, Microsoft.Office.Interop.Word.Application application)
        {
            object originalFormat = null;
            object routeDocument = false;
            object saveOption = null;
            Word.Bookmarks bookmarks = null;
            string bookmarkNames = string.Empty;
            String outName = string.Empty;
            try
            {
                object missing = System.Reflection.Missing.Value;
                object readOnly = false;
                object isVisible = true;
                object inputsFileName = inputFileName;
                application.Visible = true;
                application.DefaultWebOptions().AlwaysSaveInDefaultEncoding = true;
                Word.Document aDoc = application.Documents.Open(ref inputsFileName, ref missing,
                ref readOnly, ref missing, ref missing,
                ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref isVisible);
                saveOption = Word.WdSaveOptions.wdDoNotSaveChanges;
                originalFormat = Word.WdOriginalFormat.wdOriginalDocumentFormat;
                object fileFormat = WdSaveFormat.wdFormatPDF;
                object outputFileNames = outputFileName;


                if (aDoc != null)
                {
                    Console.WriteLine("Before Export.......");
                aDoc.ExportAsFixedFormat(  outputFileName, WdExportFormat.wdExportFormatPDF, false,
                                                 WdExportOptimizeFor.wdExportOptimizeForPrint,
                                                 WdExportRange.wdExportAllDocument, 0, 0,
                                                 WdExportItem.wdExportDocumentContent, true, true,
                                                 WdExportCreateBookmarks.wdExportCreateHeadingBookmarks, true, true, false,
                                                 ref missing);
                Console.WriteLine("After Export..............");
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                application.Quit(ref saveOption, ref originalFormat, ref routeDocument);
            }

        }
    }
}

0 个答案:

没有答案