//1.选择pdf文件
var dialog = new OpenFileDialog();
dialog.Filter = "pdf文件|*.pdf";
var dialogResult = dialog.ShowDialog();
if (dialogResult != System.Windows.Forms.DialogResult.OK)
{
return;
}
//和选择的文件并列创建一个目录
string filePath = dialog.FileName;
string directoryPath = filePath + "目录";
//aspose许可证
Aspose.Pdf.License l = new Aspose.Pdf.License();
string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Pdf.lic");
l.SetLicense(licenseName);
//定义Jpeg转换设备
Aspose.Pdf.Document document = new Aspose.Pdf.Document(filePath);
string path = Path.Combine(directoryPath, string.Format("{0}.pptx", "111"));
document.Save(path,SaveFormat.Pptx);
var device = new Aspose.Pdf.Devices.JpegDevice();
Directory.CreateDirectory(directoryPath);
//默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
device = new Aspose.Pdf.Devices.JpegDevice(100);
//遍历每一页转为jpg
for (var i = 1; i <= document.Pages.Count; i++)
{
string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}.jpg", i));
FileStream fs = new FileStream(filePathOutPut, FileMode.Create);
try
{
foreach (Artifact artifact2 in document.Pages[i].Artifacts)
{
MessageBox.Show(artifact2.Subtype + " " + artifact2.Text + " " + artifact2.Rectangle);
}
//device.Process(document.Pages[i], fs);
Resolution resolution = new Resolution(300);
PngDevice pngDevice = new PngDevice(resolution);
// Convert a particular page and save the image to stream
pngDevice.Process(document.Pages[i], fs);
fs.Close();
}
catch (Exception ex)
{
fs.Close();
File.Delete(filePathOutPut);
}
}
你能否分享一些关于你的问题的更多细节?
在此处附上您的输入、有问题的输出和预期的输出文件以进行测试。 我们将调查该问题并为您提供更多信息。 谢谢你的合作。
PS:要附加这些资源,请压缩并上传它们。