Click here to Skip to main content
16,016,134 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello,

I want to convert rtf data that contains both text and image to pdf format.


Please some body help me.
Posted

You need to buy a library to do that, or try to work out how to use a free one like iTextSharp. .NET has no PDF support.
 
Share this answer
 
Please install ms-office 2007 and plug-in save as pdf and xps...
then

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Word;

namespace PDFExport
{
public class Class1
{
public void saveaspdf(string rptname)
{
object readOnly = false;

object Unknown = System.Reflection.Missing.Value; //Type.Missing;

object missing = Type.Missing;
ApplicationClass wordApplication = new ApplicationClass();
Document wordDocument = null;
object paramSourceDocPath = rptname;
object paramMissing = Type.Missing;


string paramExportFilePath = rptname + ".pdf";

//WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatPDF;
//bool paramOpenAfterExport = false;
//WdExportOptimizeFor paramExportOptimizeFor =
// WdExportOptimizeFor.wdExportOptimizeForPrint;
//WdExportRange paramExportRange = WdExportRange.wdExportAllDocument;
//int paramStartPage = 0;
//int paramEndPage = 0;
//WdExportItem paramExportItem = WdExportItem.wdExportDocumentContent;
//bool paramIncludeDocProps = true;
//bool paramKeepIRM = true;
//WdExportCreateBookmarks paramCreateBookmarks =
// WdExportCreateBookmarks.wdExportCreateWordBookmarks;
//bool paramDocStructureTags = true;
//bool paramBitmapMissingFonts = true;
//bool paramUseISO19005_1 = false;

wordDocument = wordApplication.Documents.Open(ref paramSourceDocPath, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing, ref paramMissing, ref paramMissing,
ref paramMissing);


wordApplication.Application.Visible = false;

wordApplication.WindowState = WdWindowState.wdWindowStateMinimize;
//wordApplication.ActivePrinter = "Microsoft XPS Document Writer";
try
{

if (wordDocument != null)

wordDocument.ExportAsFixedFormat(paramExportFilePath, WdExportFormat.wdExportFormatPDF, false,
WdExportOptimizeFor.wdExportOptimizeForPrint, WdExportRange.wdExportAllDocument, 1, 1,
WdExportItem.wdExportDocumentContent, true, true,
WdExportCreateBookmarks.wdExportCreateNoBookmarks, true, true, true, ref missing);

}

catch (Exception ex)
{
// Respond to the error
}
finally
{
// Close and release the Document object.
if (wordDocument != null)
{
wordDocument.Close(ref paramMissing, ref paramMissing,
ref paramMissing);
wordDocument = null;
}

// Quit Word and release the ApplicationClass object.
if (wordApplication != null)
{
wordApplication.Quit(ref paramMissing, ref paramMissing,
ref paramMissing);
wordApplication = null;
}

GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}

}
}
 
Share this answer
 
Comments
hardikdarji 23-Nov-10 6:40am    
Thanks
hardikdarji 23-Nov-10 6:40am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900