示例#1
0
	// 0 <= pageNo <numPage
	CImage* getPage(int w, int h, int pageNo)
	{
		if(!cacheValid(w,h,pageNo))
		{
			// poppler uses 1 indexing for pageNo.

			double DPI_W=calcDPI_width(w, pageNo);
			double DPI_H=calcDPI_height(h, pageNo);
			double DPI=MIN(DPI_W, DPI_H);

			delete _textCache[pageNo]; _textCache[pageNo]=new intmatrixn();
			_textCacheState=pageNo;
			//_pdfDoc->getPageRotate(pageNo+1)
			_pdfDoc->displayPage(_outputDev, pageNo+1, DPI, DPI, 0, gFalse, gTrue, gFalse);
#ifdef USE_NULLOUTPUTDEV
			_nullOutputDev->setInfo(_pdfDoc->getPageRotate(pageNo+1),
									_pdfDoc->getCatalog()->getPage(pageNo+1)->getCropBox()->x1,
									_pdfDoc->getCatalog()->getPage(pageNo+1)->getCropBox()->y1,
									_pdfDoc->getPageCropWidth(pageNo+1),
									_pdfDoc->getPageCropHeight(pageNo+1),
									_outputDev->getBitmap()->getWidth(),
									_outputDev->getBitmap()->getHeight());
		
			_pdfDoc->displayPage(_nullOutputDev, pageNo+1, DPI, DPI, 0, gFalse, gTrue, gFalse);
#endif
			_textCacheState=-1;
				/*//_pdfDoc->displayPageSlice(_outputDev, pageNo+1, DPI, DPI, 0, gFalse, gTrue, gFalse, 20,20, 400,400);
				if(zoom2<zoom1)
				{
					if(h==_outputDev->getBitmap()->getHeight())
						bOkay=true;
					else
					{
						vDPI=72.0*h/_pdfDoc->getPageCropHeight(pageNo+1);
					}
				}
				else
				{
					if(w==_outputDev->getBitmap()->getWidth())
						bOkay=true;
					else
					{
						double tt=72*w/_pdfDoc->getPageCropHeight(pageNo+1);
					}
				}

			}
			while(!bOkay);*/

			SplashBitmap *temp=_outputDev->takeBitmap();

			CImage* ptr=new CImage();
			ptr->SetData(temp->getWidth(), temp->getHeight(), temp->getDataPtr(), temp->getRowSize());
			delete _bmpCache[pageNo]; _bmpCache[pageNo]=ptr;
			delete temp;
		}

		return _bmpCache[pageNo];
	}
示例#2
0
	double pageCropHeight(int pageNo)
	{
		int rotate=_pdfDoc->getPageRotate(pageNo+1);
		if(rotate==90 || rotate==270)
			return _pdfDoc->getPageCropWidth(pageNo+1);

		return _pdfDoc->getPageCropHeight(pageNo+1);
	}
示例#3
0
int main(int argc, char *argv[]) {
  PDFDoc *doc;
  GString *fileName;
  GString *ownerPW, *userPW;
  SplashColor paperColor;
  SplashOutputDev *splashOut;
  GBool ok;
  int exitCode;
  int pg;

  exitCode = 99;

  // parse args
  ok = parseArgs(argDesc, &argc, argv);
  
  if (!ok || argc != 2 || printVersion || printHelp) {
    fprintf(stderr, "pdf2jpeg version %s\n", xpdfVersion);
    fprintf(stderr, "%s\n", xpdfCopyright);
    if (!printVersion) {
      printUsage("pdf2jpeg", "<PDF-file> -o <jpegfile>", argDesc);
    }
    goto err0;
  }
  fileName = new GString(argv[1]);

  // read config file
  globalParams = new GlobalParams(cfgFileName);
  globalParams->setupBaseFonts(NULL);
  
  // open PDF file
  if (ownerPassword[0]) {
    ownerPW = new GString(ownerPassword);
  } else {
    ownerPW = NULL;
  }
  if (userPassword[0]) {
    userPW = new GString(userPassword);
  } else {
    userPW = NULL;
  }
  doc = new PDFDoc(fileName, ownerPW, userPW);
  if (userPW) {
    delete userPW;
  }
  if (ownerPW) {
    delete ownerPW;
  }
  if (!doc->isOk()) {
    exitCode = 1;
    goto err1;
  }

  paperColor[0] = paperColor[1] = paperColor[2] = 0xff;
  splashOut = new SplashOutputDev(splashModeRGB8, 1, gFalse, paperColor);
  
  splashOut->startDoc(doc->getXRef());

  if(page>=1 && page<=doc->getNumPages()) {
      double r = resolution;
      if(width) {
	int old_width = doc->getPageCropWidth(page);
	r = 72.0*width/old_width;
      }
      doc->displayPage(splashOut, page, r, r, 0, gFalse, gTrue, gFalse);
      SplashBitmap*bitmap = splashOut->getBitmap();
      if(bitmap) {
	Guchar*rgb = bitmap->getDataPtr();
	int width = bitmap->getWidth();
	int height = bitmap->getHeight();
	jpeg_save(rgb, width, height, quality, output);
      }
  }
  delete splashOut;

  exitCode = 0;

  // clean up
 err1:
  delete doc;
  delete globalParams;
 err0:

  // check for memory leaks
  Object::memCheck(stderr);
  gMemReport(stderr);

  return exitCode;
}