Monday, September 8, 2008

Arg!

Okay, scratch my last idea. There is no way to access an isolated storage file via a URI, which is what I was kinda counting on. Not sure where to go from here. Everything i find, most people end up just suggesting 'oh, just covert the bytes into a string, and read the string values themselves', but of course, i can't do that if I'm trying to read a .pdf file. I'll still look into this, but it might not be doable without having to write the file temporarily to the computer out in the open. And since they would need the password to open the file anyways, I would simply have to depend on putting the file in an 'odd' place that the user wouldn't look for it, and that is pretty unacceptable security.

Update:
I started looking into Apose.pdf.kit, which worked great with the trial. The software allows you to take a .pdf file, load it into a memorystream, and decode all the pages in the .pdf file into an array of system.drawing.bitmaps. The only issue (for me) was that it takes about 2 seconds to decode each page, so decoding them all up front isn't really practical, you need to decode each page on demand.

The only issue with the software was that it costs around $1700 for the single developer, royalty free license. Jeez.

In the end, we decided to just export the files with adboe writer into images, and just make a tool to view the images as if it was a pdf. I had to write a hook program to disable the printscreen button, but after that, the tool basically does what I want. Still feels like cheating though.

Labels: , , , ,

Friday, September 5, 2008

Viewing a document in memory with WPF

I have to create a tool that displays documents to a user with a memorystream. I decided to try this with wpf, but i was having a lot of trouble with it.

This site was giving me the idea on how to view xps documents through a memorystream, but I was getting a corrupted file error on Package.Open when i tried to read a .doc or .pdf file. The files that I'll be needing to read are mostly .pdf files.

I don't want to make the file available to the users, which is why i'm not just quickly writing the data from it's bytes to a an actual file, and just reading that. I've ended up just deciding to make a compromise with that, and use isolated storage to write the file to, and purge it when the app is done. Feels like a cheat, but I'm not getting many better results.

I integrated a webbrowser with my WPF code using windowsformsintegration:

<WindowsFormsHost>
<winfrm:WebBrowser x:Name="wbBrow"></winfrm:WebBrowser>
</WindowsFormsHost>

I tried playing with the 'documentstream' option on the webbrowser control, but that doesn't work for .pdf files, it just shows gibberish. I also tried using adobe's own COM control, but there is only a "LoadFile" option, which doesn't give me any extra help.

One of the real annoying things about this project is that the pdf file is password protected, and i have no idea how avoid getting the user to type in the password by doing it programmatically.

Labels: , , , , , ,