最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#實(shí)現(xiàn)word和pdf格式互轉(zhuǎn)

 更新時(shí)間:2024年10月30日 09:40:51   作者:昔舍  
這篇文章主要為大家詳細(xì)介紹了如何通過C#實(shí)現(xiàn)word和pdf格式互轉(zhuǎn)功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下

1、word轉(zhuǎn)pdf

使用nuget:

 Microsoft.Office.Interop.Word

winform頁面:

后端代碼:

//using Spire.Doc;
//using Spire.Pdf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using Aspose.Words;
using Microsoft.Office.Interop.Word;
using System.Windows.Forms;
using Application = Microsoft.Office.Interop.Word.Application;
 
namespace file_operations
{
    public partial class word轉(zhuǎn)PDF : Form
    {
        public word轉(zhuǎn)PDF()
        {
            InitializeComponent();
            //窗體居中
            this.StartPosition = FormStartPosition.CenterScreen;
            //無邊框
            this.FormBorderStyle = FormBorderStyle.None;
            //放大無效
            this.MaximizeBox = false;
            //版權(quán)
            label4.Text = "該應(yīng)用由昔舍版權(quán)所有,如修改源碼請(qǐng)聯(lián)系15574296763@163.com,侵權(quán)后果自負(fù)!!!";
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            if(openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string file = openFileDialog.FileName.ToLower();
                //獲取文件擴(kuò)展名
                string extension = System.IO.Path.GetExtension(file);
                if(extension != ".doc" && extension != ".docx")
                {
                    MessageBox.Show("請(qǐng)選擇word文件", "錯(cuò)誤提示");
                }
                else {
                    textBox1.Text = file;
 
                }
            }
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
           FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
            if(folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                textBox2.Text = folderBrowserDialog.SelectedPath+"\\";
            }
        }
 
        //保存為PDF
        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length == 0 && textBox2.Text.Length == 0 && textBox3.Text.Length ==0)
            {
                MessageBox.Show("請(qǐng)選擇要轉(zhuǎn)換的原文件和要保存的路徑", "錯(cuò)誤提示");
            }
            else
            {
                try
                {
                    //創(chuàng)建一個(gè)word實(shí)例
                    Application wordapp = new Application();
                //創(chuàng)建一個(gè)word文檔對(duì)象,并打開word文件
                Document wordDoc = wordapp.Documents.Open(textBox1.Text);
                    //獲取文件擴(kuò)展名
                    string extension = System.IO.Path.GetExtension(textBox2.Text);
                    //設(shè)置保存路徑,保存文件名稱和文件格式
                    if (extension !=".pdf")
                    {
                        try
                        {
                            string savePath = textBox2.Text + textBox3.Text + ".pdf";
                            wordDoc.SaveAs2(savePath, WdSaveFormat.wdFormatPDF);
                        }
                        catch
                        {
                            MessageBox.Show("請(qǐng)檢查選擇的文件是否有效,保存的路徑是否存在", "錯(cuò)誤提示");
                        }
                    }
                    else
                    {
                        try
                        {
                            string savePath = textBox2.Text + textBox3.Text;
                            wordDoc.SaveAs2(savePath, WdSaveFormat.wdFormatPDF);
                        }
                        catch
                        {
                            MessageBox.Show("請(qǐng)檢查選擇的文件是否有效,保存的路徑是否存在", "錯(cuò)誤提示");
                        }
 
                    }
                    //保存以后打開文件路徑
                    string openfilePath = textBox2.Text;
                    System.Diagnostics.Process.Start(openfilePath);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("請(qǐng)檢查選擇的文件是否有效,保存的路徑是否存在", "錯(cuò)誤提示");
                }
 
            }
        }
 
            private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            PDF轉(zhuǎn)word pDF = new PDF轉(zhuǎn)word();
            //隱藏本窗體
            this.Hide();
            //打開PDF轉(zhuǎn)word
            pDF.Show();
        }
 
        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.Close();
            PDF轉(zhuǎn)word pDF = new PDF轉(zhuǎn)word();
            pDF.Close();
        }
    }
}

2、pdf轉(zhuǎn)word功能實(shí)現(xiàn):

使用nuget:

破解的Spire.pdf

下載地址:crack-spire/手動(dòng)破解Spire.PDF,已破解下載鏈接在底部.md at main · zhjunbai/crack-spire · GitHub

winform頁面:

后端代碼:

using Spire.Pdf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word;
using Application = Microsoft.Office.Interop.Word.Application;
using System.Threading;
 
