asp.net 导出为pdf文档

林g 2012-11-22 11:40:12
如题.最好有实例做过的.网上找到的资料不是很全,两个文件下载引用进去了,调用报错.
比较急,才到这里发贴找.

请有做过这样导出的高手帮忙.

谢谢大家!
...全文
396 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
你是要把网面导出pdf格式?
林g 2012-11-27
  • 打赏
  • 举报
回复
引用 15 楼 yu94285572 的回复:
iTextSharp 用这个
你说的这个我在网上找了资料下来弄,结果没有弄出来.现在是可以实现功能的方法我的都愿意去试 谢谢
林g 2012-11-27
  • 打赏
  • 举报
回复
引用 13 楼 yannis_lin 的回复:
引用 12 楼 jlingang 的回复:引用 11 楼 yannis_lin 的回复:你在导出的时候先进如这个类里面转换 首先写个判断 如果已经有PDF文件 就执行导出那个操作 没有就去生成PDF文件 在导出 根据你贴上来的代码.我无法调试成功,能不能贴一个完整的列子呢,我人比较笨, 谢谢! ? 哪里有错?
public static bool PPTConvert(DocInf doc) 这里传递进去的参数类型?我不知道怎么去新建, 你说应用进去的dll已经引用进去
  • 打赏
  • 举报
回复
ABCpdf.dll 下载这个dll放到bin文件夹里面

给你个代码参考

using WebSupergoo.ABCpdf6;
using System.Text.RegularExpressions;
using System.IO;



public void getPdf(string pdf, string name, string group)
{
Random r = new Random();
Doc theDoc = new Doc();
theDoc.TopDown = true;
theDoc.Rect.String = "40 50 990 1450";//控制显示的大小205 300 632 895
theDoc.MediaBox.String = "0 0 990 1500";//控制页面的大小
string reg = @"\<a id\=(.)+\</a\>";//这段正则主要是去掉页面中自己不需要显示的东西
string reg1 = @"body\{(.)+\}";
string temp =Regex.Replace(Regex.Replace(getHtml(pdf), reg1, ""), reg, "");
temp = temp.Replace("","");

int theID = theDoc.AddImageHtml(temp, true, 0, false);
while (true)
{
if (!theDoc.Chainable(theID))
{
break;
}
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
}
byte[] theData = theDoc.GetData();
FileCreate(name, theData);
if (File.Exists(HttpContext.Current.Server.MapPath("/uploads/pdfFile/" + name + ".pdf")))
{
Response.Redirect("/uploads/"+name+".pdf");
}
else
{
//对不起,文件未找到
}
}

yannis_lin 2012-11-27
  • 打赏
  • 举报
回复
引用 17 楼 jlingang 的回复:
引用 13 楼 yannis_lin 的回复:引用 12 楼 jlingang 的回复:引用 11 楼 yannis_lin 的回复:你在导出的时候先进如这个类里面转换 首先写个判断 如果已经有PDF文件 就执行导出那个操作 没有就去生成PDF文件 在导出 根据你贴上来的代码.我无法调试成功,能不能贴一个完整的列子呢,我人比较笨, 谢谢! ? 哪……
…… 这个是一个类啊 亲 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Toppine.DM.Logic { public class DocInf { private String filename = ""; private String type = ""; private String uploadPath=""; private String id = ""; public String Id { get { return id; } set { id = value; } } public String UploadPath { get { return uploadPath; } set { uploadPath = value; } } public String Filename { get { return filename; } set { filename = value; } } public String Type { get { return type; } set { type = value; } } } } 你把这个类改一下吧
林g 2012-11-27
  • 打赏
  • 举报
回复
引用 19 楼 yu94285572 的回复:
你是要把网面导出pdf格式?
是的,网页的数据导出为PDF文档,我在网络上找了几个,英语差,没有调试出一个导出. 一个显示数据页面,然后导出成一个PDF文件.b/s架构的程序.
  • 打赏
  • 举报
回复
iTextSharp 用这个
yannis_lin 2012-11-26
  • 打赏
  • 举报
回复
引用 12 楼 jlingang 的回复:
引用 11 楼 yannis_lin 的回复:你在导出的时候先进如这个类里面转换 首先写个判断 如果已经有PDF文件 就执行导出那个操作 没有就去生成PDF文件 在导出 根据你贴上来的代码.我无法调试成功,能不能贴一个完整的列子呢,我人比较笨, 谢谢!
? 哪里有错?
林g 2012-11-26
  • 打赏
  • 举报
