tags:

views:

828

answers:

2

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.

+2  A: 

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

Jared Updike
A: 

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)
quimbo