poppler_test.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdio.h>
00028 #include "goo/GooList.h"
00029 #include "poppler/GlobalParams.h"
00030 #include "poppler/Object.h"
00031 #include "poppler/Link.h"
00032 #include "goo/GooString.h"
00033 #include "poppler/PDFDoc.h"
00034 #include "poppler/SplashOutputDev.h"
00035 #include "splash/SplashTypes.h"
00036
00037 #ifdef WIN32
00038 #include <windows.h>
00039 #else
00040 #include <sys/time.h>
00041 #endif
00042
00043 #define AppName "xpdf"
00044
00045 #ifdef WIN32
00046 #include "poppler/SecurityHandler.h"
00047 void CDECL error(int pos, char *msg, ...) {
00048 }
00049
00050 void * StandardSecurityHandler::getAuthData()
00051 {
00052 return 0;
00053 }
00054 #endif
00055
00056 int get_cur_time()
00057 {
00058 int now;
00059 #ifdef WIN32
00060 now = GetTickCount();
00061 #else
00062 struct timeval cur_time_struct;
00063 gettimeofday(&cur_time_struct, 0);
00064 now = cur_time_struct.tv_sec;
00065 #endif
00066 return now;
00067 }
00068
00069 int main(int argc, char * argv[])
00070 {
00071
00072 printf("open file %s\n", argv[1]);
00073 GooString * name = new GooString(argv[1]);
00074 #ifdef WIN32
00075 globalParams = new GlobalParams("");
00076 #else
00077 globalParams = new GlobalParams();
00078 #endif
00079 SplashColor white;
00080 white[0] = 255;
00081 white[1] = 255;
00082 white[2] = 255;
00083 SplashColorMode mode = splashModeMono8;
00084 printf("Use Mono8 mode\n");
00085
00086 SplashOutputDev * outputDev = new SplashOutputDev(mode, 4, gFalse, white);
00087
00088 PDFDoc * pdfdoc = new PDFDoc(name);
00089
00090 if (!pdfdoc->isOk())
00091 {
00092 printf("could not open doc %s\n", argv[1]);
00093 return -1;
00094 }
00095
00096 double zoom = 100.0f;
00097 if (argc >= 3)
00098 {
00099 zoom = atof(argv[2]);
00100 }
00101
00102 double hDPI = zoom * 0.01 * 150;
00103 double vDPI = zoom * 0.01 * 150;
00104 int rotate = 0;
00105 printf("start docuemnt pages %d\n", pdfdoc->getNumPages());
00106 outputDev->startDoc(pdfdoc->getXRef());
00107 printf("start document done!\n");
00108
00109 for(int i = 1; i <= pdfdoc->getNumPages(); ++i)
00110 {
00111 printf("render page %d, zoom:%f, crop width:%f, crop height:%f\n", i
00112 , zoom
00113 , pdfdoc->getPageCropWidth(i)
00114 , pdfdoc->getPageCropHeight(i));
00115 int cur_time = get_cur_time();
00116 RenderRet ret =
00117 pdfdoc->displayPage(outputDev, i, hDPI, vDPI, rotate, gFalse, gTrue, gTrue);
00118
00119
00120 printf("consume time:%d, result: %s\n", get_cur_time() - cur_time, ret == Render_Done ? "Done" : "Abort");
00121 }
00122
00123 return 0;
00124
00125 }
00126