namespace file_operations
{
    public partial class PDF轉(zhuǎn)word : Form
    {
        public PDF轉(zhuǎn)word()
        {
            InitializeComponent();
            //窗體居中
            this.StartPosition = FormStartPosition.CenterScreen;
            //無邊框
            this.FormBorderStyle = FormBorderStyle.None;
            //放大無效
            this.MaximizeBox = false;
            //版權(quán)
            label4.Text = "該應(yīng)用由昔舍版權(quán)所有,如修改源碼請(qǐng)聯(lián)系15574296763@163.com,侵權(quán)后果自負(fù)!!!";
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            //獲取PDF文件
            OpenFileDialog openFileDialog = new OpenFileDialog();
            if(openFileDialog.ShowDialog() == DialogResult.OK)
            {
                //獲取文件名
                string files = openFileDialog.FileName.ToLower();
                //獲取文件擴(kuò)展名
                string extension = System.IO.Path.GetExtension(files);
                if(extension != ".pdf")
                {
                    MessageBox.Show("請(qǐng)選擇PDF文件", "錯(cuò)誤提示");
                }
                else
                {
                    pdftext.Text = files;
                }
 
            }
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog openFileDialog = new FolderBrowserDialog();
            if(openFileDialog.ShowDialog() == DialogResult.OK) {
                wordPath.Text = openFileDialog.SelectedPath + "\\";
            }
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
 
           //初始化pdfDocument實(shí)例
           PdfDocument doc = new PdfDocument();
            try
            {
                //加載PDF文檔
                doc.LoadFromFile(pdftext.Text);
                //保存為DOC格式文檔
                string savePath = wordPath.Text + wordname.Text + ".DOC";
                doc.SaveToFile(savePath, FileFormat.DOC);
                Thread.Sleep(3000);
                //保存以后打開文件路徑
                string openfilePath = wordPath.Text;
                System.Diagnostics.Process.Start(openfilePath);
            }
            catch
            {
                MessageBox.Show("請(qǐng)確定文件選擇正確", "錯(cuò)誤提示");
            }
        }
 
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.Close();
            word轉(zhuǎn)PDF word = new word轉(zhuǎn)PDF();
            word.Close();
        }
 
        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            word轉(zhuǎn)PDF word = new word轉(zhuǎn)PDF();
            //隱藏本窗體
            this.Hide();
            word.Show();
        }
    }
}

到此這篇關(guān)于C#實(shí)現(xiàn)word和pdf格式互轉(zhuǎn)的文章就介紹到這了,更多相關(guān)C# word和pdf互轉(zhuǎn)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Unity實(shí)現(xiàn)人物旋轉(zhuǎn)和移動(dòng)效果

    Unity實(shí)現(xiàn)人物旋轉(zhuǎn)和移動(dòng)效果

    這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)人物旋轉(zhuǎn)和移動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-01-01
  • C# wpf使用ffmpeg命令行實(shí)現(xiàn)錄屏的示例代碼

    C# wpf使用ffmpeg命令行實(shí)現(xiàn)錄屏的示例代碼

    本文主要介紹了C# wpf使用ffmpeg命令行實(shí)現(xiàn)錄屏的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • C#實(shí)現(xiàn)的調(diào)用DOS命令操作類實(shí)例

    C#實(shí)現(xiàn)的調(diào)用DOS命令操作類實(shí)例

    這篇文章主要介紹了C#實(shí)現(xiàn)的調(diào)用DOS命令操作類,實(shí)例分析了C#調(diào)用系統(tǒng)常用DOS命令的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-04-04
  • C# 拓展方法的簡(jiǎn)單實(shí)例

    C# 拓展方法的簡(jiǎn)單實(shí)例

    這篇文章介紹了C# 拓展方法的簡(jiǎn)單實(shí)例,有需要的朋友可以參考一下
    2013-08-08
  • C#?實(shí)現(xiàn)Excel?打印與頁面設(shè)置功能(從入門到精通)

    C#?實(shí)現(xiàn)Excel?打印與頁面設(shè)置功能(從入門到精通)

    本文介紹了使用Spire.XLSfor.NET組件在C#中實(shí)現(xiàn)Excel文件的打印設(shè)置和靜默打印功能,通過本文的示例代碼,讀者可以快速將這些功能集成到自己的C#項(xiàng)目中,提高辦公效率和文檔的專業(yè)度,感興趣的朋友跟隨小編一起看看吧
    2026-04-04
  • C# 使用Winform 獲取下拉框 選中的值

    C# 使用Winform 獲取下拉框 選中的值

    這篇文章主要介紹了C# 使用Winform 獲取下拉框 選中的值,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • 詳解C#中的out和ref

    詳解C#中的out和ref

    本文主要介紹了out和ref的相關(guān)知識(shí)。具有一定的參考價(jià)值,下面跟著小編一起來看下吧
    2017-01-01
  • C#如何操作Excel數(shù)據(jù)透視表

    C#如何操作Excel數(shù)據(jù)透視表

    這篇文章主要為大家詳細(xì)介紹了C#如何操作Excel數(shù)據(jù)透視表, 創(chuàng)建透視表、設(shè)置行折疊、展開等操作,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • 淺談c# 浮點(diǎn)數(shù)計(jì)算

    淺談c# 浮點(diǎn)數(shù)計(jì)算

    本文通過具體的示例給大家演示了下C#中浮點(diǎn)數(shù)運(yùn)算所遇到的問題及解決方法,有需要的小伙伴可以參考下
    2017-09-09
  • C#中Hashtable和Dictionary的區(qū)別與用法示例

    C#中Hashtable和Dictionary的區(qū)別與用法示例

    由于 Hashtable 和 Dictionary 同時(shí)存在, 在使用場(chǎng)景上必然存在選擇性, 并不任何時(shí)刻都能相互替代。所以這篇文章主要給大家介紹了關(guān)于C#中Hashtable和Dictionary區(qū)別的相關(guān)資料,需要的朋友可以參考下
    2021-05-05

最新評(píng)論

星子县| 盱眙县| 阜新| 万源市| 墨玉县| 禹城市| 定边县| 霍邱县| 周至县| 浦北县| 平乡县| 阿合奇县| 万载县| 普洱| 尤溪县| 司法| 安陆市| 瓮安县| 临沭县| 昂仁县| 泗阳县| 高州市| 花莲市| 鹿邑县| 遂溪县| 奎屯市| 玉门市| 温泉县| 静乐县| 甘泉县| 甘德县| 马边| 紫阳县| 称多县| 沿河| 灵寿县| 东兴市| 开平市| 华容县| 常熟市| 潮安县|