none
How to display a PDF document in a Microsoft Surface application?

    Question

  • I want to display a PDF document in my Microsoft Surface application. I did some searching and found a lot of possibilities, but all of the seem to have a little drawback if used in Microsoft Surface.

    This insteresting approach (http://www.screencast.com/users/chujanen/folders/Jing/media/e313edbb-e09f-4df6-a4ed-f953e58701ad) seems nice, but I have trouble to check how to enable scrolling.



    Any idea how to enable scrolling in there?
     
    Thursday, February 17, 2011 8:06 AM

Answers

  • AcroRd32.exe /p filename - Executes the Reader and prints a file..
     
    Hope this helps.
     
    Bye,

    Bart Roozendaal, Sevensteps
    http://www.sevensteps.com
    Microsoft MVP for Microsoft Surface


    "Roflcoptr" wrote in message news:b47db339-1c20-49c1-b7ca-42d9d293d06c...
    Yes that would also be a possibility for me. In most cases I have only to convert 1 PDF, so it would be quite easy. However I couldn't found a documentation how to do that with acrobat while googling. Is there a *.dll I can add?

    Bart Roozendaal, Sevensteps
    Saturday, February 19, 2011 12:50 PM

All replies

  • Hi!

    That example is using a WindowsFormsHost so the Acrobat reader is hosted in a separate HWND. Contact/Touch events in Surface SDK 1.0 are a layer on top of the default windows input stack and the folks at Adobe didn't implement Surface 1.0 support for their Acrobat control. You would need to create a ContactTarget (available in the Microsoft.Surface.Core assembly) for the Acrobat HWND and transform the Contact events into something that the Acrobat control API understands.

    I wouldn't recommend this approach though since HWNDs can't be rotated, so the Acrobat control doesn't really fit Surface computing (360 degree UI specifically). A "better" way would be to either convert the PDFs to bitmaps before loading the pages, or to use some kind of render-to-bitmap technique (not sure if there is one available), in order to get the 360 degree UI and avoid Win32 interop.

    Good luck!

    /Sebastian


    Sebastian Hartman Touchtech AB http://www.touchtech.se
    Thursday, February 17, 2011 4:53 PM
  • Ok thanks. This seems to be more complicated than I thought. Do you know if it would simplify my task if I could use ps file instead of pdf?

     

    And concerning your approach to create bitmaps first: Would this project (http://www.codeproject.com/KB/showcase/pdfrasterizer.aspx) be useful?

    Thursday, February 17, 2011 5:25 PM
  • you may want to try using the WPF documentViewer control -Here is the link on how to surface enable it:

    http://fyeomans.com/2010/05/04/displaying-an-xps-document-on-the-microsoft-surface/

    Thursday, February 17, 2011 7:07 PM
  • Thanks a lot! This works perfectly well for XPS documents but unfortunately not for PDF. Are there easy ways to convert PDF 2 XPS? Or is it also possible to generate XPS file with ITextSharp? All PDFs i want to display are generated in the same application using ITextSharp
    Thursday, February 17, 2011 9:13 PM
  • Hi Roflcoptr!

    You can use Ghostscript to generate images from a PDF file and then read those images into your WPF app the usual way.

    Imagemagick should also be able to create images from PDFs and maybe you can use the .NET API to decode the PDF in runtime? Otherwise I know that you can use convert.exe from ImageMagick to convert PDFs to PNGs.

    /Sebastian


    Sebastian Hartman Touchtech AB http://www.touchtech.se
    Friday, February 18, 2011 4:57 PM
  • What we do, is very pragmatic:
    1) Start a batch file printing all PDFs to XPS files using Acrobat rader
    2) Use the generated XPS files as content for one of the RichTextViewers available
     
    Sometimes you want the XPS files generated at real time, but that scenario doesn’t come up very often. Could be done of course, but gives a bit more hassle and adds to the waiting time for the user.
     
    The above scenario works 99.9% of the times and works great. Some special PDF-features might nog be supported by printing to XPS, but again, that almost never happens.
     
    Hope this helps.

    Bart Roozendaal, Sevensteps
    http://www.sevensteps.com
    Microsoft MVP for Microsoft Surface


    "Roflcoptr" wrote in message news:69262cdb-4695-4618-a0f1-9424e44aca59...
    Thanks a lot! This works perfectly well for XPS documents but unfortunately not for PDF. Are there easy ways to convert PDF 2 XPS? Or is it also possible to generate XPS file with ITextSharp? All PDFs i want to display are generated in the same application using ITextSharp

    Bart Roozendaal, Sevensteps
    Saturday, February 19, 2011 11:53 AM
  • Yes that would also be a possibility for me. In most cases I have only to convert 1 PDF, so it would be quite easy. However I couldn't found a documentation how to do that with acrobat while googling. Is there a *.dll I can add?
    Saturday, February 19, 2011 12:48 PM
  • AcroRd32.exe /p filename - Executes the Reader and prints a file..
     
    Hope this helps.
     
    Bye,

    Bart Roozendaal, Sevensteps
    http://www.sevensteps.com
    Microsoft MVP for Microsoft Surface


    "Roflcoptr" wrote in message news:b47db339-1c20-49c1-b7ca-42d9d293d06c...
    Yes that would also be a possibility for me. In most cases I have only to convert 1 PDF, so it would be quite easy. However I couldn't found a documentation how to do that with acrobat while googling. Is there a *.dll I can add?

    Bart Roozendaal, Sevensteps
    Saturday, February 19, 2011 12:50 PM
  • Thanks. So you use the print command to print the pdf with the Microsoft XPS writer?
    Sunday, February 20, 2011 2:02 PM
  • Yes, indeed....
    Bart Roozendaal, Sevensteps
    Sunday, February 20, 2011 2:04 PM
  • Ok I was able to do that, but how do you solve the problem that the MIcrosoft XPS Document Writer asks the user to enter a filename where to store the new xps file?
    Sunday, February 20, 2011 2:37 PM
  • I’m checking this with my team. Hang on for the answer.... (not sure how they done that, really)...
     

    Bart Roozendaal, Sevensteps
    http://www.sevensteps.com
    Microsoft MVP for Microsoft Surface


    "Roflcoptr" wrote in message news:3e84e42c-801a-418f-ab69-c4028ec5e40b...
    Ok I was able to do that, but how do you solve the problem that the MIcrosoft XPS Document Writer asks the user to enter a filename where to store the new xps file?

    Bart Roozendaal, Sevensteps
    Sunday, February 20, 2011 7:18 PM
  • Thanks a lot, that would be a great help!
    Sunday, February 20, 2011 8:19 PM
  • They did it manually: specifying the output file everytime.
     
    I think there is a way  to do this from WPF (I have looked into that a couple of years ago), but can’t really remember what I did than.
     
    Sorry this doesn’t help
     

    Bart Roozendaal, Sevensteps
    http://www.sevensteps.com
    Microsoft MVP for Microsoft Surface


    "Roflcoptr" wrote in message news:96d5bf94-9146-4db5-92ce-61d2acd0e067...
    Thanks a lot, that would be a great help!

    Bart Roozendaal, Sevensteps
    Monday, February 21, 2011 8:33 AM
  • Ok thanks a lot for clearing that up!
    Monday, February 21, 2011 9:29 AM
  • I'm also sure it is possible to do that, because I found a lot of hints that people are doing this, but till now I couldn't figure out how. I saw this arguments:

     

     proc.StartInfo.Arguments = "/t " + fileName + ".pdf" + " " + "\"Microsoft XPS Document Writer\"" + " /t " + outputName + ".xps";

    but this doesnt work for me and I cant explain why there are to /t arguments?

     

     

    Tuesday, February 22, 2011 5:03 PM
  • As a temporary solution I now use Ghostscript to convert the PDFs into JPEGs. And I defined a UserControl that displays this JPEGs and allows to navigate throught the different pages.
    Wednesday, February 23, 2011 10:22 AM