'Embedded PDF Viewer in a WinForms Control

I'm trying to embed a pdf viewer in a WinForms Control in such a way that I can display the pdf to the user within the context of my application. I also need to prevent the user from copying text, printing, or saving a copy (sensitive data).

Thus far I've tried using a WebBrowser to host the Acrobat Reader activex control. This gets me close but leaves me with 2 problems.
1. Any pdfs I open seem to stay open from a file handle standpoint until the application shuts down. I've tried calling Dispose() and Navigate() to no avail.
2. I need to disable the toolbar in Reader. I can't set the viewer preferences in the original pdf files but I'm considering using iText to rewrite the files with the preferences set (if I can do that).

I'd also be happy with a well recommended 3rd party library that does this.



Solution 1:[1]

Re: 1. It kind of sucks but you could make a copy of the PDF to the temp folder

Path.GetTempPath()

and open that each time the user needed to see that PDF, so you let Reader lock that file all it wants.

Re: 2. Did you try appending

toolbar=0

to the URL? Ref (and example!) at:

see http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf#toolbar=0

Solution 2:[2]

You can use iText to rewrite the files. I have PDFs created by an external application that I need to email to clients. I use iText to encrypt them and also change the permissions:

Imports iTextSharp.text.pdf ....

Dim reader As PdfReader = New PdfReader(fileName)
PdfEncryptor.Encrypt(reader, New FileStream(mailFileName, FileMode.CreateNew), PdfWriter.STRENGTH128BITS, _
    "password", "password", PdfWriter.AllowCopy Or PdfWriter.ALLOW_PRINTING)

Solution 3:[3]

I'd recommend the WinForms PDF Viewer UI control by DevExpress (a commercial 3rd party UI library). With its comprehensive API, you can prevent the end-user from copying text, printing, saving a copy, etc.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 quimbo
Solution 3 Max