none
Word to PDF conversion, generated PDF is not searchable RRS feed

  • Question

  • Hi 

    I am using C# code to convert to word to pdf. We created exe out of C# coade and using in our java program. The pdf is creating successfully but the problem is it is not searchable. It is creating as bitmap instead of text. I need your help here. I am pasting my code below. Your help is appreciated. Thanks . Sridhar

                                    

    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);
                }

            }
        }
    }







    • Edited by Sridhar Dhurjeti Tuesday, September 1, 2015 11:55 AM
    • Moved by CoolDadTx Tuesday, September 1, 2015 7:29 PM Office related
    Tuesday, September 1, 2015 10:35 AM

Answers

  • Hi Sridhar,

    >>The pdf is creating successfully but the problem is it is not searchable. It is creating as bitmap instead of text.<<

    The issue is not relative to the code generate the PDF file, the PDF is generated correctly by Word application. It depends on the tools/library you used to open the PDF.  

    You also could use Word 2013 to open, manipulate it.

    Hope it is helpful.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, September 2, 2015 7:55 AM
    Moderator

All replies

  • Hi 

    Anybody has any thoughts on this, appreciate your help.

    Thanks

    Sridhar

    Wednesday, September 2, 2015 4:53 AM
  • Hi Sridhar,

    >>The pdf is creating successfully but the problem is it is not searchable. It is creating as bitmap instead of text.<<

    The issue is not relative to the code generate the PDF file, the PDF is generated correctly by Word application. It depends on the tools/library you used to open the PDF.  

    You also could use Word 2013 to open, manipulate it.

    Hope it is helpful.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, September 2, 2015 7:55 AM
    Moderator