将rtf转换为pdf [英] converting rtf to pdf

查看:111
本文介绍了将rtf转换为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想将同时包含文本和图像的rtf数据转换为pdf格式.


请有人帮助我.

Hello,

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


Please some body help me.

推荐答案

您需要购买一个库才能做到这一点,或者尝试弄清楚如何使用像iTextSharp这样的免费库. .NET不支持PDF.
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.


请安装ms-office 2007和插件,另存为pdf和xps ...
然后

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用Microsoft.Office.Interop.Word;

命名空间PDFExport
{
公共课Class1
{
公共无效saveaspdf(字符串rptname)
{
对象readOnly = false;

对象未知= System.Reflection.Missing.Value; //Type.Missing;

对象丢失= Type.Missing;
ApplicationClass wordApplication = new ApplicationClass();
文档wordDocument = null;
对象paramSourceDocPath = rptname;
对象paramMissing = Type.Missing;


字符串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";
试试
{

如果(wordDocument!= null)

wordDocument.ExportAsFixedFormat(paramExportFilePath,WdExportFormat.wdExportFormatPDF,false,
WdExportOptimizeFor.wdExportOptimizeForPrint,WdExportRange.wdExportAllDocument,1、1,
WdExportItem.wdExportDocumentContent,true,true,
WdExportCreateBookmarks.wdExportCreateNoBookmarks,true,true,true,引用缺失);

}

catch(ex ex例外)
{
//回应错误
}
终于
{
//关闭并释放Document对象.
如果(wordDocument!= null)
{
wordDocument.Close(ref paramMissing,ref paramMissing,
ref paramMissing);
wordDocument = null;
}

//退出Word并释放ApplicationClass对象.
如果(wordApplication!= null)
{
wordApplication.Quit(ref paramMissing,ref paramMissing,
ref paramMissing);
wordApplication = null;
}

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

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

}
}


这篇关于将rtf转换为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