项目中需要这么一个功能:将pdf 文件转化为Image或者Html的形式(变态,但是没办法)
几经努力,搞了个大概,利用PdfSharp和 Ghostscript 完成,最终转换的是图片
但是存在几个问题
1、速度问题,忒慢
2、版本问题,貌似pdf 版本过高的话,有iref 流的异常。虽然可以利用iTextSharp转换,但是忒麻烦!
3、转换的图片不是十分清晰adobe acrobat 转换的图片十分清晰,而且速度可以。但是没有找到相关的文档。
冰天雪地裸体跪求 : 曾经接触过或者现在正在搞这方面的大虾,希望不吝赐教!谢谢!传说中的分不是问题!
解决方案 »
- 如何让生成的winform无法拉伸窗口大小。
- 读取JPG图片的文字信息
- 控件名中有变量名 如何书写
- 非连接插入数据问题
- 急,c#读写cookie的问题
- 刚装老个WIN2008
- winform中如何判断picturebox中的image为空
- ///<summary>的注释问题
- 用Response.Redirect("WebForm2.aspx");可以指向WebForm2,请问如何使WebForm2在一个新的窗口中打开?
- 请问C#中有类似VB中RaiseEvent触发事件的东西吗
- Process.Start函数启动带参数的控制台程序,参数内部带空格怎么办?
- 这个连接access数据库的方法有什么错误。
my blog
http://ufo-crackerx.blog.163.com/
问题依旧……试了试其他的方法
多半是需要在客户端安装或者注册组件的
在网上看到一个Ap PDF to IMAGE batch 的小软件.1.3M
做出来的效果非常好,而且也提供了sdk!奈何是收费软件(不要跟我讲买…………)
有研究的达人还不快快现身,更待何时??
doc.Open(@"d:\test.pdf", ""); // 要转换的pdf文件object js = (doc.GetPDDoc() as Acrobat.AcroPDDoc).GetJSObject();object[] args = { @"d:\test.jpg", "com.adobe.acrobat.jpeg", "", false, false }; // 要生成的图片名称
js.GetType().InvokeMember("SaveAs", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, js, args);
说的是 adultpdf 产品?呵呵呵,它是非常简单去掉水印
my blog
http://ufo-crackerx.blog.163.com/
acrobat的sdk 里面就是这么搞的。有没有不用装东西的?
贴上现在使用的笨方法的代码,提供大家探讨下!
PDFConvert converter = new PDFConvert();
private void PdfConvert(string FileName, string SavePath)
{
if (!System.IO.File.Exists(Application.StartupPath + "\\gsdll32.dll"))
{
MessageBox.Show("系统缺少gsdll32.dll,请检查系统!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
//检查版本
GhostScriptRevision version = converter.GetRevision();
ConvertSingleImage(FileName, SavePath);
}private void ConvertSingleImage(string filename, string SavePath)
{
bool Converted = false;
string filePath = SavePath;
converter.RenderingThreads = 2;
converter.OutputToMultipleFile = true;
converter.FitPage = false;
converter.JPEGQuality = 100; //质量(0-100)
converter.OutputFormat = "jpeg";
System.IO.FileInfo input = new FileInfo(filename);
string output = SavePath + @"\pdf.jpg";
PdfSharp.Pdf.PdfDocument pdfDoc;
int iPdfPageCount = 0;
try
{
pdfDoc = PdfSharp.Pdf.IO.PdfReader.Open(filename);
}
catch (PdfSharp.Pdf.IO.PdfReaderException)
{
filename = WriteCompatiblePdf(filename, SavePath+@"\newPdf.pdf");
pdfDoc = PdfSharp.Pdf.IO.PdfReader.Open(filename);
}
iPdfPageCount = pdfDoc.PageCount; //页数
Converted = converter.Convert(input.FullName, output); //给我转
}//转换不能识别的pdf (itextpdf)
private string WriteCompatiblePdf(string sFilename, string sNewPdf)
{
iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(sFilename);
int n = reader.NumberOfPages;
iTextSharp.text.Document document = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(1));
iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new System.IO.FileStream(sNewPdf, System.IO.FileMode.Create));
//转换版本
writer.SetPdfVersion(iTextSharp.text.pdf.PdfWriter.PDF_VERSION_1_4);
document.Open();
iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
iTextSharp.text.pdf.PdfImportedPage page;
int rotation;
int i = 0;
while (i < n)
{
i++;
document.SetPageSize(reader.GetPageSizeWithRotation(i));
document.NewPage();
page = writer.GetImportedPage(reader, i);
rotation = reader.GetPageRotation(i);
if (rotation == 90 || rotation == 270)
{
cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height);
}
else
{
cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
}
}
document.Close();
return sNewPdf;
}
太多了不贴了……方法笨 ,质量还不好!
具体的补贴了,大概就是调用PdfSharp和Ghostscript 来搞的
搞法估计是没希望了!
你设定的限定条件太多了,Ghostscript已经是比较流行的free组件,你又不希望用付费的组件,还不要在客户端上装东西权衡取舍一下吧