aspose转pdf横版_将pdf文件转换成图片工具源码(Aspose.Pdf)

【实例简介】

第三方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("转换成功");

}

}

}


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部