Outputing code to a pdf file

Hi,
I need to out my results from my program into a pdf file, but I'm not sure how. Are there any easy to use libraries to do this ? And could you post step by step on how to use the library ?

For example, how would I get the exact same output I have in this test program, but in pdf file format ?
Thanks,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int num = 1000;
	string a = "Test word";
	int number[] = { 1, 3, 4, 5, 6, };
	string words[] = { word1, word2, word3 };

	cout << "Sample formatting for output. " << endl;
	cout << "\tTest indent/tab" << endl;
	cout << "\tTest indent/tab" << endl;
	cout << "\t\tTest indent/tab" << endl;
	cout << "\t\tTest indent/tab" << endl;
	cout << "\t\t\tTest indent/tab" << endl;
	cout << "\t\t\tTest indent/tab" << endl;

	cout << "Values in array number: "
	for ( int i = 0; i < (sizeof(number) / sizeof(int) ); i++ )
	{
		 cout << number[i] << " ";
	}

	cout << "Words in array words: "
	for ( int i = 0; i < (sizeof(words) / sizeof(string) ); i++ )
	{
		 cout << number[i] << " ";
	}

	return 0;
}



The thing is that, although you could open a pdf file using an fstream, you'll have to edit it in binary mode, because a pdf is not raw text. And that's going to be a rather difficult task. Check boost. boost has plenty of good stuff.
http://libharu.org/

Good luck!
Whoa, that's pretty cool. Looks like google still reigns over all.
I looked at the libharu documentation and some examples, but I don't understand how to compile the code and what the command-line arguments are to save the pdf.
It looks like a pretty suitable choice to me. Google more about it. See if you find anything. If you really find nothing, google for another pdf library.
You won't find much better.

The other good choice is http://www.gnupdf.org/
closed account (1yR4jE8b)
Does the C++ program need to produce the PDF file? Can't you just copy-paste your results into OpenOffice and export it as a PDF? Seems awfully bizarre to have to make a program that outputs such trivial output into a complex file format like a pdf.
Generally it's much easier to create a pdf file than to display it. If you know the fundamentals (and with some experience) it's quite straightforward to create a simple pdf file (containing only text!).

Look here: http://www.mactech.com/articles/mactech/Vol.15/15.09/PDFIntro/

Consider if it's worth the effort.
Topic archived. No new replies allowed.