简体   繁体   中英

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. At the bottom of the document is a button that says "Download to PDF".

To implement that feature, I am using ABCPdf . I just feed my web page to the library and it spits out a PDF, and it works very well. Almost TOO well in fact - because the PDF includes the "Download" button itself. 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. Then in my page load, I check for that parameter. If it is there, I say "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.

        '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.

I suspect that that system takes the page URL and re-loads it?

Or does some code feed the PDF system a existing page class in code?

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.

Then in your on-page load event, check for that session() value, and simple 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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