How to create a PDF file and write a simple text in c?


I’m working on GTK3 application in c. I want to export a simple Text “hello world” into PDF. Does Linux provide any native artifact to do so?

Thank you.

Hi @harshith_raj!

Take a look at PDF Surfaces: Cairo: A Vector Graphics Library

Hi @lb90 ,

I tried it but I’m getting following error

source.cpp:9:15: error: ‘cairo_pdf_surface_create’ was not declared in this scope; did you mean ‘cairo_image_surface_create’?
    9 |     surface = cairo_pdf_surface_create(filename, 595.0, 842.0); // Page size: A4 (595x842 points)
      |               ^~~~~~~~~~~~~~~~~~~~~~~~
      |               cairo_image_surface_create

I have included cario.h header file and used -lcario for linking the lib

Ok, try including also cairo-pdf.h

Thank you, This was helpful

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.