• 大小: 4.81MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-15
  • 语言: C#
  • 标签: c#  pdf  .NET  

资源简介

word转pdf的c#实现 同时发来俺这小白都理解了,发出来共享。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Aspose.Words;
using Aspose.Words.Saving;
using Aspose.Words.Lists;
namespace PicsToPDF
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        #region 选择图片
        private void btnSelectPics_Click(object sender EventArgs e)
        {
            string[] imagesPath;//图片路径数据

            //打开文件
            OpenFileDialog ofd = new OpenFileDialog();
            //ofd.InitialDirectory = “C:“;//默认初始目录
            ofd.Filter = “图片 (*.jpg*.jpeg*.bmp)|*.jpg;*.jpeg;*.bmp“;
            ofd.Multiselect = true;//可以多选文件
            ofd.RestoreDirectory = false;//不还原当前目录,方便下次继续从相同地方添加图片
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                imagesPath = ofd.FileNames;
                if (imagesPath != null && imagesPath.Length < 1)
                    return;

                //将图片加入图片列表
                lbPicAdd(imagesPath);
            }
        }

        ///  将图片加入图片列表 
        private void lbPicAdd(string[] strAdd)
        {
            if (strAdd.Length < 1) return;

            for (int i = 0; i < strAdd.Length; i++)
            {
                lbPic.Items.Add(strAdd[i]);
            }
        }
        #endregion

        #region 转换PDF
        private void btnTurn_Click(object sender EventArgs e)
        {
            //保存PDF的路径
            string savePath = string.Empty;
            //保存文件
            SaveFileDialog sfd = new SaveFileDialog();
            //sfd.InitialDirectory = “C:“;//默认初始目录
            sfd.Filter = “PDF文件 (*.pdf)|*.pdf“;
            sfd.RestoreDirectory = false;//记住保存目录
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                savePath = sfd.FileName;
            }
            if (string.IsNullOrEmpty(savePath)) return;

            //图片转换PDF
            try
            {
                Cursor = Cursors.WaitCursor;
                string[] jpgs = GetPicsPath();//获取列表中已排序的路径数组
                if (jpgs == null || jpgs.Length < 1) { Cursor = Cursors.Default; return; }
                ImagesToPDF.ConvertJPG2PDF(jpgs savePath);
                MessageBox.Show(“转换完成!“ “提示信息“);
            }
            catch (Exception ex)
            {
                MessageBox.Show(“程序出错!错误信息:\r\n“ + ex.Message “提示信息“);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }

        private string[] GetPicsPath()
        {
            string[] pics = new string[lbPic.Items.Count];
            for (int i = 0; i < pics.Length; i++)
            {
                pics[i] = lbPic.GetItemText(lbPic.Items[i]);
            }
            return pics;
        }
        #endregion

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        708  2015-09-28 08:29  PicsToPDF\PicsToPDF\app.config

     文件         10  2015-09-28 08:31  PicsToPDF\PicsToPDF\bin\Debug\.pdf

     文件    8744448  2015-09-28 09:08  PicsToPDF\PicsToPDF\bin\Debug\Aspose.Words.dll

     文件    3538944  2015-09-28 08:32  PicsToPDF\PicsToPDF\bin\Debug\itextsharp.dll

     文件    1550200  2015-09-28 08:32  PicsToPDF\PicsToPDF\bin\Debug\Microsoft.Office.Interop.Excel.dll

     文件    3571020  2015-09-28 08:32  PicsToPDF\PicsToPDF\bin\Debug\Microsoft.Office.Interop.Excel.xml

     文件     386944  2015-09-28 08:31  PicsToPDF\PicsToPDF\bin\Debug\Microsoft.Office.Interop.PowerPoint.dll

     文件         10  2015-09-28 08:31  PicsToPDF\PicsToPDF\bin\Debug\My.pdf

     文件     448360  2015-09-28 08:31  PicsToPDF\PicsToPDF\bin\Debug\office.dll

     文件    1110600  2015-09-28 08:31  PicsToPDF\PicsToPDF\bin\Debug\office.xml

     文件      40960  2015-09-28 08:31  PicsToPDF\PicsToPDF\bin\Debug\OfficeWordAddInsDom.dll

     文件      16896  2015-09-28 09:18  PicsToPDF\PicsToPDF\bin\Debug\PicsToPDF.exe

     文件        708  2015-09-28 08:29  PicsToPDF\PicsToPDF\bin\Debug\PicsToPDF.exe.config

     文件      42496  2015-09-28 09:18  PicsToPDF\PicsToPDF\bin\Debug\PicsToPDF.pdb

     文件      11600  2015-09-28 09:18  PicsToPDF\PicsToPDF\bin\Debug\PicsToPDF.vshost.exe

     文件        708  2015-09-28 08:29  PicsToPDF\PicsToPDF\bin\Debug\PicsToPDF.vshost.exe.config

     文件        490  2010-03-17 22:39  PicsToPDF\PicsToPDF\bin\Debug\PicsToPDF.vshost.exe.manifest

     文件         10  2015-09-28 08:30  PicsToPDF\PicsToPDF\bin\Debug\temp.pdf

     文件       7726  2015-09-28 08:29  PicsToPDF\PicsToPDF\FrmMain.cs

     文件       9276  2015-09-28 08:29  PicsToPDF\PicsToPDF\FrmMain.Designer.cs

     文件       5817  2015-09-28 08:29  PicsToPDF\PicsToPDF\FrmMain.resx

     文件       2550  2015-09-28 08:29  PicsToPDF\PicsToPDF\ImagesToPDF.cs

     文件       1970  2015-09-28 08:31  PicsToPDF\PicsToPDF\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6593  2015-09-28 09:18  PicsToPDF\PicsToPDF\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        310  2015-09-28 09:10  PicsToPDF\PicsToPDF\obj\x86\Debug\GenerateResource.read.1.tlog

     文件        778  2015-09-28 09:10  PicsToPDF\PicsToPDF\obj\x86\Debug\GenerateResource.write.1.tlog

     文件       3975  2015-09-28 08:58  PicsToPDF\PicsToPDF\obj\x86\Debug\PicsToPDF.csproj.FileListAbsolute.txt

     文件       1034  2015-09-28 08:31  PicsToPDF\PicsToPDF\obj\x86\Debug\PicsToPDF.csproj.GenerateResource.Cache

     文件      22800  2015-09-28 08:31  PicsToPDF\PicsToPDF\obj\x86\Debug\PicsToPDF.csprojResolveAssemblyReference.cache

     文件      16896  2015-09-28 09:18  PicsToPDF\PicsToPDF\obj\x86\Debug\PicsToPDF.exe

............此处省略33个文件信息

评论

共有 条评论