// C2.cpp : Defines the entry point for the console application.
//#include "stdafx.h"
#include <iostream>
#include <cstdlib>#include "pdflib.hpp"using namespace std;int main(int argc, char* argv[])
{
try {

PDFlib *p;
int image;
char *imagefile = (char *) "nesrin.jpg";
// This is where font/image/PDF input files live. Adjust as necessary. 
char *searchpath = (char *) "../data";

p = new PDFlib();

//  This means we must check return values of load_font() etc.
p->set_parameter("errorpolicy", "return");

p->set_parameter("SearchPath", searchpath);

// This line is required to avoid problems on Japanese systems
p->set_parameter("hypertextencoding", "host");

if (p->begin_document("image.pdf", "") == -1) {
cerr << "Error: " << p->get_errmsg() << endl; return 2;
}

p->set_info("Creator", "image.cpp");
p->set_info("Author", "Thomas Merz");
p->set_info("Title", "image sample (C++)!");

image = p->load_image("auto", imagefile, "");

if (image == -1) {
cerr << "Error: " << p->get_errmsg() << endl;
exit(3);
}

// dummy page size, will be adjusted by PDF_fit_image()
p->begin_page_ext(10, 10, "");
p->fit_image(image, 0.0, 0.0, "adjustpage");
p->close_image(image);
p->end_page_ext("");

p->end_document("");
    }

    catch (PDFlib::Exception &ex) {
cerr << "PDFlib exception occurred in hello sample: " << endl;
cerr << "[" << ex.get_errnum() << "] " << ex.get_apiname()
<< ": " << ex.get_errmsg() << endl;
return 2;
    }

    return 0;
}
编绎后出现如下错误:
Deleting intermediate files and output files for project 'C2 - Win32 Debug'.
--------------------Configuration: C2 - Win32 Debug--------------------
Compiling...
StdAfx.cpp
Compiling...
C2.cpp
pdflib.cpp
d:\mycode\c2\pdflib.cpp(69) : warning C4005: 'PDFCPP_TRY' : macro redefinition
        d:\mycode\c2\pdflib.cpp(61) : see previous definition of 'PDFCPP_TRY'
d:\mycode\c2\pdflib.cpp(75) : warning C4005: 'PDFCPP_CATCH' : macro redefinition
        d:\mycode\c2\pdflib.cpp(65) : see previous definition of 'PDFCPP_CATCH'
d:\mycode\c2\pdflib.cpp(1671) : fatal error C1010: unexpected end of file while looking for precompiled header directive
Generating Code...
执行 cl.exe 时出错.C2.exe - 1 error(s), 0 warning(s)
两个例子C1与C2,问题是C1没有问题。