#include #include #include #include /* * * PDF_set_value(p,"nameofvalue",(float)value); // get/set * - leading, textrise, textrendering,leading,horzscaling, * - charspacing, wordspacing, textx, texty * PDF_set_parameter(...) * - underline, overline, strikeout * */ int main(int argc, char *argv[]) { PDF *p; xmlDocPtr doc; xmlNodePtr cur; int pg=1; if (argc<3) { printf("Please usage %s [input.xml] [output.pdf]\n",argv[0]); return 1; } if( access(argv[1],R_OK) ) { printf("Cannot open input file \"%s\"\n",argv[1]); return 1; } p=PDF_new(); if (PDF_open_file(p,argv[2])<0) { printf("Cannot open output file for writing \"%s\"\n",argv[2]); return 1; } doc=xmlParseFile(argv[1]); if (!doc) { printf("Invalid XML document\n"); return 1; } cur=xmlDocGetRootElement(doc); if(xmlStrcmp(cur->name,(const xmlChar *)"xmlpdf")) { printf("Isn't a xmlpdf document (is <%s>)\n",cur->name); return 1; } cur=cur->xmlChildrenNode; while(cur) { xmlChar *author; float textx=0,texty=0, margeleft=0,margetop=0,margebottom=0; if (!strcmp("info",cur->name)) { PDF_set_info(p,"Creator",xmlGetProp(cur,"creator")); PDF_set_info(p,"Author",xmlGetProp(cur,"author")); PDF_set_info(p,"Title",xmlGetProp(cur,"author")); PDF_set_info(p,"Subject",xmlGetProp(cur,"subject")); PDF_set_info(p,"Keywords",xmlGetProp(cur,"keywords")); PDF_set_info(p,"Trapped",xmlGetProp(cur,"trapped")); } else if (!strcmp("page",cur->name)) { xmlChar *str,*str2; xmlNodePtr page; int w=a4_width, h=a4_height, i; // mides del full margeleft=0; margetop=h; // 0-0 marges margebottom=0; page=cur->xmlChildrenNode; str=xmlGetProp(cur,"type"); if (!strcmp("a3",str)) { w=a3_width; h=a3_height; } else if (!strcmp("a2",str)) { w=a2_width; h=a2_height; } printf("Page type: %s\n",str); PDF_begin_page(p,w,h); if (xmlGetProp(cur,"left")) margeleft=atoi(xmlGetProp(cur,"left")); if (xmlGetProp(cur,"top")) margetop=h-atoi(xmlGetProp(cur,"top")); if (xmlGetProp(cur,"bottom")) margebottom=atoi(xmlGetProp(cur,"bottom")); PDF_set_text_pos(p,margeleft,margetop); str=xmlNodeListGetString(doc,page,1); for(i=strlen(str);i;i--) if(str[i]=='\n')str[i]=' '; printf("page %d: %s\n",pg++,str); while(page) { if (!strcmp("t",page->name)) { // Text block char changePage=0; int font,fsize; int i,len,len2; xmlChar *str,*str2,*fnt; str=xmlNodeListGetString(doc,page->xmlChildrenNode,1); fnt=xmlGetProp(page,"font"); if (!fnt) fnt="Times-Roman"; if (!xmlGetProp(page,"size")) fsize=12; else fsize=atoi(xmlGetProp(page,"size")); font=PDF_findfont(p,fnt,"host",0); PDF_setfont(p,font,fsize); if (xmlGetProp(page,"x")) textx= atof(xmlGetProp(page,"x")); if (xmlGetProp(page,"y")) texty= atof(xmlGetProp(page,"y")); PDF_set_text_pos(p,margeleft+textx,margetop-texty); len2=xmlUTF8Strlen(str); len=strlen(str); UTF8Toisolat1(str,&len,str,&len); len=len2; str[len]=0; for(i=len;i;i--) if(str[i]=='\n') str[i]=0; i=0; while(iname)) { // Image block int img,x,y; float s; // scale xmlChar *type,*src,*buf; if (!xmlGetProp(page,"src") ) { printf("No src attribute on \n"); return 1; } else src=xmlGetProp(page,"src"); type=xmlGetProp(page,"type"); if (!type) type="jpeg"; img=PDF_open_image_file(p,"jpeg",src,"",0); if (img<0) { printf("Error loading image %s as %s.\n",src,type); return 1; } buf=xmlGetProp(page,"x"); if (!buf) x=50; else x=atoi(buf); buf=xmlGetProp(page,"y"); if (!buf) y=50; else y=atoi(buf); buf=xmlGetProp(page,"scale"); if (!buf) s=1.0f; else s=atof(buf); PDF_place_image(p,img,x,y,s); PDF_close_image(p,img); } page=page->next; } PDF_end_page(p); } cur=cur->next; } PDF_close(p); PDF_delete(p); return 0; }