基本信息
源码名称:将pdf文件转换成图片工具源码(Aspose.Pdf)
源码大小:18.92M
文件格式:.zip
开发语言:C#
更新时间:2018-07-13
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
第三方dll 对pdf进行截图,并将每页的截图 保存成图片
using Aspose.Pdf;
using Aspose.Pdf.Devices;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PDFTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Aspose.Pdf.License li = new Aspose.Pdf.License();
string path = Application.StartupPath "\\License.lic";
li.SetLicense(path);
string sPath = Application.StartupPath "\\test.pdf";
string imageOutputDirPath = Application.StartupPath "\\";
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(sPath);
int resolution = 700;//像素大小 128-1024
if (doc == null)
{
throw new Exception("pdf文件无效或者pdf文件被加密!");
}
if (imageOutputDirPath.Trim().Length == 0)
{
imageOutputDirPath = Path.GetDirectoryName(sPath);
}
if (!Directory.Exists(imageOutputDirPath))
{
Directory.CreateDirectory(imageOutputDirPath);
}
//开始页
int startPageNum = 1;
//结束页
int endPageNum = doc.Pages.Count;
//
if (startPageNum > endPageNum)
{
int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum;
}
string imageNamePrefix = Path.GetFileNameWithoutExtension(sPath);
for (int i = startPageNum; i <= endPageNum; i )
{
MemoryStream stream = new MemoryStream();
string imgPath = Path.Combine(imageOutputDirPath, imageNamePrefix) "_" i.ToString("000") ".jpg";
Aspose.Pdf.Devices.Resolution reso = new Aspose.Pdf.Devices.Resolution(resolution);
Aspose.Pdf.Devices.JpegDevice jpegDevice = new Aspose.Pdf.Devices.JpegDevice(reso, 100);
jpegDevice.Process(doc.Pages[i], stream);
System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
Bitmap bm = new Bitmap(img);
bm.Save(imgPath, ImageFormat.Jpeg);
img.Dispose();
stream.Dispose();
bm.Dispose();
}
MessageBox.Show("转换成功");
}
}
}