This demo shows usage of PDF dictionaries and arrays and matrix transformation. PDF tiling pattern is created by feeding corresponding dictionaries. Dictionary can have stream within, in this case it is created using HPDF_DictStream_New() function, otherwise HPDF_Dict_New() should be called.
Library automatically calculates cross-references when array inserted to dictionary or dictionary inserted to dictionary etc.
Also, some items are inserted to page's "Resources" dictionary. It is done using HPDF_Page_GetInheritableItem() function.
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
#include "handler.h"
{
char patternData[200];
sprintf(patternData, "q %f w %f 0 m %f %f l %f 0 m %f %f l S Q", lineWidth, cellWidth_4, cellWidth_4, cellWidth, cellWidth_34, cellWidth_34, cellWidth);
return patDict;
}
int
main (int argc, char **argv)
{
char fname[256];
strcpy (fname, argv[0]);
strcat (fname, ".pdf");
pdf =
HPDF_New (demo_error_handler, NULL);
if (!pdf) {
printf ("error: cannot create PdfDoc object\n");
return 1;
}
if (setjmp(env)) {
return 1;
}
HPDF_Dict originalPat = createPattern (pdf, 0, 1.0);
HPDF_Dict scaledPat = createPattern (pdf, 0, 0.2);
HPDF_Dict rotatedPat = createPattern (pdf, 70, 1.7);
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_New(HPDF_Error_Handler user_error_fn, void *user_data)
Create an instance of a document object and initialize it.
HPDF_STATUS HPDF_Page_GSave(HPDF_Page page)
Save the page's current graphics state to the stack.
HPDF_STATUS HPDF_Page_Rectangle(HPDF_Page page, HPDF_REAL x, HPDF_REAL y, HPDF_REAL width, HPDF_REAL height)
Append rectangle to the current path.
HPDF_STATUS HPDF_Page_Fill(HPDF_Page page)
Fill current path using non-zero winding number rule.
HPDF_STATUS HPDF_Page_GRestore(HPDF_Page page)
Restore graphics state which is saved by HPDF_Page_GSave().
HPDF_REAL HPDF_Page_GetHeight(HPDF_Page page)
Get page height.
HPDF_STATUS HPDF_Page_RawWrite(HPDF_Page page, char *data)
Write raw commands to page stream This command allow user to write some data to page stream unconditi...
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_REAL HPDF_Page_GetWidth(HPDF_Page page)
Get page width.
#define HPDF_MM
Predefined value for calculations with millimeters. Equals to 72.0/25.4 (72 points pre inch per mm).
Definition: hpdf_consts.h:178
HPDF_Dict HPDF_DictStream_New(HPDF_MMgr mmgr, HPDF_Xref xref)
HPDF_Array HPDF_Array_New(HPDF_MMgr mmgr)
HPDF_STATUS HPDF_Array_AddReal(HPDF_Array array, HPDF_REAL value)
HPDF_STATUS HPDF_Dict_AddReal(HPDF_Dict dict, const char *key, HPDF_REAL value)
HPDF_Dict HPDF_Dict_New(HPDF_MMgr mmgr)
HPDF_STATUS HPDF_Array_AddName(HPDF_Array array, const char *value)
HPDF_STATUS HPDF_Dict_AddName(HPDF_Dict dict, const char *key, const char *value)
HPDF_STATUS HPDF_Xref_Add(HPDF_Xref xref, void *obj)
HPDF_STATUS HPDF_Dict_Add(HPDF_Dict dict, const char *key, void *obj)
#define HPDF_OCLASS_DICT
Definition: hpdf_objects.h:47
HPDF_STATUS HPDF_Dict_AddNumber(HPDF_Dict dict, const char *key, HPDF_INT32 value)
@ HPDF_PAGE_SIZE_A4
ISO 216 "A4" page size (210.0mm x 297.0mm)
Definition: hpdf_page_sizes.h:137
void * HPDF_Page_GetInheritableItem(HPDF_Page page, const char *key, HPDF_UINT16 obj_class)
HPDF_STATUS HPDF_Stream_WriteStr(HPDF_Stream stream, const char *value)
float HPDF_REAL
Definition: hpdf_types.h:79
@ HPDF_PAGE_LANDSCAPE
Landscape orientation (longest size horizontal)
Definition: hpdf_types.h:577
HPDF_TransMatrix HPDF_Matrix_RotateDeg(HPDF_TransMatrix m, HPDF_REAL degrees)
HPDF_TransMatrix HPDF_Matrix_Scale(HPDF_TransMatrix m, HPDF_REAL sx, HPDF_REAL sy)
Definition: hpdf_objects.h:333
Definition: hpdf_objects.h:421
HPDF_MMgr mmgr
Definition: hpdf_objects.h:423
HPDF_Stream stream
Definition: hpdf_objects.h:430
Definition: hpdf_doc.h:36
HPDF_MMgr mmgr
Definition: hpdf_doc.h:40
HPDF_Xref xref
Definition: hpdf_doc.h:43
Definition: hpdf_types.h:240
HPDF_REAL b
Definition: hpdf_types.h:242
HPDF_REAL y
Definition: hpdf_types.h:246
HPDF_REAL a
Definition: hpdf_types.h:241
HPDF_REAL d
Definition: hpdf_types.h:244
HPDF_REAL c
Definition: hpdf_types.h:243
HPDF_REAL x
Definition: hpdf_types.h:245