poppler_test.cpp

Go to the documentation of this file.
00001 /*
00002  * File Name: poppler_test.cpp
00003  */
00004 
00005 /*
00006  * This file is part of uds-plugin-pdf.
00007  *
00008  * uds-plugin-pdf is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * uds-plugin-pdf is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
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     // SplashColorMode mode = splashModeRGB8;
00086     SplashOutputDev * outputDev = new SplashOutputDev(mode/*Packed*/, 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 
Generated by  doxygen 1.6.2-20100208