100

I want to be able to generate PDF output from my (native) C++ Windows application. Are there any free/open source libraries available to do this?

I looked at the answers to this question, but they mostly relate to .Net.

ChrisN
  • 16,635
  • 9
  • 57
  • 81

10 Answers10

67

LibHaru

Haru is a free, cross platform, open-sourced software library for generating PDF written in ANSI-C. It can work as both a static-library (.a, .lib) and a shared-library (.so, .dll).

Didn't try it myself, but maybe it can help you

Daniil Ryzhkov
  • 7,416
  • 2
  • 41
  • 58
aku
  • 122,288
  • 32
  • 173
  • 203
20

I worked on a project that required a pdf report. After searching for online I found the PoDoFo library. Seemed very robust. I did not need all the features, so I created a wrapper to abstract away some of the complexity. Wasn't too difficult. You can find the library here:

http://podofo.sourceforge.net/

Enjoy!

  • 1
    Building PdDoFo on Mac is a huge pain so I finally gave up trying. Building LibHaru was very easy. –  Jan 23 '15 at 01:13
  • 1
    Podofo got 2 compiler issues, after adding #include , in two files, was able to build the package. But somehow, the cmake system does not play well on my Linux where I have two versions of GCC (old one came with my Centos6.5, and a latest 5.3 that I build). Linking is an issue. I managed to link the helloworld, but the test program produced a blank document. It is very hard to solve this problem. – Kemin Zhou Aug 17 '16 at 18:11
  • 2
    But podofo REQUIRES freetype2 library which is **GPL, not LGPL**. You cannot make software with use of freetype2 **if you want not to make your source public.** – 18C Aug 24 '17 at 18:35
  • 2
    @18C : Freetype allows inclusion in commercial closed source applications. See [this](https://opensource.stackexchange.com/questions/5144/is-it-safe-to-use-freetype-inside-a-proprietary-closed-source-software) – Congenital Optimist Nov 12 '18 at 11:18
18

If you're brave and willing to roll your own, you could start with a PostScript library and augment it to deal with PDF, taking advantage of Adobe's free online PDF reference.

Tyler
  • 28,498
  • 11
  • 90
  • 106
10

jagpdf seems to be one of them. It is written in C++ but provides a C API.

Sangcheol Choi
  • 841
  • 1
  • 12
  • 19
8

PDF Hummus. see for http://pdfhummus.com/ - contains all required features for manipulation with PDF files except rendering.

Lidia Mirkin
  • 81
  • 1
  • 1
  • 1
    I did a large PDF-Export with Hummus recently and can recommend it. Probably not complete in terms of covering all features of the current PDFSpec (which is quite exhaustive), but easy to understand and good extensible through a callback class with a number of virtual functions (https://github.com/galkahana/PDF-Writer/blob/master/PDFWriter/DocumentContextExtenderAdapter.h). Contains TIFF/JPEG handling and the freetype library for font handling. – RED SOFT ADAIR May 27 '14 at 12:14
  • have you been able to compile it as a dynamic linked library? Or does it support just static linked library? – Sam Sep 12 '18 at 13:57
8

It depends a bit on your needs. Some toolkits are better at drawing, others are better for writing text. Cairo has a pretty good for drawing (it support a wide range of screen and file types, including pdf), but it may not be ideal for good typography.

Leon Timmermans
  • 30,029
  • 2
  • 61
  • 110
5

muPdf library looks very promising: http://mupdf.com/

There is also an open source viewer: http://blog.kowalczyk.info/software/sumatrapdf/free-pdf-reader.html

Peter
  • 346
  • 5
  • 7
  • 1
    It looks like muPdf is for rendering PDFs, not generating them? – vy32 Aug 20 '12 at 21:16
  • 1
    @vy32 Looking at the source I would say generating pdf-files is at best work in progress and not the primary goal of `muPdf` – matec Jun 22 '14 at 19:44
5
  • LibHaru seems to be used by many.

A non-open source approach is: PDF Creator Pilot which provides more language options including C++, C#, Delphi, ASP, ASP.NET, VB, VB.NET, VBScript, PHP and Python

vy32
  • 28,461
  • 37
  • 122
  • 246
prakash
  • 58,901
  • 25
  • 93
  • 115
2

Try wkhtmltopdf

Software features

Cross platform. Open source. Convert any web pages into PDF documents using webkit. You can add headers and footers. TOC generation. Batch mode conversions. Can run on Linux server with an XServer (the X11 client libs must be installed). Can be directly used by PHP or Python via bindings to libwkhtmltox.

M.Hefny
  • 2,677
  • 1
  • 26
  • 30
  • 3
    This is good. But, as it use dated webkit, some pages may complaint (youtube for example) – swdev Aug 31 '14 at 23:31
1

http://wxcode.sourceforge.net/docs/wxpdfdoc/

Works with the wxWidgets library.