回复
引用 11 楼 yannis_lin 的回复:
你在导出的时候先进如这个类里面转换 首先写个判断 如果已经有PDF文件 就执行导出那个操作 没有就去生成PDF文件 在导出
根据你贴上来的代码.我无法调试成功,能不能贴一个完整的列子呢,我人比较笨, 谢谢!
yannis_lin 2012-11-23
  • 打赏
  • 举报
回复
你在导出的时候先进如这个类里面转换 首先写个判断 如果已经有PDF文件 就执行导出那个操作 没有就去生成PDF文件 在导出
yannis_lin 2012-11-23
  • 打赏
  • 举报
回复
引用 9 楼 jlingang 的回复:
引用 8 楼 yannis_lin 的回复:引用 7 楼 jlingang 的回复:引用 6 楼 yannis_lin 的回复:要实现你那个效果你可以先这样 在点击导出的时候 先把该文件转换成PDF格式 在将其导出去 导出的话你应该会吧 你觉得可以咱在接着说 首先谢谢你提供的思路. 我这个是直接把浏览的页面转换成pdf文件导出,你说的这个思路也……
先引用 using Word = Microsoft.Office.Interop.Word; using Excel = Microsoft.Office.Interop.Excel; using PowerPoint = Microsoft.Office.Interop.PowerPoint; public static bool DOCConvert(DocInf doc) { bool result; String DOCtargetPath =doc.UploadPath; //这里都是完整路径 String PDFtargetPath = DMCommonInfo.ConvertPDFPath + doc.Id + ".pdf"; Object paramMissing = Type.Missing; Word.ApplicationClass wordApplication = new Word.ApplicationClass(); Word._Document wordDocument = null; try { Object paramSourceDocPath = DOCtargetPath; String paramExportFilePath = PDFtargetPath; Word.WdExportFormat paramExportFormat = Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF; bool paramOpenAfterExport = false; Word.WdExportOptimizeFor paramExportOptimizeFor = Word.WdExportOptimizeFor.wdExportOptimizeForPrint; Word.WdExportRange paramExportRange = Word.WdExportRange.wdExportAllDocument; Int32 paramStartPage = 0; Int32 paramEndPage = 0; Word.WdExportItem paramExportItem = Word.WdExportItem.wdExportDocumentContent; bool paramIncludeDocProps = true; bool paramKeepIRM = true; Word.WdExportCreateBookmarks paramCreateBookmarks = Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks; bool paramDocStructureTags = true; bool paramBitmapMissingFonts = true; bool paramUseISO19005_1 = false; wordDocument = wordApplication.Documents.Open( ref paramSourceDocPath, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing); if (wordDocument != null) wordDocument.ExportAsFixedFormat(paramExportFilePath, paramExportFormat, paramOpenAfterExport, paramExportOptimizeFor, paramExportRange, paramStartPage, paramEndPage, paramExportItem, paramIncludeDocProps, paramKeepIRM, paramCreateBookmarks, paramDocStructureTags, paramBitmapMissingFonts, paramUseISO19005_1, ref paramMissing); result = true; } finally { if (wordDocument != null) { wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing); wordDocument = null; } if (wordApplication != null) { wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing); wordApplication = null; } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } return result; } public static bool XLSConvert(DocInf doc) { bool result; String XLStargetPath = doc.UploadPath; String PDFtargetPath = DMCommonInfo.ConvertPDFPath + doc.Id + ".pdf"; Object missing = Type.Missing; Excel.ApplicationClass application = null; Excel.Workbook workBook = null; try { application = new Excel.ApplicationClass(); Object target = PDFtargetPath; Excel.XlFixedFormatType type = Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF; workBook = application.Workbooks.Open(XLStargetPath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); workBook.ExportAsFixedFormat(type, target, Excel.XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing); result = true; } catch { result = false; } finally { if (workBook != null) { workBook.Close(true, missing, missing); workBook = null; } if (application != null) { application.Quit(); application = null; } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } return result; } public static bool PPTConvert(DocInf doc) { bool result; String PPTtargetPath = doc.UploadPath; String PDFtargetPath = DMCommonInfo.ConvertPDFPath + doc.Id + ".pdf"; Object missing = Type.Missing; PowerPoint.PpSaveAsFileType FileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPDF; PowerPoint.Presentation persentation = null; PowerPoint.Application application = null; try { application = new PowerPoint.ApplicationClass(); persentation = application.Presentations.Open(PPTtargetPath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); persentation.SaveAs(PDFtargetPath, FileType, Microsoft.Office.Core.MsoTriState.msoTrue); result = true; } catch { result = false; } finally { if (persentation != null) { persentation.Close(); persentation = null; } if (application != null) { application.Quit(); application = null; } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } return result; }
林g 2012-11-23
  • 打赏
  • 举报
回复
引用 8 楼 yannis_lin 的回复:
引用 7 楼 jlingang 的回复:引用 6 楼 yannis_lin 的回复:要实现你那个效果你可以先这样 在点击导出的时候 先把该文件转换成PDF格式 在将其导出去 导出的话你应该会吧 你觉得可以咱在接着说 首先谢谢你提供的思路. 我这个是直接把浏览的页面转换成pdf文件导出,你说的这个思路也是可以,就是要把当前的页面做为文件存在服务器……
你说的这个完全可以满足我所需要做的功能,能提供一下代码么.具体如何去实现? 谢谢!
attidust 2012-11-22
  • 打赏
  • 举报
回复
有一个iText,如果是Office系列转PDF,好像微软有一个这样的类,是可以直接用的。 见: http://bbs.csdn.net/topics/390111871
yannis_lin 2012-11-22
  • 打赏
  • 举报
回复
引用 7 楼 jlingang 的回复:
引用 6 楼 yannis_lin 的回复:要实现你那个效果你可以先这样 在点击导出的时候 先把该文件转换成PDF格式 在将其导出去 导出的话你应该会吧 你觉得可以咱在接着说 首先谢谢你提供的思路. 我这个是直接把浏览的页面转换成pdf文件导出,你说的这个思路也是可以,就是要把当前的页面做为文件存在服务器上,然后通过软件转换成pdf的格式文件.……
思路的话呢 大概就是这个样子了 我前面做的那个在线浏览 其实跟你这个也差不多 我那个也是点击页面的某个文件 然后转换成PDF 在转换成SWF 最后在线时出来 你 这里的话只需要转换成PDF就可以 我那个转换是用的office组件
林g 2012-11-22
  • 打赏
  • 举报
回复
引用 6 楼 yannis_lin 的回复:
要实现你那个效果你可以先这样 在点击导出的时候 先把该文件转换成PDF格式 在将其导出去 导出的话你应该会吧 你觉得可以咱在接着说
首先谢谢你提供的思路. 我这个是直接把浏览的页面转换成pdf文件导出,你说的这个思路也是可以,就是要把当前的页面做为文件存在服务器上,然后通过软件转换成pdf的格式文件. 与一楼的方法有些相似. 能否把你后面的思路也说一些呢,也可以给我做个参考!
yannis_lin 2012-11-22
  • 打赏
  • 举报
回复
要实现你那个效果你可以先这样 在点击导出的时候 先把该文件转换成PDF格式 在将其导出去 导出的话你应该会吧 你觉得可以咱在接着说
蝶恋花雨 2012-11-22
  • 打赏
  • 举报
回复
http://bbs.csdn.net/topics/380188529 下载参考下
林g 2012-11-22
  • 打赏
  • 举报
回复
引用 1 楼 attidust 的回复:
有一个iText,如果是Office系列转PDF,好像微软有一个这样的类,是可以直接用的。 见: http://bbs.csdn.net/topics/390111871
我这边不是excel的文件转为pdf文档,是从当前浏览的页面导出为pdf文档.这个好像有点麻烦. 谢谢你提供的信息.
林g 2012-11-22
  • 打赏
  • 举报
回复
引用 2 楼 leexiaochong 的回复:
看看我们网站上面的例子吧,http://www.transecho.com/Whatman-Grade-No-2-Filter-Paper-Whatman-1002125_p0_617288_1.html 点击Down Load PDF链接就会将产品信息导出为pdf供用户下载使用.
你好!能否提供一下实现的代码? 谢谢
李小冲 2012-11-22
  • 打赏
  • 举报
回复
看看我们网站上面的例子吧,http://www.transecho.com/Whatman-Grade-No-2-Filter-Paper-Whatman-1002125_p0_617288_1.html
点击Down Load PDF链接就会将产品信息导出为pdf供用户下载使用.

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