Daniel Zwirner - 2013-10-20

LibPdfFlow

LibPdfFlow is a library used to write PDF files from a C program. The idea behind this library is, to generate PDF
files as simple as HTML files (e.g. reports) on an embedded device with restricted resources.The library is
written in C and uses only libc and libHaru a free, cross platform, open source library for
generating PDF files. LibPdfFlow has only a few features, but it is small and does not need a lot of resources like
latex or similar libraries.

License

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Installation

Install libharu and type make.

Examples

Hello World

Writes "Hello World" emphasized to the file test.pdf:

#include "pdfflow.h"

FPDF_WRITER * doc = FPDF_doc_new(FPDF_PAGE_DIRECTION_PORTRAIT);
FPDF_em_start(doc);
FPDF_out(doc, "Hello World");
FPDF_em_end(doc);
FPDF_render(doc);
FPDF_doc_save(doc, "test.pdf");
FPDF_doc_free(doc);

Simple

The example simple (examples/simple) shows how to use the libpdfflow with a C programm.

mkd2pdf

The example mkd2pdf shows how to convert a markdown document into a PDF.
As markdown parser, libsoldout is used. This
markdown file converted with mkd2pdf is here.

API

FPDF_doc_new()

FPDF_WRITER * FPDF_doc_new(enum FPDF_PAGE_DIRECTION page_direction)

Description

FPDF_doc_new() create an instance of a document object and initialize it.

Parameters

page_direction - Page direction. FPDF_PAGE_DIRECTION_PORTRAIT or FPDF_PAGE_DIRECTION_LANDSCAPE.

Return Value

FPDF_doc_new() return a handle of document object on success and NULL on failure.

See also

FPDF_doc_free()

FPDF_doc_free()

void FPDF_doc_free(FPDF_WRITER * doc)

Description

FPDF_doc_free() revokes a document object and all resources.

Parameters

doc - The handle of a document object.

See also

FPDF_doc_new()

void FPDF_doc_save(FPDF_WRITER * doc, const char * filename);

FPDF_doc_save()

void FPDF_doc_save(FPDF_WRITER * doc, const char * filename)

Description

Saves the document.

Parameters

doc - The handle of a document object.

filename - The name of the file to save.

FPDF_render()

void FPDF_render(FPDF_WRITER * doc)

Description

Renders the PDF file.

Parameters

doc - The handle of a document object.

FPDF_h_start()

void FPDF_h_start(FPDF_WRITER * doc, int level)

Description

Start a header section. This function corresponds to the HTML tag h1-h4.

Parameters

doc - The handle of a document object.

level - Header level 1-4

See also

FPDF_h_end()

FPDF_h_end()

void FPDF_h_end(FPDF_WRITER * doc);

Description

End a haeder section. This function corresponds to the HTML tag /h1-/h4.

Parameters

doc - The handle of a document object.

See also

FPDF_h_start()

FPDF_em_start()

void FPDF_em_start(FPDF_WRITER * doc);

Description

Start a emphasized section. This function corresponds to the HTML tag em.

Parameters

doc - The handle of a document object.

See also

FPDF_em_end()

FPDF_em_end()

void FPDF_em_end(FPDF_WRITER * doc)

Description

End a emphasized section. This function corresponds to the HTML tag /em.

Parameters

doc - The handle of a document object.

See also

FPDF_em_start()

FPDF_strong_start()

void FPDF_strong_start(FPDF_WRITER * doc);

Description

Start a important text section. This function corresponds to the HTML tag strong.

Parameters

doc - The handle of a document object.

See also

FPDF_strong_end()

FPDF_strong_end()

void FPDF_strong_end(FPDF_WRITER * doc)

Description

End a important text section. This function corresponds to the HTML tag /strong.

Parameters

doc - The handle of a document object.

See also

FPDF_strong_start()

FPDF_code_start()

void FPDF_code_start(FPDF_WRITER * doc)

Description

Start a source code section. This function corresponds to the HTML tag code.

Parameters

