1// $Id: image.cpp 14574 2005-10-29 16:27:43Z bonefish $ 2// PDFlib client: image example in C++ 3// 4// 5 6#include <iostream> 7 8#include "pdflib.hpp" 9 10int 11main(void) 12{ 13 try { 14 PDFlib *p; // pointer to the PDFlib class 15 int image; 16 char *imagefile = (char *) "nesrin.jpg"; 17 // This is where font/image/PDF input files live. Adjust as necessary. 18 char *searchpath = (char *) "../data"; 19 20 p = new PDFlib(); 21 22 // Open new PDF file 23 if (p->open_file("image.pdf") == -1) { 24 cerr << "Error: " << p->get_errmsg() << endl; 25 return 2; 26 } 27 28 p->set_parameter("SearchPath", searchpath); 29 30 // This line is required to avoid problems on Japanese systems 31 p->set_parameter("hypertextencoding", "host"); 32 33 p->set_info("Creator", "image.cpp"); 34 p->set_info("Author", "Thomas Merz"); 35 p->set_info("Title", "image sample (C++)!"); 36 37 image = p->load_image("auto", imagefile, ""); 38 39 if (image == -1) { 40 cerr << "Error: " << p->get_errmsg() << endl; 41 exit(3); 42 } 43 44 // dummy page size, will be adjusted by PDF_fit_image() 45 p->begin_page(10, 10); 46 p->fit_image(image, (float) 0.0,(float) 0.0, "adjustpage"); 47 p->close_image(image); 48 p->end_page(); // close page 49 50 p->close(); // close PDF document 51 } 52 catch (PDFlib::Exception &ex) { 53 cerr << "PDFlib exception occurred in hello sample: " << endl; 54 cerr << "[" << ex.get_errnum() << "] " << ex.get_apiname() 55 << ": " << ex.get_errmsg() << endl; 56 return 2; 57 } 58 59 return 0; 60} 61