使用iTextSharp将pdf显示到网页? [英] Displaying a pdf to webpage using iTextSharp?
问题描述
我正在使用iTextSharp生成pdf。我想在网页上显示它,让用户从在线pdf查看器中保存它。 dynamicpdf 有一个drawtoweb()方法,但它不能免费使用,我无法使用iTextSharp找到相同的功能。如何显示pdf?
I am generating a pdf using iTextSharp. I would like to display it on the webpage and let the user save it from the online pdf viewer. dynamicpdf has a drawtoweb() method, but it is not free to use and I cannot find the same functionality using iTextSharp. How can I display the pdf?
string newFile = "Pdf Document.pdf";
Document doc = new Document();
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(newFile, FileMode.Create));
doc.AddCreator("Myself");
doc.AddTitle("Sample PDF Document");
doc.Open();
doc.Add(new Paragraph("Hello, World!"));
doc.Close();
推荐答案
有没有理由你不能只显示PDF像任何其他网站一样吗?只需将生成的文件作为具有正确元数据的响应流发送给用户。它将在其默认的PDF查看器中自动打开,最有可能在浏览器中打开。
据我所知, dynamicpdf的DrawToWeb方法正是它正在做的事情。
Is there a reason you can't just display the PDF like any other website does? Just send the generated file to the user as a response stream with the correct meta data. It will open automatically in its default PDF viewer, most likely inside the browser.
As far as I understand the DrawToWeb method of dynamicpdf that's exactly what it is doing.
更新
一些研究提出了这样的解决方案:
在您的网页上添加iframe:
UPDATE:
Some research brought up a solution like this:
Add an iframe to your web page:
<IFrame runat="server" id="iframepdf">
</IFrame>
并用PDF文件填充:
iframepdf.Attributes.Add("src", "showpdf.ashx?pdf=" + xyz);
参见< iframe src如何读取本地临时文件?以获取更多信息。
这篇关于使用iTextSharp将pdf显示到网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!