doc - The handle of a document object.

See also

FPDF_code_end()

FPDF_code_end()

void FPDF_code_end(FPDF_WRITER * doc)

Description

End a source code section. This function corresponds to the HTML tag /code.

Parameters

doc - The handle of a document object.

See also

FPDF_code_start()

void FPDF_link_start(FPDF_WRITER * doc, const char * link, enum FPDF_LINK_TYPE type);

Description

Start a link section. This function corresponds to the HTML tag a.

Parameters

doc - The handle of a document object.

link - URL of destination to jump to.

type - Type of link (web, internal)

enum FPDF_LINK_TYPE Description
FPDF_LINK_TYPE_URI URL
FPDF_LINK_TYPE_INTERNAL Link to an other page. Set the anchor with FPDF_anchor()

See also

FPDF_link_end(), FPDF_anchor()

void FPDF_link_end(FPDF_WRITER * doc)

Description

End a link section. This function corresponds to the HTML tag /a.

Parameters

doc - The handle of a document object.

See also

FPDF_link_start()

FPDF_list_start()

void FPDF_list_start(FPDF_WRITER * doc, enum FPDF_LIST_STYLE style)

Description

Start a list. This function corresponds to the HTML tag ol or ul. To start a list item, use FPDF_listitem_start().

Parameters

doc - The handle of a document object.

style - One of the following values:

enum FPDF_LIST_STYLE Description
FPDF_LIST_STYLE_NUMBERS Numbered list (ol)
FPDF_LIST_STYLE_BULLETS List with bullets (ul)

See also

FPDF_list_end()

FPDF_list_end()

void FPDF_list_end(FPDF_WRITER * doc)

Description

End a list. This function corresponds to the HTML tag \ol or \ul.

Parameters

doc - The handle of a document object.

See also

FPDF_list_start()

FPDF_listitem_start()

void FPDF_listitem_start(FPDF_WRITER * doc)

Description

Start a list item. This function corresponds to the HTML tag li.

Parameters

doc - The handle of a document object.

See also

FPDF_listitem_end()

FPDF_listitem_end()

void FPDF_listitem_end(FPDF_WRITER * doc)

Description

End a list item. This function corresponds to the HTML tag \li.

Parameters

doc - The handle of a document object.

See also

FPDF_listitem_start()

FPDF_blockquote_start()

void FPDF_blockquote_start(FPDF_WRITER * doc)

Description

Start a inserted section. This function corresponds to the HTML tag blockquote.

Parameters

doc - The handle of a document object.

See also

FPDF_blockquote_end()

FPDF_blockquote_end()

void FPDF_blockquote_end(FPDF_WRITER * doc)

Description

End a inserted section. This function corresponds to the HTML tag \blockquote.

Parameters

doc - The handle of a document object.

See also

FPDF_blockquote_start()

FPDF_paragraph_start()

void FPDF_paragraph_start(FPDF_WRITER * doc)

Description

Start a paragraph. This function corresponds to the HTML tag p.

Parameters

doc - The handle of a document object.

See also

FPDF_paragraph_end()

FPDF_paragraph_end()

void FPDF_paragraph_end(FPDF_WRITER * doc)

Description

End a paragraph. This function corresponds to the HTML tag /p.

Parameters

doc - The handle of a document object.

See also

FPDF_paragraph_start()

FPDF_pre_start()

void FPDF_pre_start(FPDF_WRITER * doc)

Description

Start a pre formatted section. This function corresponds to the HTML tag pre.

Parameters

doc - The handle of a document object.

See also

FPDF_pre_end()

FPDF_pre_end()

void FPDF_pre_end(FPDF_WRITER * doc)

Description

End a pre formatted section. This function corresponds to the HTML tag \pre.

Parameters

doc - The handle of a document object.

See also

FPDF_pre_start()

FPDF_out()

void FPDF_out(FPDF_WRITER * doc, const char * text)

Description

Write some text into the PDF file.

Parameters

doc - The handle of a document object.
text - Text to be written.

FPDF_out2()

