设为首页 加入收藏

TOP

C++使用wkhtmltopdf的API的配置(五)
2012-11-28 12:59:16 来源: 作者: 【 】 浏览:1458
Tags:使用 wkhtmltopdf API 配置


 

实例:

  1. #include <stdio.h>  
  2. #include <stdlib.h>  
  3.   
  4. #include <stdbool.h>  
  5. #include <wkhtmltox\pdf.h>  
  6.   
  7. void progress_changed(wkhtmltopdf_converter* c, int p){  
  8.     printf("%3d%%\r", p);     
  9.     fflush(stdout);  
  10. }  
  11.   
  12. void phase_changed(wkhtmltopdf_converter* c){  
  13.     int phase = wkhtmltopdf_current_phase(c);  
  14.     printf("%s\n", wkhtmltopdf_phase_description(c,phase));   
  15. }  
  16.   
  17. void error(wkhtmltopdf_converter* c, const char* msg){  
  18.     fprintf(stderr, "Error: %s\n", msg);      
  19. }  
  20.   
  21. void warning(wkhtmltopdf_converter* c, const char* msg){  
  22.     fprintf(stderr, "Warning: %s\n", msg);    
  23. }  
  24.   
  25. int main(int argc, char *argv[]){  
  26.     if( argc != 3 ){  
  27.         fprintf(stderr, "Usage: html2pdf <url> <filename>\r\n");  
  28.         return -1;  
  29.     }  
  30.       
  31.     wkhtmltopdf_global_settings* gs;  
  32.     wkhtmltopdf_object_settings* os;  
  33.     wkhtmltopdf_converter* c;  
  34.       
  35.     wkhtmltopdf_init(false);  
  36.       
  37.     gs = wkhtmltopdf_create_global_settings();  
  38.     wkhtmltopdf_set_global_setting(gs, "out", argv );  
  39.       
  40.     os = wkhtmltopdf_create_object_settings();  
  41.     wkhtmltopdf_set_object_setting(os, "page", argv );  
  42.       
  43.     c = wkhtmltopdf_create_converter(gs);  
  44.       
  45.     wkhtmltopdf_set_progress_changed_callback(c, progress_changed);  
  46.     wkhtmltopdf_set_phase_changed_callback(c, phase_changed);  
  47.     wkhtmltopdf_set_error_callback(c, error);  
  48.     wkhtmltopdf_set_warning_callback(c, warning);  
  49.       
  50.     wkhtmltopdf_add_object(c, os, NULL);  
  51.       
  52.     if( !wkhtmltopdf_convert(c) )  
  53.         fprintf(stderr, "Convertion failed!");  
  54.           
  55.     printf("httpErrorCode: %d\n", wkhtmltopdf_http_error_code(c));  
  56.       
  57.     wkhtmltopdf_destroy_converter(c);  
  58.       
  59.     wkhtmltopdf_deinit();  
  60.       
  61.     return 0;  
  62. }  

      

首页 上一页 2 3 4 5 6 7 下一页 尾页 5/7/7
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++ 实现static const.. 下一篇hdu 4430 Yukari's..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: