1 /* 2 * PDF file output routines. 3 * 4 * Copyright 2008 by Tobias Hoffmann. 5 * 6 * This file is licensed as noted in "COPYING" 7 * which should have been included with this file. 8 * 9 */ 10 #include <time.h> 11 12 struct keyval_t { 13 char *key,*value; 14 }; 15 16 typedef struct { 17 long filepos; 18 19 int pagessize,pagesalloc; 20 int *pages; 21 22 int xrefsize,xrefalloc; 23 long *xref; 24 25 int kvsize,kvalloc; 26 struct keyval_t *kv; 27 } pdfOut; 28 29 /* allocates a new pdfOut structure 30 * returns NULL on error 31 */ 32 pdfOut *pdfOut_new(); 33 void pdfOut_free(pdfOut *pdf); 34 35 /* start outputting a pdf 36 * returns false on error 37 */ 38 int pdfOut_begin_pdf(pdfOut *pdf); 39 void pdfOut_finish_pdf(pdfOut *pdf); 40 41 /* General output routine for our pdf. 42 * Keeps track of characters actually written out 43 */ 44 void pdfOut_printf(pdfOut *pdf,const char *fmt,...) 45 __attribute__((format(printf, 2, 3))); 46 47 /* write out an escaped pdf string: e.g. (Text \(Test\)\n) 48 * >len==-1: use strlen(str) 49 */ 50 void pdfOut_putString(pdfOut *pdf,const char *str,int len); 51 void pdfOut_putHexString(pdfOut *pdf,const char *str,int len); 52 53 /* Format the broken up timestamp according to 54 * pdf requirements for /CreationDate 55 * NOTE: uses statically allocated buffer 56 */ 57 const char *pdfOut_to_pdfdate(struct tm *curtm); 58 59 /* begin a new object at current point of the 60 * output stream and add it to the xref table. 61 * returns the obj number. 62 */ 63 int pdfOut_add_xref(pdfOut *pdf); 64 65 /* adds page dictionary >obj to the global Pages tree 66 * returns false on error 67 */ 68 int pdfOut_add_page(pdfOut *pdf,int obj); 69 70 /* add a >key,>val pair to the document's Info dictionary 71 * returns false on error 72 */ 73 int pdfOut_add_kv(pdfOut *pdf,const char *key,const char *val); 74 75 /* Writes the font >emb including descriptor to the pdf 76 * and returns the object number. 77 * On error 0 is returned. 78 */ 79 struct _EMB_PARAMS; 80 int pdfOut_write_font(pdfOut *pdf,struct _EMB_PARAMS *emb); 81