void FPDF_out2(FPDF_WRITER * doc, const char * text, int length)

Description

Write some text into the PDF file.

Parameters

doc - The handle of a document object.
text - Text to be written.
length - Length of the text to be written.

FPDF_table_start()

void FPDF_table_start(FPDF_WRITER * doc, struct FPDF_TABLE_OPTIONS * options)

Description

Start a table. This function corresponds to the HTML tag table.

Parameters

doc - The handle of a document object.

options - Pointer to a table option struct or NULL.

See also

FPDF_init_table_options()

See also

FPDF_table_end()

FPDF_table_end()

void FPDF_table_end(FPDF_WRITER * doc)

Description

End a table. This function corresponds to the HTML tag /table.

Parameters

doc - The handle of a document object.

See also

FPDF_table_start()

FPDF_table_row_start()

void FPDF_table_row_start(FPDF_WRITER * doc)

Description

Start a row. This function corresponds to the HTML tag tr.

Parameters

doc - The handle of a document object.

See also

FPDF_table_row_end()

FPDF_table_row_end()

void FPDF_table_row_end(FPDF_WRITER * doc)

Description

End a row. This function corresponds to the HTML tag /tr.

Parameters

doc - The handle of a document object.

See also

FPDF_table_row_start()

FPDF_table_cell_start()

void FPDF_table_cell_start(FPDF_WRITER * doc, struct FPDF_CELL_OPTIONS * options)

Description

Start a cell. This function corresponds to the HTML tag td.

Parameters

doc - The handle of a document object.

options - Cell options or NULL.

See also

FPDF_table_cell_end()

FPDF_table_cell_end()

void FPDF_table_cell_end(FPDF_WRITER * doc)

Description

Start a cell. This function corresponds to the HTML tag /td.

Parameters

doc - The handle of a document object.

See also

FPDF_table_cell_start()

FPDF_header()

void FPDF_header(FPDF_WRITER * doc, const char * titel, const char * image)

Description

Add a titel and an image to each page. This function must be called after FPDF_render().

Parameters

doc - The handle of a document object.

titel - Document titel

image - Path to a PNG image or NULL.

void FPDF_footer(FPDF_WRITER * doc)

Description

Add a page numbers to each page. This function must be called after FPDF_render().

Parameters

doc - The handle of a document object.

FPDF_outline()

void FPDF_outline(FPDF_WRITER * doc)

Description

Add an outline to the document.

Parameters

doc - The handle of a document object.

FPDF_init_table_options()

struct FPDF_TABLE_OPTIONS FPDF_init_table_options()

Description

This function returns a FPDF_TABLE_OPTIONS struct with default values.

struct FPDF_TABLE_OPTIONS Description
enum FPDF_TABLE_STYLE style See enum FPDF_TABLE_STYLE
struct FPDF_COLOR stroke Color of borders
struct FPDF_COLOR fill Cell background color
HPDF_BOOL drawStroke If true, draw borders
HPDF_BOOL doFill If true, draw background color
int * columWidths Pointer to an array with column widths in % or NULL
int columWidthsCount Number of entries in columWidths
enum FPDF_TABLE_STYLE Description
FPDF_TABLE_STYLE_EQUAL All columns are equal
FPDF_TABLE_STYLE_DESCRIPTION_RIGHT The right column gets the rest of the space
FPDF_TABLE_STYLE_USER_DEFINED User defines, use columWidths to set column widths

FPDF_init_cell_options()

struct FPDF_CELL_OPTIONS FPDF_init_cell_options()

Description

This function returns a FPDF_CELL_OPTIONS struct with default values.

struct FPDF_CELL_OPTIONS Description
struct FPDF_COLOR fill Cell background color

FPDF_anchor()

void FPDF_anchor(FPDF_WRITER * doc, const char * id)

Description

Set at the current position an achor with the id id.

Parameters

doc - The handle of a document object.

id - Anchor id.

See also

FPDF_link_start()

 

Last edit: Daniel Zwirner 2014-04-04