Haru Free PDF Library
page_sizes_demo.c
All available page sizes demo.

This demo creates PDF file, feed it with pages of all sizes from HPDF_PageSizes enumeration. For every page outline is created with the name of a page size from HPDF_PageSizeName.

/*
* << Haru Free PDF Library 2.0.0 >> -- page_sizes_demo.c
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2023 Dmitry Solomennikov
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
* It is provided "as is" without express or implied warranty.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
#include "hpdf.h"
#include "handler.h"
#include "utils.h"
#include "hpdf_utils.h"
int main (int argc, char **argv)
{
HPDF_Doc pdf;
char fname[256];
pdf = HPDF_NewEx (demo_error_handler, NULL, NULL, 0, NULL);
if (!pdf) {
printf ("error: cannot create PdfDoc object\n");
return 1;
}
if (setjmp(env)) {
HPDF_Free (pdf);
return 1;
}
strcpy (fname, argv[0]);
strcat (fname, ".pdf");
/* Set page mode to use outlines. */
/* create outline root. */
root = HPDF_CreateOutline (pdf, NULL, "Page sizes list", NULL);
while (i < HPDF_PAGE_SIZE_EOF) {
printf("Processing %s...\n", HPDF_PageSizeName (i));
HPDF_Page page = HPDF_AddPage (pdf);
HPDF_Outline outline;
outline = HPDF_CreateOutline (pdf, root, HPDF_PageSizeName (i), NULL);
i++;
}
/* save the document to a file */
HPDF_SaveToFile (pdf, fname);
/* clean up */
HPDF_Free (pdf);
return 0;
}
HPDF_STATUS HPDF_SaveToFile(HPDF_Doc pdf, const char *filename)
Saves the current document to file.
void HPDF_Free(HPDF_Doc pdf)
Revoke a document object and all resources.
HPDF_Doc HPDF_NewEx(HPDF_Error_Handler user_error_fn, HPDF_Alloc_Func user_alloc_fn, HPDF_Free_Func user_free_fn, HPDF_UINT mem_pool_buf_size, void *user_data)
Create an instance of a document object and initialize it.
HPDF_Outline HPDF_CreateOutline(HPDF_Doc pdf, HPDF_Outline parent, const char *title, HPDF_Encoder encoder)
Create new outline object.
HPDF_STATUS HPDF_Outline_SetOpened(HPDF_Outline outline, HPDF_BOOL opened)
Set whether this outline node is opened when the outline is displayed for the first time.
HPDF_STATUS HPDF_Outline_SetDestination(HPDF_Outline outline, HPDF_Destination dst)
Set target destination object to jump to when outline object is clicked.
HPDF_REAL HPDF_Page_GetHeight(HPDF_Page page)
Get page height.
HPDF_Page HPDF_AddPage(HPDF_Doc pdf)
Create new page and add it after the last page of document.
HPDF_STATUS HPDF_Page_SetSize(HPDF_Page page, HPDF_PageSizes size, HPDF_PageDirection direction)
Change page size and direction to a predefined ones.
HPDF_STATUS HPDF_SetPageMode(HPDF_Doc pdf, HPDF_PageMode mode)
Set document display mode.
#define HPDF_TRUE
Definition: hpdf_consts.h:26
@ HPDF_PAGE_SIZE_US_LETTER
US Loose "Letter" page size (216.0mm x 279.0mm)
Definition: hpdf_page_sizes.h:74
@ HPDF_PAGE_SIZE_EOF
Last page size enum value.
Definition: hpdf_page_sizes.h:914
enum _HPDF_PageSizes HPDF_PageSizes
@ HPDF_PAGE_PORTRAIT
Portrait orientation (longest size vertical)
Definition: hpdf_types.h:575
@ HPDF_PAGE_MODE_USE_THUMBS
Definition: hpdf_types.h:363
const char * HPDF_PageSizeName(HPDF_PageSizes size)
Return name of predefined page size.
Definition: hpdf_objects.h:333
Definition: hpdf_objects.h:421
Definition: hpdf_doc.h:36