locked
How to display PDF Thumbnails and launch PDF Viewer

    Question

  • I would also like to display Thumbnails of PDFs in my metro app and allow the user to open the pdf in the preferred pdf viewer. Is that really not possible in current metro apps?
    Friday, November 11, 2011 12:29 PM

Answers

  • Hi Phil,

    Once you are able to generate the thumbnails you can launch the appropriate app (if it is installed) using the launcher with code similar to this:

    Windows.System.Launcher.launchDefaultProgramForFile(file);

    You can get the thumbnails for other types of files if you want to play with this.  For example PPT files have picture thumbnails.  For a preview view you would get the singleItem type thumbnail (modified the Thumbnail Sample to show this):

                var requestedSize = 100,
                thumbnailMode = Windows.Storage.FileProperties.ThumbnailMode.singleItem;
           
            // Clean output in case of repeat usage
            onScenarioChanged();

            var openpicker = new Windows.Storage.Pickers.FileOpenPicker();
            openpicker.fileTypeFilter.replaceAll([".doc", ".xls", ".ppt", ".docx", ".xlsx", ".pptx", ".pdf", ".txt", ".rtf"]);
            openpicker.pickSingleFileAsync().then(function (file) {
                if (file) {
                    Windows.System.Launcher.launchDefaultProgramForFile(file);

                    file.getThumbnailAsync(thumbnailMode, requestedSize).then(function (thumbnail) {
                        if (thumbnail) {
                            outputResult(file, thumbnail, thumbnailMode.toString(), requestedSize);
                   

    Let me know how you are getting these PDF thumbnails today and we can talk about how you might be able to use them in your app.

     

    -Jeff

     


    Jeff Sanders (MSFT)
    Friday, November 11, 2011 5:09 PM
    Moderator

All replies

  • Hi Phil,

    How do you generate PDF thumbnails today?

    -Jeff


    Jeff Sanders (MSFT)
    Friday, November 11, 2011 3:05 PM
    Moderator
  • Hi Phil,

    Once you are able to generate the thumbnails you can launch the appropriate app (if it is installed) using the launcher with code similar to this:

    Windows.System.Launcher.launchDefaultProgramForFile(file);

    You can get the thumbnails for other types of files if you want to play with this.  For example PPT files have picture thumbnails.  For a preview view you would get the singleItem type thumbnail (modified the Thumbnail Sample to show this):

                var requestedSize = 100,
                thumbnailMode = Windows.Storage.FileProperties.ThumbnailMode.singleItem;
           
            // Clean output in case of repeat usage
            onScenarioChanged();

            var openpicker = new Windows.Storage.Pickers.FileOpenPicker();
            openpicker.fileTypeFilter.replaceAll([".doc", ".xls", ".ppt", ".docx", ".xlsx", ".pptx", ".pdf", ".txt", ".rtf"]);
            openpicker.pickSingleFileAsync().then(function (file) {
                if (file) {
                    Windows.System.Launcher.launchDefaultProgramForFile(file);

                    file.getThumbnailAsync(thumbnailMode, requestedSize).then(function (thumbnail) {
                        if (thumbnail) {
                            outputResult(file, thumbnail, thumbnailMode.toString(), requestedSize);
                   

    Let me know how you are getting these PDF thumbnails today and we can talk about how you might be able to use them in your app.

     

    -Jeff

     


    Jeff Sanders (MSFT)
    Friday, November 11, 2011 5:09 PM
    Moderator
  • Thanks Jeff for talking your time to answer my question.

    Today I not getting any PDF thumbs yet. I was basically checking if Win8 has some on-board functionality to generate (high-quality) thumbnails of docs.

    So given the code you posted it seems that is indeed the case and I could enumerate the documentsLibrary (with the approriate rights) for docs that are interesting to us (pdf, doc). 

    I guess for other formats as LibreOffice/OpenOffice we would have to supply our own (C++) thumbnail generator or hope that the OpenOffice guys supply such in the future?

    Friday, November 11, 2011 11:48 PM
  • Correct!
    Jeff Sanders (MSFT)
    Monday, November 14, 2011 3:21 PM
    Moderator
  • Windows 8.1 has APIs for rendering PDFs. Please have a look at the Windows.Data.Pdf namespace

    Build conference session recording available on Channel 9. This details how to use the new PDF rendering APIs.

    Friday, November 1, 2013 7:38 AM