本文介绍了我正在尝试下载带有照片的身份证的pdf文件,但没有打开pdf,其显示错误“无法加载PDF文档。”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HttpContext.Current.Response.Clear();

HttpContext.Current.Response.AddHeader

(Content-Disposition,attachment; filename = iTextSharpExample。 pdf);

HttpContext.Current.Response.Charset =;

HttpContext.Current.Response.ContentType =application / pdf;

StringWriter stringwrite = new StringWriter();

HtmlTextWriter htmlwrite = new HtmlTextWriter(stringwrite);

dvText.RenderControl(htmlwrite);

StringReader sr = new StringReader(stringwrite.ToString());

文件pdfDoc =新文件(PageSize.A4,50,50,25,25);

PdfWriter writer = PdfWriter.GetInstance(pdfDoc,Response.OutputStream);

HTMLWorker htmlparser = new HTMLWorker(pdfDoc);



什么我试过了:



我正在尝试下载带有照片的身份证的pdf文件,但没有打开pdf它的显示错误无法加载PDF文档。

解决方案

您已经在 []


HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader
("Content-Disposition", "attachment;filename=iTextSharpExample.pdf");
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/pdf";
StringWriter stringwrite = new StringWriter();
HtmlTextWriter htmlwrite = new HtmlTextWriter(stringwrite);
dvText.RenderControl(htmlwrite);
StringReader sr = new StringReader(stringwrite.ToString());
Document pdfDoc = new Document(PageSize.A4, 50, 50, 25, 25);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

What I have tried:

I am trying to download pdf file of ID Card with photo but not open the pdf its shoing error "Failed to load PDF document."

解决方案
You already posted this question at When download ID card pdf file on button click using above code showing error as access to the path 'C:\' is denied....[^]


这篇关于我正在尝试下载带有照片的身份证的pdf文件,但没有打开pdf,其显示错误“无法加载PDF文档。”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 09:35