1'****************************************************************************** 2'* Program name: hpdftest 3'* Version: 0.1 4'* 5'* Author: Copyright (c) 2008 Klaus Siebke 6'* Siebke Unternehmensberatung 7'* URL http://www.siebke.com 8'* 9'* Description: 10'* ----------- 11'* 12'* Program to test the creation of a PDF file using the Haru Free PDF Library 13'* for more details see: http://www.freebasic.net/forum/viewtopic.php?t=9014 14'* 15'* License: 16'* ------- 17'* 18'* Permission to use, copy, modify, distribute and sell this software 19'* and its documentation for any purpose is hereby granted without fee, 20'* provided that the above copyright notice appear in all copies and 21'* that both that copyright notice and this permission notice appear 22'* in supporting documentation. 23'* It is provided "as is" without express or implied warranty. 24'* 25'* 26'* External libraries used by the program: 27'* -------------------------------------- 28'* 29'* << Haru Free PDF Library 2.0.8 >> 30'* URL http://libharu.org/ 31'* Copyright (c) 1999-2006 Takeshi Kanno 32'* 33'****************************************************************************** 34 35#include "crt/errno.bi" 36#include "zlib.bi" 37 38'****************************************************************************** 39'* Includes for Haru Free PDF Library 40'****************************************************************************** 41#ifndef __mod_hpdf_bi__ 42#define __mod_hpdf_bi__ 43#include once "hpdf_consts.bi" 44#include once "hpdf_types.bi" 45#include once "hpdf.bi" 46#endif 47 48'****************************************************************************** 49'* Declarations of subroutines and functions 50'****************************************************************************** 51declare sub error_handler cdecl (byval error_no as HPDF_STATUS, byval detail_no as HPDF_STATUS, byval user_data as any ptr ) 52 53'****************************************************************************** 54'* Constants 55'****************************************************************************** 56#define NULL 0 57const page_title = "PDF test document" 58 59'****************************************************************************** 60'* Variables 61'****************************************************************************** 62dim shared pdf as HPDF_Doc 'ptr 63dim shared fname as string * 256 64dim shared page as HPDF_Page 65dim shared def_font as HPDF_Font 66dim shared txt_font as HPDF_Font 67dim shared tw as HPDF_REAL 68dim shared doc_height as HPDF_REAL 69dim shared doc_width as HPDF_REAL 70dim shared i as HPDF_UINT 71'dim shared errno as HPDF_STATUS ptr 72dim shared detno as HPDF_STATUS ptr 73dim shared userdat as any ptr 74 75 76'****************************************************************************** 77'* Begin of main program 78'****************************************************************************** 79 80'let's go ... (initialize hpdf) 81pdf = HPDF_New(@error_handler, NULL) 82 83 84'add a new page object 85page = HPDF_AddPage (pdf) 86 87'specify the document size 88doc_height = HPDF_Page_GetHeight (page) 89doc_width = HPDF_Page_GetWidth (page) 90 91'print a frame 92HPDF_Page_SetLineWidth (page, .5) 93HPDF_Page_Rectangle (page, 50, 50, doc_width - 100, doc_height - 110) 94HPDF_Page_Stroke (page) 95 96'print the title of the page (with positioning center) with font Helvetica 97def_font = HPDF_GetFont (pdf, "Helvetica", NULL) 98HPDF_Page_SetFontAndSize (page, def_font, 24) 99tw = HPDF_Page_TextWidth (page, page_title) 100HPDF_Page_BeginText (page) 101HPDF_Page_TextOut (page, (doc_width - tw) / 2, doc_height - 50, page_title) 102HPDF_Page_EndText (page) 103 104'print some text inside the frame 105HPDF_Page_BeginText (page) 106 107'first line with font Times Roman 14 108txt_font = HPDF_GetFont (pdf, "Times-Roman", NULL) 109HPDF_Page_MoveTextPos (page, 60, doc_height - 105) 110HPDF_Page_SetFontAndSize (page, txt_font, 14) 111HPDF_Page_ShowText (page, "This is a first line") 112 113'second line with font Courier 12 114txt_font = HPDF_GetFont (pdf, "Courier", NULL) 115HPDF_Page_MoveTextPos (page, 0, -20) 116HPDF_Page_SetFontAndSize (page, txt_font, 12) 117HPDF_Page_ShowText (page, "This is a second line") 118 119'third line with font Symbol 16 120txt_font = HPDF_GetFont (pdf, "Symbol", NULL) 121HPDF_Page_MoveTextPos (page, 0, -20) 122HPDF_Page_SetFontAndSize (page, txt_font, 16) 123HPDF_Page_ShowText (page, "Here are some symbols") 124 125'fourth line with font Helvetica 14 126txt_font = HPDF_GetFont (pdf, "Helvetica", NULL) 127HPDF_Page_MoveTextPos (page, 0, -20) 128HPDF_Page_SetFontAndSize (page, txt_font, 14) 129HPDF_Page_ShowText (page, "This is arial") 130 131 132HPDF_Page_EndText (page) 133 134'save the document 135HPDF_SaveToFile (pdf, "mydoc.pdf") 136 137'clean up 138HPDF_Free (pdf) 139 140'****************************************************************************** 141'* End of main program 142'****************************************************************************** 143 144 145sub error_handler cdecl (byval error_no as HPDF_STATUS, byval detail_no as HPDF_STATUS, byval user_data as any ptr) 146'****************************************************************************** 147'* Error handler 148'****************************************************************************** 149' do something here ... 150 print "error_no: ", error_no 151 print "detail_no:", detail_no 152 print "data: ", user_data 153 154end sub 155