-
May 19th, 2009, 02:43 PM
#1
Thread Starter
Lively Member
[RESOLVED] display a PDF
Anyone know if there is a way to display a PDF file in a WPF application? and not by using a window form control? im trying to avoid that but it looks like that might be the only way...
-
May 19th, 2009, 08:52 PM
#2
Frenzied Member
Re: display a PDF
I believe the only functional method at this time is to use a control host ala: http://hugeonion.com/2009/04/06/disp...f-application/
Is this your pdf or someone else's? The reason I ask is there are some pretty slick examples on the web of rich documents native to WPF.
-
May 20th, 2009, 07:52 AM
#3
Thread Starter
Lively Member
Re: display a PDF
well maybe you might have a better idea. I want to include help files in a WPF application which would be PDF or a word doc i guess. I was hoping to be able to prevent the user from saving the file and printing the file as best as i could. So this would be my pdf, I just wanted to make a custom help interface so it doesnt look like crap compared to the rest of the WPF application. thanks
-
May 20th, 2009, 08:37 AM
#4
Frenzied Member
Re: display a PDF
In WPF there is a huge amount of power over document creation. While it can be comple at first its power is amazing for top notch documents or in your case help files, it also means that these files can be fully intergrated with the look and feel of your application.
The first port of call is to read up about document creation here. Pay paticular attention to the XPS section which is a document format that can be used on word 07 documents. This means you could create all your documents in word and write a tool to convert them to XPS and display them in your wpf application natively.
There is an example of this here in VB.
To be honest though it is probably best to write up a small application to author these files natively in the first place since all the formatting is essentially xaml but have word does give you the flexablity to have very complex help files.
One other thing is although i agree about the saving i would disagree about the ability to print. Most people, like me often print out manuals in order to have them as a reference. If you use any of the document containers you should give the ability to print and if you use a fixed container your helpfiles will look the same on screen and paper. Trust me people will still print the manual even if they have to to so by screen shotting so give them that ability.
-
May 20th, 2009, 08:57 AM
#5
Thread Starter
Lively Member
Re: display a PDF
awesome. this looks like it will be something i will be able to use. Ill look into it. I appreciate your help. Yeah, i agree with you about the printing, but my boss wants to lock down the printing of the help as much as we can to prevent the competitors from getting their hands on what we are doing of course, if theres a will theres a way, but i would like to make it as much of a pain in the ass as possible. Thanks for your help
-
May 20th, 2009, 09:07 AM
#6
Re: display a PDF
Originally Posted by DeanMc
Pay paticular attention to the XPS section which is a document format that can be used on word 07 documents. This means you could create all your documents in word and write a tool to convert them to XPS and display them in your wpf application natively.
You dont need Word 2007 to be able to create XPS documents. I think the XPS printer is automatically installed when you install the Office 2007 compatibility pack (which is a free download). I know I've got it on this PC and I've only got Word 2003 on this machine
-
May 20th, 2009, 09:16 AM
#7
Thread Starter
Lively Member
Re: display a PDF
haha, i was just about to post the question if i needed office 2007. thanks chris, ill look at the compatibility pack.
-
May 20th, 2009, 10:30 AM
#8
Frenzied Member
Re: display a PDF
But will the documents formating persist? I know that the conversion is from .docx to xps for raw workable data in wpf. I suppose a little testing is in order.... care to try chris? It would be interesting to find out.
-
May 20th, 2009, 10:47 AM
#9
Thread Starter
Lively Member
Re: display a PDF
can you guys run that sample that DeanMc posted? I cant get it to run to save my life. I keep getting a COMException: Value out of range. I believe i installed all the XPS prerequisites. but i just cant figure this out... thanks for you help
-
May 20th, 2009, 10:48 AM
#10
Re: display a PDF
When you say 'raw workable data in wpf' what do you mean? I thought your suggestion was to just save some word documents to XPS file format and then just display them in the WPF app, not modify them within the WPF application
-
May 20th, 2009, 11:25 AM
#11
Frenzied Member
Re: display a PDF
I would imagine you get the xps file as a workable stream that you could save as a flow document. Im in work at the moment though so i wont be able to take a good look at it until later.
-
May 20th, 2009, 12:24 PM
#12
Re: display a PDF
oh right, well if thats the case I cant see why it would only be with Word 2007 - at the end of the day surely one XPS format file can be imported/manipulated in the exact same way as any other XPS format file
-
May 20th, 2009, 01:34 PM
#13
Frenzied Member
Re: display a PDF
True but word does have advanced editing features tha can be helpful in the creation of the actual document. I'm going to run some tests now.
-
May 20th, 2009, 02:12 PM
#14
Frenzied Member
Re: display a PDF
Ok I think I've got it!
So here is what you need to do:
1: Get the XPS printer installed.
2: Make help file in program of choice and "print" to XPS printer.
3: Open in your program.
Now here are the cravats....
1: Links don't seem to work although you could have one big helpfile like a PDF to solve this.
2: You cant hide the original documents per say. I would imagine trying to parse out of a database would be a nightmare but lets face it if your competitors really wanted them they would just use a disassembler on your app if they could be embedded.
3:Your kind of stuck with the built in viewing controls from what I can see, there are a view but they look similar to my screeny.
Having said that they are pretty neat. If you wanted complete control over how your help files and truly wanted them internal you could look at hand crafted flow documents. These are essentially Xaml marked text files that could be stored in a DB and parsed on the fly but it would be similar to creating HTML help files IE by hand.
As for the code. Its 1 imports statement and 2 lines of code:
VB Code:
Imports System.Windows.Xps.Packaging
Class Window1
Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
Dim Document As New XpsDocument("C:\\C.xps", IO.FileAccess.Read)
DocumentViewer1.Document = Document.GetFixedDocumentSequence()
End Sub
End Class
you also need to add a reference to ReachFramework.DLL in order to use XPS its in the add reference list though so thats not too much trouble. The document view is simply a control as you can see:
Code:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="389" Width="654">
<Grid>
<DocumentViewer Name="DocumentViewer1" />
</Grid>
</Window>
^ I love my Xaml parsing engine...
Any questions?
-
May 20th, 2009, 02:15 PM
#15
Re: display a PDF
Originally Posted by DeanMc
^ I love my Xaml parsing engine...
haha shameless plug :P but yeah it is good!
As for not being able to hide the XPS documents, couldnt you just store them in the database and download them from there when the user hits the help button? I guess it wouldnt work very well if they are large file sizes though...
-
May 20th, 2009, 02:17 PM
#16
Frenzied Member
Re: display a PDF
Thats what I was thinking, although you could just rename it to .help and im sure it would still read.
-
May 20th, 2009, 02:18 PM
#17
Thread Starter
Lively Member
Re: display a PDF
i just got to that point like probably 10 minutes ago. lol. So looks like we both came to the same conclusion :P I never was aware of this XPS stuff until now, but i really appreciate your help. I'm also going to override the controltemplate to get rid of the copy and print buttons on the document viewer and i think i will be able to not allow selection of the text as well. so that should be locked down enough. if they want to screen capture 100 pages, then they can be my guest thanks alot for both your help.
-
May 20th, 2009, 02:19 PM
#18
Thread Starter
Lively Member
Re: display a PDF
im am going to test the help files over the DB but im not sure how well it will work over the network. some pages have images and stuff on them so it might be slow.
-
May 20th, 2009, 02:23 PM
#19
Frenzied Member
Re: display a PDF
If your overriding the template you could add in a navigation pane, that way you can simply break the files into pages and store them that way in a db. I imagine a page of parsed information would not be that hard on the connection?
-
May 20th, 2009, 02:24 PM
#20
Frenzied Member
Re: display a PDF
I actually had not looked into it either but it essentially means you can have any information that you want in your wpf application providing you can print it which is pretty amazing!
-
May 20th, 2009, 02:25 PM
#21
Re: display a PDF
and you get the XPS printer installed with the office 07 compat pack like I said dont you? Or did you get it from somewhere else?
-
May 20th, 2009, 02:27 PM
#22
Thread Starter
Lively Member
Re: display a PDF
yeah, thats pretty much what im going to do but im going to build it outside of the documentviewer and split up the huge help file into relevant sections. it will be used in a few states across the country so i will have to see. last time when trying to do something like this with images, it did not turn out so well..
-
May 20th, 2009, 02:28 PM
#23
Frenzied Member
Re: display a PDF
Actually I got it after installing Office 07 but yeah you do get it from that way. It's a pity Microsoft doesn't push things like this enough!
-
May 20th, 2009, 02:29 PM
#24
Frenzied Member
Re: display a PDF
Originally Posted by bflosabre91
yeah, thats pretty much what im going to do but im going to build it outside of the documentviewer and split up the huge help file into relevant sections. it will be used in a few states across the country so i will have to see. last time when trying to do something like this with images, it did not turn out so well..
That makes sense and also the power of word would be silly to overlook when it comes to making nice documents!
-
May 20th, 2009, 02:31 PM
#25
Thread Starter
Lively Member
Re: display a PDF
chris- im not sure when the xps printer came up for me but i assume that when it did. but i didnt know it would show up as an actual printer so it took me forever to get to that point.
-
May 20th, 2009, 02:34 PM
#26
Frenzied Member
Re: display a PDF
Ha ha yeah it is a software printer which makes the most confusing sense yet!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|