Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ehayut

Suspended
Original poster
Jun 29, 2005
96
0
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?
 

jellomizer

macrumors 6502
Sep 12, 2006
486
4
Upstate NY
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 .
 

netdog

macrumors 603
Feb 6, 2006
5,760
38
London
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.
 

ehayut

Suspended
Original poster
Jun 29, 2005
96
0
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.
 

jellomizer

macrumors 6502
Sep 12, 2006
486
4
Upstate NY
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.
That will be the hard part... OS X and Windows are actually very different OS's while a lot of code usually the logic can be cross compatible the easiest way of doing what you need to be done can't really be by cross platform programming, You will need to have a Windows way and an OS X way. The time that it will take you to do it both ways will be probably less then searching for a solution that will work both ways, wich may or may not work as well. If you do find a cross platform library it will probably just do the same thing having two different platform independant code segments and will choose wich segment to compile depending on what OS you are compiling on. This sounds like an ambishious project and I know you want to do it the best way idologically, and I can commend the effort. But sometimes you need to suck it up and and do it the platform independent route. You can still have both options in your code base and depending on the compiler you compile one version of you convert module vs the other one. It really isn't all that bad and it is done more often then not on cross platform apps.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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
 

ehayut

Suspended
Original poster
Jun 29, 2005
96
0
Thank you very much, you guys have been very helpful. I will look into all your recommendations.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.