简体   繁体   English

HTML 到 PDF:避免在下载的 PDF 中有下载按钮

[英]HTML to PDF: Avoid having the download button in the downloaded PDF

I have an ASP.NET page that generates a document for the user based on parameters in the URL.我有一个 ASP.NET 页面,它根据 URL 中的参数为用户生成一个文档。 At the bottom of the document is a button that says "Download to PDF".文档底部是一个按钮,上面写着“下载为 PDF”。

To implement that feature, I am using ABCPdf .为了实现该功能,我正在使用ABCPdf I just feed my web page to the library and it spits out a PDF, and it works very well.我只是将我的 web 页面提供给库,它会吐出一个 PDF,它工作得很好。 Almost TOO well in fact - because the PDF includes the "Download" button itself.事实上几乎太好了——因为 PDF 本身包含“下载”按钮。 How can I include my entire page EXCEPT that specific button?除了那个特定的按钮,我怎样才能包含我的整个页面?

Here is what I have tried:这是我尝试过的:

In the AddImageToURL call, I added a parameter "&pdfmode" to the URL.AddImageToURL调用中,我向 URL 添加了一个参数“&pdfmode”。 Then in my page load, I check for that parameter.然后在我的页面加载中,我检查那个参数。 If it is there, I say "btnDownloadPDF.Visible=False".如果它在那里,我说“btnDownloadPDF.Visible=False”。 This has no effect.这没有效果。 I tried a similar approach by checking the page.request.form arguments to detect whether the page is posting back because of a click of the button.我通过检查 page.request.form arguments 尝试了类似的方法,以检测页面是否由于单击按钮而回发。

        'This does not work; the PDF still includes the download button
        Dim pbcontrol = GetPostBackControl(Page)
        Dim pdfMode As Boolean =
            (pbcontrol IsNot Nothing AndAlso pbcontrol.ID = "btnDownloadPDF") _
            OrElse (Not String.IsNullOrEmpty(Context.Request.QueryString("pdfmode")))
        If pdfMode Then
            btnDownloadPDF.Visible = False
        End If

Hum, we probably need some details of how, and when the page is sent to that PDF system.嗯,我们可能需要一些关于如何以及何时将页面发送到 PDF 系统的详细信息。

I suspect that that system takes the page URL and re-loads it?我怀疑该系统获取页面 URL 并重新加载它?

Or does some code feed the PDF system a existing page class in code?或者某些代码是否向 PDF 系统提供代码中的现有页面 class?

This suggests?这表明? Hence on your existing page, you need a session() value, (or hidden field) and you have to set that persisted value to "hide" the button.因此,在您现有的页面上,您需要一个 session() 值(或隐藏字段),并且您必须设置该持久值以“隐藏”按钮。

Then in your on-page load event, check for that session() value, and simple go mybutton.visible = false.然后在您的页面加载事件中,检查该 session() 值和简单的 go mybutton.visible = false。 So, that external library probably is feed a page url, and it re-renders the whole page - so in page on-load, you need to hide the button?所以,那个外部库可能是一个页面 url,它重新呈现整个页面 - 所以在页面加载时,你需要隐藏按钮吗?

It just not clear how you hiding that button, but in your code behind, that may well not suffice, since the PDF library is re-loading its OWN copy of the page - hence you need code in the on-load event to hide the button.只是不清楚您如何隐藏该按钮,但在您的代码中,这可能还不够,因为 PDF 库正在重新加载其 OWN 页面副本 - 因此您需要 on-load 事件中的代码来隐藏按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM