使用asp.net将word文件转换为pdf [英] convert word file to pdf using asp.net

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

问题描述

先生,

我已经制作了一个应用程序,其中我已经使用了word文件,我们可以在word中插入值。我像下面的代码一样创建类文件.'AutomateWord.cs'。

Sir,
I have make an application in which I have taken word file in which we can insert value in word.. I crate class file like.'AutomateWord.cs' as following code.

 public static class Document
    {
        public static bool Process(string strWordDoc, string strPDFDoc, ArrayList dReplacement)
        {
            //A set of objects needed to pass into the calls
            object oMissing = System.Reflection.Missing.Value;
            object oFalse = false;
            object oTrue = true;
            //The variable that will store the return value
            bool bolOutput = true;
            //Creates the needed objects (the application and the document)
            Word._Application oWord;
            Word._Document oDoc;
            //Checks to see if the file does not exist (which would throw an error)
            if (!System.IO.File.Exists(strWordDoc))
            {
                //Since the file does not exist, write out the
                //error to the console and exit
                Console.WriteLine("The file does not exist on the specified        path.");
                return false;
            }

            try
            {
                oWord = new Word.Application();
               
                oWord.Visible = true;
              
                oDoc = oWord.Documents.Open(strWordDoc, oFalse, oTrue);
               
                foreach (Word.Bookmark oRange in oDoc.Content.Bookmarks)
                {
                    for (int i = 0; i < dReplacement.Count; i++)
                    {
                        string[] value = dReplacement[i].ToString().Split(':');

                        if (oRange.Name == value[0].ToString())
                        {
                            oRange.Range.Text = value[1].ToString();
                        }

                    }
                }
               
                oDoc.ExportAsFixedFormat(strPDFDoc, Word.WdExportFormat.wdExportFormatPDF);
               
                bolOutput = true;
            }
            catch (Exception ex)
            {
                //Here is where you put your logging code
                Console.WriteLine(ex.ToString());
                bolOutput = false;
            }
            finally
            { //Releases the objects
                oDoc = null;
                oWord = null;
            }
            return bolOutput;

        }



    }

we use bookmark and replacement of in word file..
   on button click  I have write code as follow..
    
      Dictionary<string,> dkeywords = new Dictionary<string,>();
            /*create object "**date**" in word doc file */
            ArrayList ar = new ArrayList();
            ar.Add("date" + ":" + Label2.Text);
            //ar.Add("date" + ":" + lbldate1.Text);
            /*create object "**company name**" in word doc file */
            ar.Add("id" + ":" + spi);
            /*create object "**customer name**" in word doc file */
            ar.Add("sr" + ":" + srno);
            /*create object "**price1**" in word doc file */
            ar.Add("company" + ":" + TextBox2.Text);
            /*create object "**price2**" in word doc file 
            dkeywords.Add("*Address*", ad);
            dkeywords.Add("*date1*", lbldate1.Text);
            /*create object "**company name**" in word doc file */
            ar.Add("id1" + ":" + spi);
            /*create object "**customer name**" in word doc file */
            ar.Add("sr1" + ":" + srno);
            /*create object "**price1**" in word doc file */
            ar.Add("company1" + ":" + TextBox2.Text);
            /*create object "**price2**" in word doc file */
            ar.Add("address" + ":" + ad);
            ar.Add("address1" + ":" + ad);
            /*create object "**price3**" in word doc file */
            ar.Add("client" + ":" + DropDownList1.Text);
            ar.Add("client1" + ":" + DropDownList1.Text);
            ar.Add("design" + ":" + dec);
            ar.Add("mo" + ":" + spm);
            ar.Add("design1" + ":" + dec);
            ar.Add("mo1" + ":" + spm);
            ar.Add("design2" + ":" + dec);
            ar.Add("mo2" + ":" + spm);
            ar.Add("sign" + ":" + sp);
            ar.Add("sign1" + ":" + sp);
            ar.Add("sign2" + ":" + sp);
            ar.Add("price" + ":" + TextBox9.Text);
            Random randamnumber = new Random();
            int i5 = randamnumber.Next(1, 9000);
           
            sale.Document.Process(Environment.CurrentDirectory + "\\Best Offer - Pinnacle BK3 CNC.doc",
                Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\ Pinnacle BK3 CNC" + Convert.ToInt32(i5) + ".pdf", ar);
            System.Diagnostics.Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\  Pinnacle BK3 CNC" + Convert.ToInt32(i5) + ".pdf");



问题是要面对word文件无法打开&也没有创建pdf,所以给我这个问题的正确解决方案。



谢谢先生


the problem is to face the word file cannot open & also pdf not created,so give me the proper solution for this problem.

Thanks sir

推荐答案





参考此链接

将Word文档转换为ASP.NET服务器上的PDF [ ^ ]



好​​运


refer this link
Convert Word-Documents to PDF on an ASP.NET Server[^]

Best Luck


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

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