[英]Highlight words in a pdf using itextsharp, not displaying highlighted word in browser
[英]Displaying a pdf to webpage using iTextSharp?
我正在使用iTextSharp生成pdf。 我想在網頁上顯示它,讓用戶從在線pdf查看器中保存它。 dynamicpdf有drawtoweb()方法,但它不是免費使用,使用iTextSharp的我找不到相同的功能。 我該如何顯示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方法正是它正在做的事情。
更新:
一些研究提出了這樣的解決方案:
將iframe添加到您的網頁:
<IFrame runat="server" id="iframepdf">
</IFrame>
並使用PDF文件填充它:
iframepdf.Attributes.Add("src", "showpdf.ashx?pdf=" + xyz);
請參閱如何<iframe src可以讀取本地臨時文件? 了解更多信息。
我最后只是購買了dynamicpdf的許可證。 使用比itextsharp更容易。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.