Search code examples
macosbitmapms-officequicklook

QuickLook Previews for Microsoft Office Files


I am developing a application where user has the facility to share MS-Office files. Under Windows I use the Word Automation objects and a virtual printer to create .BMP files from the .doc and the .ppt's which I then read/display and send it on a network.

Now, I am porting my application on MAC.

On MAC I am really not sure as to how to achieve this stuff. I searched and found a way to get the bitmap representation of files under MAC through the user of QuickLook API. I also found some posts here related to QuickLook.

Get QuickLook preview image for file

Mac Quick Look Preview in an NSView or NSImage?

But here we are stuck with QLThumbnailImageCreate as it gives only a single thumbnail image for the document (1st page of .doc and .ppt). So this would not be of any use for me.

I researched a bit more and found a command qlmanage that with its option of -p will generate the actual PREVIEW of the document not only the thumbnail. But now it only saves the images inside pages as .png files and does nothing with the text. It gives a single Preview.html file though along with PreviewProperties.plist that has information about the attachments.

The same qlmange command does something weird for PowerPoint files. It saves the template of slide as .pdf file( and the embedded images as .png).

Does there exists some way in code through which I can request the MS-Office QuickLook generator (office.qlgenerator) to give me a preview objects and then using that preview object I convert the pages into bitmaps ?

Finder / Spotlight seems to figure the preview perfectly I wonder how are these applications are able to do it ? Does Apple hide this functionality from developers ???

Can anyone having QuickLook expertise guide me through this, or show me some other way possible, with or without QuickLook because as of now I think I am really stuck here.

In simple terms I just want the raw image representations of pages/slides.

Any help in this regard would be highly appreciated.

Thanks & Regards, LazyCoder7


Solution

  • Answering my own question for someone having the same situation as mine.

    We would require a two step process here.

    1.Any Document -> .PDF.

    For this part you may use the information provided at Programming a Filter/Backend to 'Print to PDF' with CUPS from any Mac OS X application. It's very good explained, you can also check out this link https://bitbucket.org/codepoet/cups-pdf-for-mac-os-x/wiki/Home.

    Once you understand and experiment with CUPS you will be able to generate .PDF files from .doc or say a .ppt.

    Now begins the second part of the solution.

    2.Convert .PDF to .JPG.

    For this part you can use the code at Convert PDF pages to images with COCOA.

    The code works good and gives the desired results.

    So now basically we can convert any MS Office files to images and that too page wise without going the QuickLook way (which will not work in this case though).

    Hope, this might help someone.

    Regards,

    CrazyCoder7.