int bbdocument_makethumb( char documenttype[],char document[],size_t dokument_size,char **imagebuffer,size_t *imageSize) { #ifdef BBDOCUMENT_IMAGE if (strcmp(documenttype,"pdf") == 0) { //pdf convert if (((*imagebuffer) = generate_pdf_thumbnail( document, dokument_size, imageSize )) == NULL) { return 0; } return 1; return 0; } else if (canconvert(documenttype) && (((*imagebuffer) = generate_thumbnail( document, dokument_size, imageSize )) == NULL)) { return 0; } #else #if BBDOCUMENT_IMAGE_BY_CONVERT if (strcmp(documenttype,"pdf") == 0) { //pdf convert /* if (((*imagebuffer) = generate_pdf_thumbnail_by_convert( document, dokument_size, imageSize )) == NULL) { return 0; } return 1; */ return 0; } else if (canconvert(documenttype)) { if ((((*imagebuffer) = generate_thumbnail_by_convert( document, dokument_size, imageSize, documenttype)) == NULL )) { printf("error: cant run generate_thumbnail_by_convert\n"); return 0; } else { return 1; } } #endif #endif //er bare her hvis vi ikke klarte og lage bilde, og da har vi selsakt ikke noe størelse //printf("imageSize %"PRId64" at %s:%i\n",(*imageSize),__FILE__,__LINE__); return 0; }
unsigned char* generate_pdf_thumbnail( const void *document, const size_t size, size_t *new_size ) { void *image; void *thumbnail; FILE *fp; char command[512]; char documentfile[PATH_MAX]; char imagefile[PATH_MAX]; struct stat inode; // lager en struktur for fstat å returnere. //tmpfilename = mktemp("/tmp/generateThumbnail_XXXXXX"); //make a unique temporary file name snprintf(documentfile,sizeof(documentfile),"%s.pdf",converttemptemplate); snprintf(imagefile,sizeof(imagefile),"%s.png",converttemptemplate); if ((fp = fopen(documentfile,"wb")) == NULL) { printf(documentfile); return NULL; } fwrite(document,1,size,fp); fclose(fp); snprintf(command,sizeof(command),"%s -dBATCH -dFirstPage=1 -dLastPage=1 -sDEVICE=png256 -dNOPAUSE -dSAFER -sOutputFile=%s %s",gspath,imagefile,documentfile); printf("runing %s\n",command); system(command); if ((fp = fopen(imagefile,"rb")) == NULL) { printf(imagefile); return NULL; } fstat(fileno(fp),&inode); image = malloc(inode.st_size); fread(image,1,inode.st_size,fp); fclose(fp); thumbnail = generate_thumbnail(image,inode.st_size,new_size); free(image); unlink(documentfile); unlink(imagefile); return thumbnail; }