Results 1 to 26 of 26

Thread: [RESOLVED] display a PDF

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2007
    Posts
    127

    Resolved [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...

  2. #2
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2007
    Posts
    127

    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

  4. #4
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    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.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2007
    Posts
    127

    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

  6. #6
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: display a PDF

    Quote Originally Posted by DeanMc View Post
    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
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 2007
    Posts
    127

    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.

  8. #8
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    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.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jul 2007
    Posts
    127

    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

  10. #10
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  11. #11
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    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.

  12. #12
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  13. #13
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    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.

  14. #14
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    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:
    1. Imports System.Windows.Xps.Packaging
    2.  
    3. Class Window1
    4.  
    5.  
    6.  
    7.     Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
    8.  
    9.         Dim Document As New XpsDocument("C:\\C.xps", IO.FileAccess.Read)
    10.         DocumentViewer1.Document = Document.GetFixedDocumentSequence()
    11.  
    12.     End Sub
    13. 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?

  15. #15
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: display a PDF

    Quote Originally Posted by DeanMc View Post


    ^ 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...
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  16. #16
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: display a PDF

    Thats what I was thinking, although you could just rename it to .help and im sure it would still read.

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Jul 2007
    Posts
    127

    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.

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Jul 2007
    Posts
    127

    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.

  19. #19
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    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?

  20. #20
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    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!

  21. #21
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  22. #22

    Thread Starter
    Lively Member
    Join Date
    Jul 2007
    Posts
    127

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

  23. #23
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    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!

  24. #24
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: display a PDF

    Quote Originally Posted by bflosabre91 View Post
    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!

  25. #25

    Thread Starter
    Lively Member
    Join Date
    Jul 2007
    Posts
    127

    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.

  26. #26
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    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
  •  



Click Here to Expand Forum to Full Width