Converting Word docs, XML, and HTML to PDF

Discussion in 'Mac Programming' started by ehayut, Aug 7, 2007.

  1. macrumors member

    Joined:
    Jun 29, 2005
    #1
    Hi,

    I am developing a cross platform (Windows+Mac) desktop app using C++. I'm looking for a tool to programmatically convert any sort of document (.doc, .txt, .rtf, .xml, .html) to a PDF format.

    I have found many tools, but they are almost all Windows only. Does anybody know of any tool/API that will allow me to do this cross platform?
     
  2. macrumors 6502

    jellomizer

    Joined:
    Sep 12, 2006
    Location:
    Upstate NY
    #2
    OS X and PDF.

    Well remember that OS X has PDF Support build in. I am sure you can make an Apple Script that opens Office (or text edit with some sucess), or Safari then have it do a print and there is a print option to PDF. I know you may be looking for a more direct C++ using some shared libs but the best way may just make an apple script (or have your C++ program generate the apple script) and execute it. C++ is not a good language for creating cross platform application. Finding cross platform libaries for converting these files to PDF will be very difficult because espectially .DOC format requires a fare amount of work to aproximate and Microsoft isn't helpful in releasing the specs. .xml and .html too even with the full specs are considered hard to render, just becasue of all the specs that need to be followed. The best you can probably do is use some pre-procesor definations and part of the make file say the code is either for OS X or Windows and do the different methods for both of them. Remember these are pre-processor definanitions so it essentionally doesn't compile the code if it isn't in the #IFDEF .
     
  3. macrumors 603

    netdog

    Joined:
    Feb 6, 2006
    Location:
    London
    #3
    Yes, you'll find it in the PRINT function of OS X. Print, PDF, Save as PDF. It works flawlessly, and surely there is a way to access this function in an automated way.
     
  4. thread starter macrumors member

    Joined:
    Jun 29, 2005
    #4
    Thanks for the responses, but I need a way to do this in a way such that it will work in both Windows and on a Mac without having to write platform specific code. I know that a lot of the tools out there need a copy of Word installed, which is fine by me. The tool doesn' have to ahve reverse engineered the .doc format :p

    Any other suggestions?

    Thanks again.
     
  5. macrumors 6502

    jellomizer

    Joined:
    Sep 12, 2006
    Location:
    Upstate NY
    #5
     
  6. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    You will probably want to write a separate Cocoa CLI app for the Mac that does the conversion, and another for Windows. Here's a tutorial to get you started: Create a PDF

    Combine that with an NSTextView that displays an NSAttributedString (which can be made from RTF, Word, HTML, etc), should be pretty simple to create if you're familiar with Cocoa.

    Edit: if you don't want to go down the Cocoa road, check out this article, which has sample C code:
    PDF Document Creation, Viewing, and Transforming
     
  7. thread starter macrumors member

    Joined:
    Jun 29, 2005
    #7
    Thank you very much, you guys have been very helpful. I will look into all your recommendations.
     

Share This Page