将Word文件转换为pdf [英] convert word file into pdf

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

问题描述

我有一个应用程序,我在其中上传了一个Word文件,当我单击按钮时,它将转换为pdf文件.我也尝试过itextsharp,但也没有得到确切的代码.有谁能帮助我使用itextsharp或任何其他方法解决此问题?预先谢谢您...

i have an application in which i upload a word file and when i click on button it''ll convert it into pdf file. I also tried itextsharp but not getting exact code for that also. Can any one help me to solve this using itextsharp or any other method?? Thank you in advance...

推荐答案

我认为_A_K_建议您写一篇好文章

您也可以使用在线API,即我建议使用Restfull服务 http://www.convertapi.com /api/word-pdf-api .

下面的控制台应用程序示例也可以在ASP.NET应用程序中使用.
I think the _A_K_ suggested you a good article

You can also to use online API, ie I would like to suggest the Restfull service http://www.convertapi.com/api/word-pdf-api.

A following console app example below can be used in ASP.NET applications too.
using System;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Threading;
using System.Windows.Forms;

namespace Word2Pdf
{
    class Program
    {
        [STAThreadAttribute]
        static void Main(string[] args)
        {

            using (var client = new WebClient())
            {
                Console.WriteLine("Please choose a Word document to convert to PDF.");

                var openFileDialog = new OpenFileDialog {Filter = 
"Word document(*.doc;*.docx)|*.doc;*.docx"};
                if (openFileDialog.ShowDialog()!=DialogResult.OK) return;                               
                var fileToConvert = openFileDialog.FileName;

                Console.WriteLine(string.Format("Converting the file {0} Please wait.", fileToConvert));

                var data = new NameValueCollection();               
                data.Add("OutputFileName", "MyFile.pdf"); 

                try
                {                    
                    client.QueryString.Add(data);
                    var response = 
client.UploadFile("http://do.convertapi.com/word2pdf", fileToConvert);
                    var responseHeaders = client.ResponseHeaders;
                    var web2PdfOutputFileName = responseHeaders["OutputFileName"];
                    var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), web2PdfOutputFileName);
                    File.WriteAllBytes(path, response);
                    Console.WriteLine("The conversion was successful! The word file {0} converted to PDF and saved at {1}", fileToConvert, path);
                }
                catch (WebException e)
                {
                    Console.WriteLine("Exception Message :" + e.Message);
                    if (e.Status == WebExceptionStatus.ProtocolError)
                    {
                        Console.WriteLine("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode);
                        Console.WriteLine("Status Description : {0}", ((HttpWebResponse)e.Response).StatusDescription);
                    }

                }


            }

            Console.ReadLine();
        }
    }
}




或者,您也可以通过Spire.Doc( http://www.e-iceblue.com/Introduce/word-for-net-introduce.html [




Or you can also to convert document of Word to PDF by Spire.Doc (http://www.e-iceblue.com/Introduce/word-for-net-introduce.html[^]), for example:

Spire.Doc.Document doc = new Spire.Doc.Document("my document.doc/docx")
doc.SaveToFile("pdf document.pdf", Spire.Doc.FileFormat.PDF);


Spire.Doc是MS Word组件,它使用户能够直接执行各种Word文档处理任务,例如为.NET生成,读取,写入和修改Word文档.它支持C#,VB.NET,ASP.NET,ASP.NET和MVC.


Spire.Doc is an MS Word component which enables user to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document for .NET. It supports C#, VB.NET, ASP.NET, ASP.NET and MVC.


此功能将帮助您做到这一点:
_Document.ExportAsFixedFormat方法 [使用C#将Word文档导出为PDF [使用C#将.xls,.doc文件转换为PDF [ ^ ]
将word文档转换为pdf [ ^ ]
和此CP文章使用C#(和Office)从RTF/DOC文件创建PDF [ ^ ]可能会对您有所帮助.

这是一个简单的示例,您可以从中得到很多.
如何以编程方式将Word文件转换为PDF? [ ^ ]

尝试在 CodeProject质量检查上进行搜索 [ CodeProject文章 [
This function will help you to make it:
_Document.ExportAsFixedFormat Method[^]

Here is an example:
Export Word Documents to PDF with C#[^]

Also have a look at some similar threads:
Convert .xls,.doc files to PDF with C#[^]
Convert word doc to pdf[^]
and this CP article PDF creation using C# (and Office) from RTF/DOC files[^] might help you.

Here is simple example where you get a lot of it.
How do I convert Word files to PDF programmatically?[^]

Try a search on CodeProject QA[^] & CodeProject Articles[^] on same.



请参考链接:
在ASP上将Word-Documents转换为PDF. NET服务器 [
Hi,
Refer the link:
Convert Word-Documents to PDF on an ASP.NET Server[^]

All the best.
--Amit


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

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