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