int main(void) { try { int i, stationery, page, regularfont, boldfont; string infile = "stationery.pdf"; // This is where font/image/PDF input files live. Adjust as necessary. string searchpath = "../data"; const double left = 55; const double right = 530; time_t timer; struct tm ltime; double fontsize = 12, leading, y; double sum, total; double pagewidth = 595, pageheight = 842; char buf[256]; char optlist[256]; char baseopt[256] = "ruler { 30 45 275 375 475} " "tabalignment {right left right right right} " "hortabmethod ruler fontsize 12 "; int textflow; PDFlib p; string closingtext = "Terms of payment: <fillcolor={rgb 1 0 0}>30 days net. " "<fillcolor={gray 0}>90 days warranty starting at the day of sale. " "This warranty covers defects in workmanship only. " "<fontname=Helvetica-BoldOblique encoding=host>Kraxi Systems, Inc. " "<resetfont>will, at its option, repair or replace the " "product under the warranty. This warranty is not transferable. " "No returns or exchanges will be accepted for wet products."; struct articledata { articledata(string n, double pr, int q): name(n), price(pr), quantity(q){} string name; double price; int quantity; }; articledata data[] = { articledata("Super Kite", 20, 2), articledata("Turbo Flyer", 40, 5), articledata("Giga Trash", 180, 1), articledata("Bare Bone Kit", 50, 3), articledata("Nitty Gritty", 20, 10), articledata("Pretty Dark Flyer", 75, 1), articledata("Free Gift", 0, 1), }; #define ARTICLECOUNT (sizeof(data)/sizeof(data[0])) static const string months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; // 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("invoice.pdf", "") == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } p.set_info("Creator", "invoice.cpp"); p.set_info("Author", "Thomas Merz"); p.set_info("Title", "PDFlib invoice generation demo (C++)"); stationery = p.open_pdi_document(infile, ""); if (stationery == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } page = p.open_pdi_page(stationery, 1, ""); if (page == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } boldfont = p.load_font("Helvetica-Bold", "host", ""); if (boldfont == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } regularfont = p.load_font("Helvetica", "host", ""); if (regularfont == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } leading = fontsize + 2; // Establish coordinates with the origin in the upper left corner. p.begin_page_ext(pagewidth, pageheight, "topdown"); p.fit_pdi_page(page, 0, pageheight, ""); p.close_pdi_page(page); p.setfont(regularfont, 12); // Print the address y = 170; p.set_value("leading", leading); p.show_xy("John Q. Doe", left, y); p.continue_text("255 Customer Lane"); p.continue_text("Suite B"); p.continue_text("12345 User Town"); p.continue_text("Everland"); // Print the header and date p.setfont(boldfont, 12); y = 300; p.show_xy("INVOICE", left, y); time(&timer); ltime = *localtime(&timer); sprintf(buf, "%s %d, %d", months[ltime.tm_mon].c_str(), ltime.tm_mday, ltime.tm_year + 1900); p.fit_textline(buf, right, y, "position {100 0}"); // Print the invoice header line p.setfont(boldfont, 12); // "position {0 0}" is left-aligned, "position {100 0}" right-aligned y = 370; sprintf(buf, "\tITEM\tDESCRIPTION\tQUANTITY\tPRICE\tAMOUNT"); sprintf(optlist, "%s font %d ", baseopt, boldfont); textflow = p.create_textflow(buf, optlist); if (textflow == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } p.fit_textflow(textflow, left, y-leading, right, y, ""); p.delete_textflow(textflow); // Print the article list p.setfont(regularfont, 12); y += 2*leading; total = 0; sprintf(optlist, "%s font %d ", baseopt, regularfont); for (i = 0; i < (int)ARTICLECOUNT; i++) { sum = data[i].price * data[i].quantity; sprintf(buf, "\t%d\t%s\t%d\t%.2f\t%.2f", i+1, (char *)data[i].name.c_str(), data[i].quantity, data[i].price, sum); textflow = p.create_textflow(buf, optlist); if (textflow == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } p.fit_textflow(textflow, left, y-leading, right, y, ""); p.delete_textflow(textflow); y += leading; total += sum; } y += leading; p.setfont(boldfont, 12); sprintf(buf, "%.2f", total); p.fit_textline(buf, right, y, "position {100 0}"); // Print the closing text y += 5*leading; strcpy(optlist, "alignment=justify leading=120% "); strcat(optlist, "fontname=Helvetica fontsize=12 encoding=host "); textflow = p.create_textflow(closingtext, optlist); if (textflow == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } p.fit_textflow(textflow, left, y+6*leading, right, y, ""); p.delete_textflow(textflow); p.end_page_ext(""); p.end_document(""); p.close_pdi_document(stationery); } catch (PDFlib::Exception &ex) { cerr << "PDFlib exception occurred in invoice sample: " << endl; cerr << "[" << ex.get_errnum() << "] " << ex.get_apiname() << ": " << ex.get_errmsg() << endl; return 2; } return 0; }
int main(void) { try { /* This is where the data files are. Adjust as necessary. */ const wstring searchpath = L"../data"; const wstring outfile = L"starter_type3font.pdf"; wostringstream buf; PDFlib p; int font; double x, y; p.set_parameter(L"SearchPath", searchpath); /* This means we must check return values of load_font() etc. */ p.set_parameter(L"errorpolicy", L"return"); if (p.begin_document(outfile, L"") == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } p.set_info(L"Creator", L"PDFlib starter sample"); p.set_info(L"Title", L"starter_type3font"); /* Create the font "SimpleFont" containing the glyph L"l", * the glyph "space" for spaces and the glyph ".notdef" for any * undefined character */ p.begin_font(L"SimpleFont", 0.001, 0.0, 0.0, 0.001, 0.0, 0.0, L""); p.begin_glyph(L".notdef", 266, 0, 0, 0, 0); p.end_glyph(); p.begin_glyph(L"space", 266, 0, 0, 0, 0); p.end_glyph(); p.begin_glyph(L"l", 266, 0, 0, 266, 570); p.setlinewidth(20); p.setdash(0, 0); x = 197; y = 10; p.moveto(x, y); y += 530; p.lineto(x, y); x -= 64; p.lineto(x, y); y -= 530; p.moveto(x, y); x += 128; p.lineto(x, y); p.stroke(); p.end_glyph(); p.end_font(); /* Start page */ p.begin_page_ext(0, 0, L"width=300 height=200"); /* Load the new L"SimpleFont" font */ font = p.load_font(L"SimpleFont", L"winansi", L""); if (font == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } /* Output the characters L"l" and L"space" of the L"SimpleFont" font. * The character L"x" is undefined and will be mapped to L".notdef" */ buf.str(L""); buf << L"font=" << font << L" fontsize=40"; p.fit_textline(L"lll lllxlll", 100, 100, buf.str()); p.end_page_ext(L""); p.end_document(L""); } catch (PDFlib::Exception &ex) { wcerr << L"PDFlib exception occurred in invoice sample: " << endl << L"[" << ex.get_errnum() << L"] " << ex.get_apiname() << L": " << ex.get_errmsg() << endl; return 2; } return 0; }
int main(void) { try { int i, form, page, regularfont, boldfont; string infile = "stationery.pdf"; // This is where font/image/PDF input files live. Adjust as necessary. string searchpath = "../data"; const float col1 = 55; const float col2 = 100; const float col3 = 330; const float col4 = 430; const float col5 = 530; time_t timer; struct tm ltime; float fontsize = 12, leading, y; float sum, total; float pagewidth = 595, pageheight = 842; char buf[128]; PDFlib p; string closingtext = "30 days warranty starting at the day of sale. " "This warranty covers defects in workmanship only. " "Kraxi Systems, Inc. will, at its option, repair or replace the " "product under the warranty. This warranty is not transferable. " "No returns or exchanges will be accepted for wet products."; struct articledata { articledata(string n, float pr, int q): name(n), price(pr), quantity(q) {} string name; float price; int quantity; }; articledata data[] = { articledata("Super Kite", 20, 2), articledata("Turbo Flyer", 40, 5), articledata("Giga Trash", 180, 1), articledata("Bare Bone Kit", 50, 3), articledata("Nitty Gritty", 20, 10), articledata("Pretty Dark Flyer", 75, 1), articledata("Free Gift", 0, 1), }; #define ARTICLECOUNT (sizeof(data)/sizeof(data[0])) static const string months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; // open new PDF file if (p.open_file("invoice.pdf") == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } p.set_parameter("SearchPath", searchpath); // This line is required to avoid problems on Japanese systems p.set_parameter("hypertextencoding", "host"); p.set_info("Creator", "invoice.cpp"); p.set_info("Author", "Thomas Merz"); p.set_info("Title", "PDFlib invoice generation demo (C++)"); form = p.open_pdi(infile, "", 0); if (form == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } page = p.open_pdi_page(form, 1, ""); if (page == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } boldfont = p.load_font("Helvetica-Bold", "host", ""); regularfont = p.load_font("Helvetica", "host", ""); leading = fontsize + 2; // Establish coordinates with the origin in the upper left corner. p.set_parameter("topdown", "true"); p.begin_page(pagewidth, pageheight); // A4 page p.fit_pdi_page(page, 0, pageheight, ""); p.close_pdi_page(page); p.setfont(regularfont, 12); // Print the address y = 170; p.set_value("leading", leading); p.show_xy("John Q. Doe", col1, y); p.continue_text("255 Customer Lane"); p.continue_text("Suite B"); p.continue_text("12345 User Town"); p.continue_text("Everland"); // Print the header and date p.setfont(boldfont, 12); y = 300; p.show_xy("INVOICE", col1, y); time(&timer); ltime = *localtime(&timer); sprintf(buf, "%s %d, %d", months[ltime.tm_mon].c_str(), ltime.tm_mday, ltime.tm_year + 1900); p.fit_textline(buf, col5, y, "position {100 0}"); // Print the invoice header line p.setfont(boldfont, 12); // "position {0 0}" is left-aligned, "position {100 0}" right-aligned y = 370; p.fit_textline("ITEM", col1, y, "position {0 0}"); p.fit_textline("DESCRIPTION", col2, y, "position {0 0}"); p.fit_textline("QUANTITY", col3, y, "position {100 0}"); p.fit_textline("PRICE", col4, y, "position {100 0}"); p.fit_textline("AMOUNT", col5, y, "position {100 0}"); // Print the article list p.setfont(regularfont, 12); y += 2*leading; total = 0; for (i = 0; i < (int)ARTICLECOUNT; i++) { sprintf(buf, "%d", i+1); p.show_xy(buf, col1, y); p.show_xy(data[i].name, col2, y); sprintf(buf, "%d", data[i].quantity); p.fit_textline(buf, col3, y, "position {100 0}"); sprintf(buf, "%.2f", data[i].price); p.fit_textline(buf, col4, y, "position {100 0}"); sum = data[i].price * data[i].quantity; sprintf(buf, "%.2f", sum); p.fit_textline(buf, col5, y, "position {100 0}"); y += leading; total += sum; } y += leading; p.setfont(boldfont, 12); sprintf(buf, "%.2f", total); p.fit_textline(buf, col5, y, "position {100 0}"); // Print the closing text y += 5*leading; p.setfont(regularfont, 12); p.set_value("leading", leading); p.show_boxed(closingtext, col1, y + 4*leading, col5-col1, 4*leading, "justify", ""); p.end_page(); p.close(); p.close_pdi(form); } catch (PDFlib::Exception &ex) { cerr << "PDFlib exception occurred in invoice sample: " << endl; cerr << "[" << ex.get_errnum() << "] " << ex.get_apiname() << ": " << ex.get_errmsg() << endl; return 2; } return 0; }
int main(void) { try { PDFlib p; int i, blockcontainer, page; const string infile = "boilerplate.pdf"; /* This is where font/image/PDF input files live. Adjust as necessary. * * Note that this directory must also contain the LuciduxSans font * outline and metrics files. */ const string searchpath = "../data"; struct blockdata { blockdata(string n, string v): name(n), value(v){} string name; string value; }; blockdata data[] = { blockdata("name", "Victor Kraxi"), blockdata("business.title", "Chief Paper Officer"), blockdata("business.address.line1", "17, Aviation Road"), blockdata("business.address.city", "Paperfield"), blockdata("business.telephone.voice","phone +1 234 567-89"), blockdata("business.telephone.fax", "fax +1 234 567-98"), blockdata("business.email", "*****@*****.**"), blockdata("business.homepage", "www.kraxi.com"), }; #define BLOCKCOUNT (sizeof(data)/sizeof(data[0])) // This means we must check return values of load_font() etc. p.set_parameter("errorpolicy", "return"); // Set the search path for fonts and PDF files p.set_parameter("SearchPath", searchpath); // This line is required to avoid problems on Japanese systems p.set_parameter("hypertextencoding", "host"); if (p.begin_document("businesscard.pdf", "") == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } p.set_info("Creator", "businesscard.cpp"); p.set_info("Author", "Thomas Merz"); p.set_info("Title","PDFlib block processing sample (C++)"); blockcontainer = p.open_pdi_document(infile, ""); if (blockcontainer == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } page = p.open_pdi_page(blockcontainer, 1, ""); if (page == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } p.begin_page_ext(20, 20, ""); // dummy page size // This will adjust the page size to the block container's size. p.fit_pdi_page(page, 0, 0, "adjustpage"); // Fill all text blocks with dynamic data for (i = 0; i < (int) BLOCKCOUNT; i++) { if (p.fill_textblock(page, data[i].name, data[i].value, "embedding encoding=host") == -1) { cerr << "Error: " << p.get_errmsg() << endl; } } p.end_page_ext(""); p.close_pdi_page(page); p.end_document(""); p.close_pdi_document(blockcontainer); } catch (PDFlib::Exception &ex) { cerr << "PDFlib exception occurred in businesscard sample: " << endl; cerr << "[" << ex.get_errnum() << "] " << ex.get_apiname() << ": " << ex.get_errmsg() << endl; return 99; } return 0; }
int main(void) { try { /* This is where the data files are. Adjust as necessary. */ string searchpath = "../data"; string outfile = "starter_image.pdf"; #define BUFLEN 1024 char buf[BUFLEN]; PDFlib p; string imagefile = "lionel.jpg"; int font, image; int bw = 400, bh = 200; int x = 20, y = 580, yoffset = 260; p.set_parameter("SearchPath", searchpath); /* This means we must check return values of load_font() etc. */ p.set_parameter("errorpolicy", "return"); if (p.begin_document(outfile, "") == -1) { cerr << "Error: " << p.get_errmsg() << endl; return 2; } p.set_info("Creator", "PDFlib starter sample"); p.set_info("Title", "starter_image"); /* For PDFlib Lite: change "unicode" to "winansi" */ font = p.load_font("Helvetica", "winansi", ""); if (font == -1) { cerr << "Error: " << p.get_errmsg() << endl; return 2; } /* Load the image */ image = p.load_image("auto", imagefile, ""); if (image == -1) { cerr << "Error: " << p.get_errmsg() << endl; return 2; } /* Start page 1 */ p.begin_page_ext(0, 0, "width=a4.width height=a4.height"); p.setfont(font, 12); /* ------------------------------------ * Place the image in its original size * ------------------------------------ */ /* Position the image in its original size with its lower left corner * at the reference point (20, 380) */ p.fit_image(image, 20, 380, ""); /* Output some descriptive text */ p.fit_textline( "The image is placed with the lower left corner in its original " "size at reference point (20, 380):", 20, 820, ""); p.fit_textline("fit_image(image, 20, 380, \"\");", 20, 800, ""); /* -------------------------------------------------------- * Place the image with scaling and orientation to the west * -------------------------------------------------------- */ /* Position the image with its lower right corner at the reference * point (580, 20). * "scale=0.5" scales the image by 0.5. * "orientate=west" orientates the image to the west. */ p.fit_image(image, 580, 20, "scale=0.5 position={right bottom} orientate=west"); /* Output some descriptive text */ p.fit_textline( "The image is placed with a scaling of 0.5 and an orientation to " "the west with the lower right corner", 580, 320, "position={right bottom}"); p.fit_textline( " at reference point (580, 20): fit_image(image, 580, 20, " "\"scale=0.5 orientate=west position={right bottom}\");", 580, 300, "position={right bottom}"); p.end_page_ext(""); /* Start page 2 */ p.begin_page_ext(0, 0, "width=a4.width height=a4.height"); p.setfont(font, 12); /* -------------------------------------- * Fit the image into a box with clipping * -------------------------------------- */ /* The "boxsize" option defines a box with a given width and height and * its lower left corner located at the reference point. * "position={right top}" positions the image on the top right of the * box. * "fitmethod=clip" clips the image to fit it into the box. */ sprintf(buf, "boxsize={%d %d} position={right top} fitmethod=clip", bw, bh); p.fit_image(image, x, y, buf); /* Output some descriptive text */ p.fit_textline( "fit_image(image, x, y, \"boxsize={400 200} position={right top} " "fitmethod=clip\");", 20, y+bh+10, ""); /* --------------------------------------------------- * Fit the image into a box with proportional resizing * --------------------------------------------------- */ /* The "boxsize" option defines a box with a given width and height and * its lower left corner located at the reference point. * "position={center}" positions the image in the center of the * box. * "fitmethod=meet" resizes the image proportionally until its height * or width completely fits into the box. * The "showborder" option is used to illustrate the borders of the box. */ sprintf(buf, "boxsize={%d %d} position={center} fitmethod=meet showborder", bw, bh); p.fit_image(image, x, y-=yoffset, buf); /* Output some descriptive text */ p.fit_textline( "fit_image(image, x, y, \"boxsize={400 200} position={center} " "fitmethod=meet showborder\");", 20, y+bh+10, ""); /* --------------------------------- * Fit the image into a box entirely * --------------------------------- */ /* The "boxsize" option defines a box with a given width and height and * its lower left corner located at the reference point. * By default, the image is positioned in the lower left corner of the * box. * "fitmethod=entire" resizes the image proportionally until its height * or width completely fits into the box. */ sprintf(buf, "boxsize={%d %d} fitmethod=entire", bw, bh); p.fit_image(image, x, y-=yoffset, buf); /* Output some descriptive text */ p.fit_textline( "fit_image(image, x, y, \"boxsize={400 200} fitmethod=entire\");", 20, y+bh+10, ""); p.end_page_ext(""); p.close_image(image); p.end_document(""); } catch (PDFlib::Exception &ex) { cerr << "PDFlib exception occurred:" << endl; cerr << "[" << ex.get_errnum() << "] " << ex.get_apiname() << ": " << ex.get_errmsg() << endl; return 2; } return 0; }
int main(void) { try { int font; PDFlib p; // the PDFlib object // open new PDF file if (p.open_file("hello.pdf") == -1) { cerr << "Error: " << p.get_errmsg() << endl; return 2; } // This line is required to avoid problems on Japanese systems p.set_parameter("hypertextencoding", "host"); p.set_info("Creator", "hello.cpp"); p.set_info("Author", "Thomas Merz"); p.set_info("Title", "Hello, world (C++)!"); // start a new page p.begin_page((float) a4_width, (float) a4_height); // Change "host" encoding to "winansi" or whatever you need! font = p.load_font("Helvetica-Bold", "host", ""); p.setfont(font, 24); p.set_text_pos(50, 700); p.show("Hello, world!"); p.continue_text("(says C++)"); p.end_page(); // close page p.close(); // close PDF 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; }
int main(void) { try { /* This is where the data files are. Adjust as necessary.*/ const wstring searchpath = L"../data"; PDFlib p; const wstring imagefile = L"nesrin.jpg"; int font, image, spot, icc; wostringstream optlist; // This means we must check return values of load_font() etc. p.set_parameter(L"errorpolicy", L"return"); p.set_parameter(L"SearchPath", searchpath); if (p.begin_document(L"starter_pdfx3.pdf", L"pdfx=PDF/X-3:2003") == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } p.set_info(L"Creator", L"PDFlib starter sample"); p.set_info(L"Title", L"starter_pdfx3"); /* * You can use one of the Standard output intents (e.g. for SWOP * printing) which do not require an ICC profile: p.load_iccprofile(L"CGATS TR 001", L"usage=outputintent"); * However, if you use ICC or Lab color you must load an ICC * profile as output intent: */ if (p.load_iccprofile(L"ISOcoated.icc", L"usage=outputintent") == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; wcerr << L"Please install the ICC profile package from " << L"www.pdflib.com to run the PDF/X starter sample." << endl; return 2; } p.begin_page_ext(595, 842, L""); /* Font embedding is required for PDF/X */ font = p.load_font(L"LuciduxSans-Oblique", L"winansi", L"embedding"); if (font == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } p.setfont(font, 24); spot = p.makespotcolor(L"PANTONE 123 C"); p.setcolor(L"fill", L"spot", spot, 1.0, 0.0, 0.0); p.fit_textline(L"PDF/X-3:2003 starter", 50, 700, L""); /* The RGB image below needs an ICC profile; we use sRGB. */ icc = p.load_iccprofile(L"sRGB", L""); optlist.str(L""); optlist << L"iccprofile=" << icc; image = p.load_image(L"auto", imagefile, optlist.str()); if (image == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } p.fit_image(image, 0.0, 0.0, L"scale=0.5"); p.end_page_ext(L""); p.end_document(L""); } catch (PDFlib::Exception &ex) { wcerr << L"PDFlib exception occurred:" << endl << L"[" << ex.get_errnum() << L"] " << ex.get_apiname() << L": " << ex.get_errmsg() << endl; return 2; } return 0; }
int main(void) { try { int i, stationery, page, regularfont, boldfont; const wstring infile = L"stationery.pdf"; // This is where font/image/PDF input files live. Adjust as necessary. wstring searchpath = L"../data"; const double left = 55; const double right = 530; time_t timer; struct tm ltime; double fontsize = 12, leading, y; double sum, total; double pagewidth = 595, pageheight = 842; wostringstream buf; wostringstream optlist; const wstring baseopt = L"ruler { 30 45 275 375 475} " L"tabalignment {right left right right right} " L"hortabmethod ruler fontsize 12 "; int textflow; PDFlib p; const wstring closingtext = L"Terms of payment: <fillcolor={rgb 1 0 0}>30 days net. " L"<fillcolor={gray 0}>90 days warranty starting at the day " L"of sale. This warranty covers defects in workmanship only. " L"<fontname=Helvetica-BoldOblique encoding=host>Kraxi Systems, " L"Inc. <resetfont>will, at its option, repair or replace the " L"product under the warranty. This warranty is not transferable. " L"No returns or exchanges will be accepted for wet products."; struct articledata { articledata(wstring n, double pr, int q): name(n), price(pr), quantity(q) {} wstring name; double price; int quantity; }; const articledata data[] = { articledata(L"Super Kite", 20, 2), articledata(L"Turbo Flyer", 40, 5), articledata(L"Giga Trash", 180, 1), articledata(L"Bare Bone Kit", 50, 3), articledata(L"Nitty Gritty", 20, 10), articledata(L"Pretty Dark Flyer", 75, 1), articledata(L"Free Gift", 0, 1), }; const int ARTICLECOUNT = sizeof(data) / sizeof(data[0]); static const wstring months[] = { L"January", L"February", L"March", L"April", L"May", L"June", L"July", L"August", L"September", L"October", L"November", L"December" }; // This means we must check return values of load_font() etc. p.set_parameter(L"errorpolicy", L"return"); p.set_parameter(L"SearchPath", searchpath); if (p.begin_document(L"invoice.pdf", L"") == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return(2); } p.set_info(L"Creator", L"invoice.cpp"); p.set_info(L"Author", L"Thomas Merz"); p.set_info(L"Title", L"PDFlib invoice generation demo (C++)"); stationery = p.open_pdi_document(infile, L""); if (stationery == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } page = p.open_pdi_page(stationery, 1, L""); if (page == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } boldfont = p.load_font(L"Helvetica-Bold", L"host", L""); if (boldfont == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } regularfont = p.load_font(L"Helvetica", L"host", L""); if (regularfont == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } leading = fontsize + 2; // Establish coordinates with the origin in the upper left corner. p.begin_page_ext(pagewidth, pageheight, L"topdown"); p.fit_pdi_page(page, 0, pageheight, L""); p.close_pdi_page(page); p.setfont(regularfont, 12); // Print the address y = 170; p.set_value(L"leading", leading); p.show_xy(L"John Q. Doe", left, y); p.continue_text(L"255 Customer Lane"); p.continue_text(L"Suite B"); p.continue_text(L"12345 User Town"); p.continue_text(L"Everland"); // Print the header and date p.setfont(boldfont, 12); y = 300; p.show_xy(L"INVOICE", left, y); time(&timer); ltime = *localtime(&timer); buf.str(L""); buf << months[ltime.tm_mon].c_str() << " " << ltime.tm_mday << ", " << ltime.tm_year + 1900; p.fit_textline(buf.str(), right, y, L"position {100 0}"); // Print the invoice header line p.setfont(boldfont, 12); // L"position {0 0}" is left-aligned, L"position {100 0}" right-aligned y = 370; optlist << baseopt << " font " << boldfont; textflow = p.create_textflow( L"\tITEM\tDESCRIPTION\tQUANTITY\tPRICE\tAMOUNT", optlist.str()); if (textflow == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } p.fit_textflow(textflow, left, y-leading, right, y, L""); p.delete_textflow(textflow); // Print the article list p.setfont(regularfont, 12); y += 2*leading; total = 0; optlist.str(L""); optlist << baseopt << " font " << regularfont; for (i = 0; i < (int)ARTICLECOUNT; i++) { sum = data[i].price * data[i].quantity; buf.str(L""); buf << L"\t" << (i + 1) << L"\t" << data[i].name << L"\t" << data[i].quantity << L"\t"; buf.setf(ios_base::fixed, ios_base::floatfield); buf.precision(2); buf << data[i].price << L"\t" << sum; textflow = p.create_textflow(buf.str(), optlist.str()); if (textflow == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } p.fit_textflow(textflow, left, y-leading, right, y, L""); p.delete_textflow(textflow); y += leading; total += sum; } y += leading; p.setfont(boldfont, 12); buf.str(L""); buf.setf(ios_base::fixed, ios_base::floatfield); buf.precision(2); buf << total; p.fit_textline(buf.str(), right, y, L"position {100 0}"); // Print the closing text y += 5*leading; optlist.str(L""); optlist << L"alignment=justify leading=120% " << L"fontname=Helvetica fontsize=12 encoding=host "; textflow = p.create_textflow(closingtext, optlist.str()); if (textflow == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } p.fit_textflow(textflow, left, y+6*leading, right, y, L""); p.delete_textflow(textflow); p.end_page_ext(L""); p.end_document(L""); p.close_pdi_document(stationery); } catch (PDFlib::Exception &ex) { wcerr << L"PDFlib exception occurred in invoice sample: " << endl << L"[" << ex.get_errnum() << L"] " << ex.get_apiname() << L": " << ex.get_errmsg() << endl; return 2; } return 0; }
int main(void) { try { /* This is where the data files are. Adjust as necessary. */ const wstring searchpath = L"../data"; PDFlib p; const wstring imagefile = L"nesrin.jpg"; int font; int image; // This means we must check return values of load_font() etc. p.set_parameter(L"errorpolicy", L"return"); p.set_parameter(L"SearchPath", searchpath); if (p.begin_document(L"starter_pdfa1b.pdf", L"pdfa=PDF/A-1b:2005") == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } /* * We use sRGB as output intent since it allows the color * spaces CIELab, ICC-based, grayscale, and RGB. * * If you need CMYK color you must use a CMYK output profile. */ p.load_iccprofile(L"sRGB", L"usage=outputintent"); p.set_info(L"Creator", L"PDFlib starter sample"); p.set_info(L"Title", L"starter_pdfa1b"); p.begin_page_ext(595, 842, L""); /* Font embedding is required for PDF/A */ font = p.load_font(L"LuciduxSans-Oblique", L"winansi", L"embedding"); if (font == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } p.setfont(font, 24); p.fit_textline(L"PDF/A-1b:2005 starter", 50, 700, L""); /* We can use an RGB image since we already supplied an * output intent profile. */ image = p.load_image(L"auto", imagefile, L""); if (image == -1){ wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } /* Place the image at the bottom of the page */ p.fit_image(image, 0.0, 0.0, L"scale=0.5"); p.end_page_ext(L""); p.close_image(image); p.end_document(L""); } catch (PDFlib::Exception &ex) { wcerr << L"PDFlib exception occurred:" << endl << L"[" << ex.get_errnum() << L"] " << ex.get_apiname() << L": " << ex.get_errmsg() << endl; return 2; } return 0; }
int main(void) { 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; }
int main(void) { try { /* This is where the data files are. Adjust as necessary. */ const wstring searchpath = L"../data"; const wstring outfile = L"starter_graphics.pdf"; PDFlib p; double xt=20, x = 210, y=770, dy=90; int font; p.set_parameter(L"SearchPath", searchpath); /* This means we must check return values of load_font() etc. */ p.set_parameter(L"errorpolicy", L"return"); if (p.begin_document(outfile, L"") == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } p.set_info(L"Creator", L"PDFlib starter sample"); p.set_info(L"Title", L"starter_graphics"); font = p.load_font(L"Helvetica", L"winansi", L""); if (font == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } /* Start an A4 page */ p.begin_page_ext(0, 0, L"width=a4.width height=a4.height"); /* Set the font */ p.setfont(font, 14); /* Set the line width */ p.setlinewidth(2.0); /* Set the stroke color */ p.setcolor(L"stroke", L"rgb", 0.0, 0.5, 0.5, 0.0); /* Set the fill color */ p.setcolor(L"fill", L"rgb", 0.0, 0.85, 0.85, 0.0); /* ------------- * Stroke a line * ------------- */ /* Set the current point for graphics output */ p.moveto(x, y); /* Draw a line from the current point to the supplied point */ p.lineto(x+300, y+50); /* Stroke the path using the current line width and stroke color, and * clear it */ p.stroke(); /* Output some descriptive black text */ p.fit_textline(L"lineto() and stroke()", xt, y, L"fillcolor={gray 0}"); /* -------------- * Stroke a curve * -------------- */ /* Set the current point for graphics output */ p.moveto(x, y-=dy); /* Draw a Bézier curve from the current point to (x3, y3), using three * control points */ p.curveto(x+50, y+40, x+200, y+80, x+300, y+30); /* Stroke the path using the current line width and stroke color, and * clear it */ p.stroke(); /* Output some descriptive black text */ p.fit_textline(L"curveto() and stroke()", xt, y, L"fillcolor={gray 0}"); /* --------------- * Stroke a circle * --------------- */ /* Draw a circle at position (x, y) with a radius of 40 */ p.circle(x, y-=dy, 40); /* Stroke the path using the current line width and stroke color, and * clear it */ p.stroke(); /* Output some descriptive black text */ p.fit_textline(L"circle() and stroke()", xt, y, L"fillcolor={gray 0}"); /* --------------------- * Stroke an arc segment * --------------------- */ /* Draw an arc segment counterclockwise at position (x, y) with a radius * of 40 starting at an angle of 90 degrees and ending at 180 degrees */ p.arc(x, y-=dy+20, 40, 90, 180); /* Stroke the path using the current line width and stroke color, and * clear it */ p.stroke(); /* Output some descriptive black text */ p.fit_textline(L"arc() and stroke()", xt, y, L"fillcolor={gray 0}"); /* ------------------ * Stroke a rectangle * ------------------ */ /* Draw a rectangle at position (x, y) with a width of 200 and a height * of 50 */ p.rect(x, y-=dy, 200, 50); /* Stroke the path using the current line width and stroke color, and * clear it */ p.stroke(); /* Output some descriptive black text */ p.fit_textline(L"rect() and stroke()", xt, y, L"fillcolor={gray 0}"); /* ---------------- * Fill a rectangle * ---------------- */ /* Draw a rectangle at position (x, y) with a width of 200 and a height * of 50 */ p.rect(x, y-=dy, 200, 50); /* Fill the path using current fill color, and clear it */ p.fill(); /* Output some descriptive black text */ p.fit_textline(L"rect() and fill()", xt, y, L"fillcolor={gray 0}"); /* --------------------------- * Fill and stroke a rectangle * --------------------------- */ /* Draw a rectangle at position (x, y) with a width of 200 and a height * of 50 */ p.rect(x, y-=dy, 200, 50); /* Fill and stroke the path using the current line width, fill color, * and stroke color, and clear it */ p.fill_stroke(); /* Output some descriptive black text */ p.fit_textline(L"rect() and fill_stroke()", xt, y, L"fillcolor={gray 0}"); /* ------------------------------------------------------------- * Draw a line and an arc, close the path and fill and stroke it * ------------------------------------------------------------- */ /* Set the current point for graphics output */ p.moveto(x-40, y-=dy); /* Draw a line from the current point to the supplied point */ p.lineto(x, y); /* Draw an arc segment counterclockwise at position (x, y) with a radius * of 40 starting at an angle of 90 degrees and ending at 180 degrees */ p.arc(x, y, 40, 90, 180); /* Close the path and stroke and fill it, i.e. close the current subpath * (add a straight line segment from the current point to the starting * point of the path), and stroke and fill the complete current path */ p.closepath_fill_stroke(); /* Output some descriptive black text */ p.fit_textline(L"lineto(), arc(), and", xt, y+20, L"fillcolor={gray 0}"); p.fit_textline(L"closepath_fill_stroke()", xt, y, L"fillcolor={gray 0}"); /* ----------------------------------------------------------------- * Draw a rectangle and use it as the clipping a path. Draw and fill * a circle and clip it according to the clipping path defined. * ----------------------------------------------------------------- */ /* Save the current graphics state including the current clipping * path which is set to the entire page by default */ p.save(); /* Draw a rectangle at position (x, y) with a width of 200 and a height * of 50 */ p.rect(x, y-=dy, 200, 50); /* Use the current path as the clipping path for subsequent operations */ p.clip(); /* Draw a circle at position (x, y) with a radius of 100 */ p.circle(x, y, 80); /* Fill the path with the current fill color and clear it */ p.fill(); /* Restore the graphics state which has been saved above */ p.restore(); /* Output some descriptive black text */ p.fit_textline(L"rect(), clip(),", xt, y+20, L"fillcolor={gray 0}"); p.fit_textline(L"circle(), and fill()", xt, y, L"fillcolor={gray 0}"); p.end_page_ext(L""); p.end_document(L""); } catch (PDFlib::Exception &ex) { wcerr << L"PDFlib exception occurred:" << endl << L"[" << ex.get_errnum() << L"] " << ex.get_apiname() << L": " << ex.get_errmsg() << endl; return 2; } return 0; }
int main(void) { try { /* This is where the data files are. Adjust as necessary. */ const wstring searchpath = L"../data"; const wstring outfile = L"starter_color.pdf"; PDFlib p; int font, spot; int y = 800, x = 50, xoffset1=80, xoffset2 = 100, yoffset = 70, r = 30; double icchandle; p.set_parameter(L"SearchPath", searchpath); /* This means we must check return values of load_font() etc. */ p.set_parameter(L"errorpolicy", L"return"); if (p.begin_document(outfile, L"") == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } p.set_info(L"Creator", L"PDFlib starter sample"); p.set_info(L"Title", L"starter_color"); /* Load the font */ font = p.load_font(L"Helvetica", L"winansi", L""); if (font == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } /* Start the page */ p.begin_page_ext(0, 0, L"width=a4.width height=a4.height"); p.setfont(font, 14); /* ------------------------------------------------------------------- * Use default colors * * If no special color is set the default values will be used. The * default values are restored at the beginning of the page. * 0=black in the Gray color space is the default fill and stroke * color in many cases, as shown in our sample. * ------------------------------------------------------------------- */ /* Fill a circle with the default black fill color */ p.circle(x, y-=yoffset, r); p.fill(); /* Output text with default black fill color */ p.fit_textline( L"Circle and text filled with default color {gray 0}", x+xoffset2, y, L""); p.fit_textline(L"1.", x+xoffset1, y, L""); /* ------------------------------------------------------------------- * Use the Gray color space * * Gray color is defined by Gray values between 0=black and 1=white. * ------------------------------------------------------------------- */ /* Using setcolor(), set the current fill color to a light gray * represented by (0.5, 0, 0, 0) which defines 50% gray. Since gray * colors are defined by only one value, the last three function * parameters must be set to 0. */ p.setcolor(L"fill", L"gray", 0.5, 0, 0, 0); /* Fill a circle with the current fill color defined above */ p.circle(x, y-=yoffset, r); p.fill(); /* Output text with the current fill color */ p.fit_textline(L"Circle and text filled with {gray 0.5}", x+xoffset2, y, L""); /* Alternatively, you can set the fill color in the call to * fit_textline() using the L"fillcolor" option. This case applies the * fill color just the single function call. The current fill color * won't be affected. */ p.fit_textline(L"2.", x+xoffset1, y, L"fillcolor={gray 0.5}"); /* -------------------------------------------------------------------- * Use the RGB color space * * RGB color is defined by RGB triples, i.e. three values between 0 and * 1 specifying the percentage of red, green, and blue. * (0, 0, 0) is black and (1, 1, 1) is white. The commonly used RGB * color values in the range 0...255 must be divided by 255 in order to * scale them to the range 0...1 as required by PDFlib. * -------------------------------------------------------------------- */ /* Use setcolor() to set the fill color to a grass-green * represented by (0.1, 0.95, 0.3, 0) which defines 10% red, 95% green, * 30% blue. Since RGB colors are defined by only three values, the last * function parameter must be set to 0. */ p.setcolor(L"fill", L"rgb", 0.1, 0.95, 0.3, 0); /* Draw a circle with the current fill color defined above */ p.circle(x, y-=yoffset, r); p.fill(); /* Output a text line with the RGB fill color defined above */ p.fit_textline(L"Circle and text filled with {rgb 0.1 0.95 0.3}", x+xoffset2, y, L""); /* Alternatively, you can set the fill color in the call to * fit_textline() using the L"fillcolor" option. This case applies the * fill color just the single function call. The current fill color * won't be affected. */ p.fit_textline(L"3.", x+xoffset1, y, L"fillcolor={rgb 0.1 0.95 0.3}"); /* -------------------------------------------------------------------- * Use the CMYK color space * * CMYK color is defined by four CMYK values between 0 = no color and * 1 = full color representing cyan, magenta, yellow, and black values; * (0, 0, 0, 0) is white and (0, 0, 0, 1) is black. * -------------------------------------------------------------------- */ /* Use setcolor() to set the current fill color to a pale * orange, represented by (0.1, 0.7, 0.7, 0.1) which defines 10% Cyan, * 70% Magenta, 70% Yellow, and 10% Black. */ p.setcolor(L"fill", L"cmyk", 0.1, 0.7, 0.7, 0.1); /* Fill a circle with the current fill color defined above */ p.circle(x, y-=yoffset, r); p.fill(); /* Output a text line with the CMYK fill color defined above */ p.fit_textline(L"Circle and text filled with {cmyk 0.1 0.7 0.7 0.1}", x+xoffset2, y, L""); /* Alternatively, you can set the fill color in the call to * fit_textline() using the L"fillcolor" option. This case applies the * fill color just the single function call. The current fill color * won't be affected. */ p.fit_textline(L"4.", x+xoffset1, y, L"fillcolor={cmyk 0.1 0.7 0.7 0.1}"); /* -------------------------------------------------------------------- * Use a Lab color * * Device-independent color in the CIE L*a*b* color space is specified * by a luminance value in the range 0-100 and two color values in the * range -127 to 128. The first value contains the green-red axis, * while the second value contains the blue-yellow axis. * -------------------------------------------------------------------- */ /* Set the current fill color to a loud blue, represented by * (100, -127, -127, 0). Since Lab colors are defined by only three * values, the last function parameter must be set to 0. */ p.setcolor(L"fill", L"lab", 100, -127, -127, 0); /* Fill a circle with the fill color defined above */ p.circle(x, y-=yoffset, r); p.fill(); /* Output a text line with the Lab fill color defined above */ p.fit_textline(L"Circle and text filled with {lab 100 -127 -127}", x+xoffset2, y, L""); /* Alternatively, you can set the fill color in the call to * fit_textline() using the L"fillcolor" option. This case applies the * fill color just the single function call. The current fill color * won't be affected. */ p.fit_textline(L"5.", x+xoffset1, y, L"fillcolor={lab 100 -127 -127}"); /* --------------------------------------------------------------- * Use an ICC based color * * ICC-based colors are specified with the help of an ICC profile. * --------------------------------------------------------------- */ /* Load the sRGB profile. sRGB is guaranteed to be always available */ icchandle = p.load_iccprofile(L"sRGB", L"usage=iccbased"); /* Set the sRGB profile. (Accordingly, you can use * L"setcolor:iccprofilergb" or L"setcolor:iccprofilegray" with an * appropriate profile) */ p.set_value(L"setcolor:iccprofilergb", icchandle); /* Use setcolor() with the L"iccbasedrgb" color space to set the current * fill and stroke color to a grass-green, represented * by the RGB color values (0.1 0.95 0.3 0) which define 10% Red, * 95% Green, and 30% Blue. Since iccbasedrgb colors are defined by only * three values, the last function parameter must be set to 0. */ p.setcolor(L"fill", L"iccbasedrgb", 0.1, 0.95, 0.3, 0); /* Fill a circle with the ICC based RGB fill color defined above */ p.circle(x, y-=yoffset, r); p.fill(); /* Output a text line with the ICC based RGB fill color defined above */ p.fit_textline( L"Circle and text filled with {iccbasedrgb 0.1 0.95 0.3}", x+xoffset2, y, L""); /* Alternatively, you can set the fill color in the call to * fit_textline() using the L"fillcolor" option. This case applies the * fill color just the single function call. The current fill color * won't be affected. */ p.fit_textline(L"6.", x+xoffset1, y, L"fillcolor={iccbasedrgb 0.1 0.95 0.3}"); /* -------------------------------------------------------------------- * Use a spot color * * Spot color (separation color space) is a predefined or arbitrarily * named custom color with an alternate representation in one of the * other color spaces above; this is generally used for preparing * documents which are intended to be printed on an offset printing * machine with one or more custom colors. The tint value (percentage) * ranges from 0 = no color to 1 = maximum intensity of the spot color. * -------------------------------------------------------------------- */ /* Define the spot color L"PANTONE 281 U" from the builtin color * library PANTONE */ spot = p.makespotcolor(L"PANTONE 281 U"); /* Set the spot color L"PANTONE 281 U" with a tint value of 1 (=100%) * and output some text. Since spot colors are defined by only two * values, the last two function parameters must be set to 0. */ p.setcolor(L"fill", L"spot", spot, 1.0, 0, 0); /* Fill a circle with the ICC based RGB fill color defined above */ p.circle(x, y-=yoffset, r); p.fill(); p.fit_textline( L"Circle and text filled with {spotname {PANTONE 281 U} 1}", x+xoffset2, y, L""); /* Alternatively, you can set the fill color in the call to * fit_textline() using the L"fillcolor" option. This case applies the * fill color just the single function call. The current fill color * won't be affected. */ p.fit_textline(L"7.", x+xoffset1, y, L"fillcolor={spotname {PANTONE 281 U} 1}"); /* or */ wostringstream buf; buf.str(L""); buf << L"fillcolor={spot " << spot << L" 1}"; p.fit_textline(L"7.", x+xoffset1, y, buf.str()); /* ---------------------------------------------------------- * For using the Pattern color space, see the Cookbook topics * graphics/fill_pattern and images/background_pattern. * ---------------------------------------------------------- */ /* --------------------------------------------------------- * For using the Shading color space, see the Cookbook topic * color/color_gradient. * --------------------------------------------------------- */ p.end_page_ext(L""); p.end_document(L""); } catch (PDFlib::Exception &ex) { wcerr << L"PDFlib exception occurred:" << endl << L"[" << ex.get_errnum() << L"] " << ex.get_apiname() << L": " << ex.get_errmsg() << endl; return 2; } return 0; }
int main(void) { try { /* This is where the data files are. Adjust as necessary. */ const wstring searchpath = L"../data"; PDFlib p; const wstring pdfinput = L"TET-datasheet.pdf"; const wstring docoptlist = L"requiredmode=minimum"; int count, pcosmode; int i, doc; wstring objtype; // This means we must check return values of load_font() etc. p.set_parameter(L"errorpolicy", L"return"); p.set_parameter(L"SearchPath", searchpath); /* We do not create any output document, so no call to * begin_document() is required. */ /* Open the input document */ if ((doc = p.open_pdi_document(pdfinput, docoptlist)) == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } /* --------- general information (always available) */ pcosmode = static_cast<int>(p.pcos_get_number(doc, L"pcosmode")); wcout << L" File name: " << p.pcos_get_string(doc,L"filename") << endl; wcout << L" PDF version: " << p.pcos_get_string(doc, L"pdfversionstring") << endl; wcout << L" Encryption: " << p.pcos_get_string(doc, L"encrypt/description") << endl; wcout << L" Master pw: " << ((p.pcos_get_number(doc, L"encrypt/master") != 0) ? L"yes":L"no") << endl; wcout << L" User pw: " << ((p.pcos_get_number(doc, L"encrypt/user") != 0) ? L"yes" : L"no") << endl; wcout << L"Text copying: " << ((p.pcos_get_number(doc, L"encrypt/nocopy") != 0) ? L"no":L"yes") << endl; wcout << L" Linearized: " << ((p.pcos_get_number(doc, L"linearized") != 0) ? L"yes" : L"no") << endl; if (pcosmode == 0) { wcout << L"Minimum mode: no more information available" << endl; return 0; } wcout << endl; /* --------- more details (requires at least user password) */ wcout << L"PDF/X status: " << p.pcos_get_string(doc, L"pdfx") << endl; wcout << L"PDF/A status: " << p.pcos_get_string(doc, L"pdfa") << endl; bool xfa_present = p.pcos_get_string(doc, L"type:/Root/AcroForm/XFA") != L"null"; wcout << L" XFA data: " << (xfa_present ? L"yes" : L"no") << endl; wcout << L" Tagged PDF: " << ((p.pcos_get_number(doc, L"tagged") != 0) ? L"yes" : L"no") << endl; wcout << L"No. of pages: " << static_cast<int>(p.pcos_get_number(doc, L"length:pages")) << endl; wcout << L" Page 1 size: width=" << fixed << setprecision(3) << p.pcos_get_number(doc, L"pages[0]/width") << L", height=" << p.pcos_get_number(doc, L"pages[0]/height") << endl; /* reset formatting to default */ wcout << resetiosflags(ios::floatfield) << setprecision(6); count = static_cast<int>(p.pcos_get_number(doc, L"length:fonts")); wcout << L"No. of fonts: " << count << endl; for (i = 0; i < count; i++) { wostringstream fontstr; fontstr.str(L""); fontstr << L"fonts[" << i << L"]"; const wstring& font = fontstr.str(); if (p.pcos_get_number(doc, font + L"/embedded") != 0) wcout << L"embedded "; else wcout << L"unembedded "; wcout << p.pcos_get_string(doc, font + L"/type") << L" font "; wcout << p.pcos_get_string(doc, font + L"/name") << endl; } wcout << endl; const bool plainmetadata = p.pcos_get_number(doc, L"encrypt/plainmetadata") != 0; if (pcosmode == 1 && !plainmetadata && p.pcos_get_number(doc, L"encrypt/nocopy") != 0) { wcout << L"Restricted mode: no more information available" << endl; return 0; } /* ----- document info keys and XMP metadata (requires master pw) */ count = (int) p.pcos_get_number(doc, L"length:/Info"); for (i=0; i < count; i++) { wostringstream infostr; wstring key; infostr.str(L""); infostr << L"/Info[" << i << L"]"; const wstring& info = infostr.str(); objtype = p.pcos_get_string(doc, L"type:" + info); key = p.pcos_get_string(doc, info + L".key"); wcout.width(12); wcout << key << L": "; /* Info entries can be stored as string or name objects */ if (objtype == L"name" || objtype == L"string") { wcout << L"'" + p.pcos_get_string(doc, info) << L"'" << endl; } else { wcout << L"(" + objtype << L" object)" << endl; } } wcout << endl << L"XMP metadata: "; objtype = p.pcos_get_string(doc, L"type:/Root/Metadata"); if (objtype == L"stream") { const unsigned char *contents; int len; contents = p.pcos_get_stream(doc, &len, L"", L"/Root/Metadata"); wcout << len << L" bytes "; } else { wcout << L"not present"; } wcout << endl; p.close_pdi_document(doc); } catch (PDFlib::Exception &ex) { wcerr << L"PDFlib exception occurred: " << endl << L"[" << ex.get_errnum() << L"] " << ex.get_apiname() << L": " << ex.get_errmsg() << endl; return 2; } return 0; }
void CCopyProperties::OnBnClickedBtnSaveasPdf() { CString strTitle = m_RichEdit.GetText(); int nLength = strTitle.GetLength(); OPENFILENAME ofn; TCHAR szFile[400]; memset(&szFile, 0, sizeof(szFile)); memset(&ofn, 0, sizeof(ofn)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = m_hWnd; ofn.lpstrFile = szFile; ofn.nMaxFile = sizeof(szFile); ofn.lpstrFilter=_T("PDF File (.pdf)\0*.pdf\0\0"); ofn.nFilterIndex = 1; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; ofn.lpstrDefExt = _T("pdf"); ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_OVERWRITEPROMPT; if(GetSaveFileName(&ofn)) { PDFlib pdf; pdf.set_parameter("compatibility", "1.4"); //Compatible for Acrobat 5 CString strFileName(ofn.lpstrFile); pdf.open(ofn.lpstrFile); float width = 595.0; float height = 842.0; pdf.begin_page(width, height); float PageHeight=0.0, PageWidth=0.0; //Font will be embedded in PDF int font=pdf.findfont("Arial", "winansi", 1); int fontSize = 10; pdf.setfont(font, fontSize); pdf.set_text_pos(20, 822); CString Line, Text; Text=strTitle; Text.Replace("\r\n","\r"); float descender=pdf.get_value("descender", font); float LineHeight=(1-descender)*fontSize; int iWordIndex=0; int iProgress=0; while (!Text.IsEmpty()) { while (PageWidth <= width) { iWordIndex=Text.Find(' ', iWordIndex); if (iWordIndex!=-1) Line=Text.Left(iWordIndex++); else { Line=Text; break; } PageWidth=pdf.stringwidth(Line.GetBuffer(0), font, fontSize); } iWordIndex=Line.Find('\r'); if (iWordIndex!=-1) //enter found (carriage return) { Line=Line.Left(iWordIndex); Text=Text.Right(Text.GetLength() - Line.GetLength() - 1); } else { iWordIndex=Line.ReverseFind(' '); if (iWordIndex!=-1) //space found { if (pdf.stringwidth(Line.GetBuffer(0), font, fontSize)>width) { Line=Line.Left(iWordIndex); //with space character Text=Text.Right(Text.GetLength() - iWordIndex); } else { Line=Text; Text=""; } } else { Text=Text.Right(Text.GetLength() - Line.GetLength()); } } iWordIndex=0; iProgress+=Line.GetLength(); pdf.continue_text(Line.GetBuffer(0)); PageWidth=0; PageHeight=pdf.get_value("texty",0.0); if (PageHeight < 10.0 ) { pdf.end_page(); pdf.begin_page(width, height); pdf.setfont(font, fontSize); pdf.set_text_pos(20, 822); } Line=""; } pdf.end_page(); // USES_CONVERSION; // LPCSTR sstr= W2CA((LPCWSTR)strTitle); // LPCSTR sstr = (LPCSTR)strTitle; // pdf.continue_text(sstr); // pdf.end_page(); pdf.close();/**/ } }
int main(void) { try { int font; PDFlib p; // This means we must check return values of load_font() etc. p.set_parameter("errorpolicy", "return"); // This line is required to avoid problems on Japanese systems p.set_parameter("hypertextencoding", "host"); if (p.begin_document("hello.pdf", "") == -1) { cerr << "Error: " << p.get_errmsg() << endl; return 2; } p.set_info("Creator", "hello.cpp"); p.set_info("Author", "Thomas Merz"); p.set_info("Title", "Hello, world (C++)!"); p.begin_page_ext(a4_width, a4_height, ""); // Change "host" encoding to "winansi" or whatever you need! font = p.load_font("Helvetica-Bold", "host", ""); if (font == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } p.setfont(font, 24); p.set_text_pos(50, 700); p.show("Hello, world!"); p.continue_text("(says C++)"); 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; }
int main(void) { try { /* This is where the data files are. Adjust as necessary. */ string searchpath = "../data"; string outfile = "starter_layer.pdf"; PDFlib p; string rgb = "nesrin.jpg"; string gray = "nesrin_gray.jpg"; #define BUFLEN 1024 char buf[BUFLEN]; int font, imageRGB, imageGray, layerRGB, layerGray, layerEN, layerDE; /* This means we must check return values of load_font() etc. */ p.set_parameter("errorpolicy", "return"); p.set_parameter("SearchPath", searchpath); /* Open the document with the "Layers" navigation tab visible */ if (p.begin_document(outfile, "openmode=layers") == -1) { cerr << "Error: " << p.get_errmsg() << endl; return 2; } p.set_info("Creator", "PDFlib starter sample"); p.set_info("Title", "starter_layer"); /* Load the font */ font = p.load_font("Helvetica", "winansi", ""); if (font == -1) { cerr << "Error: " << p.get_errmsg() << endl; return 2; } /* Load the Grayscale image */ imageGray = p.load_image("auto", gray, ""); if (imageGray == -1) { cerr << "Error: " << p.get_errmsg() << endl; return 2; } /* Load the RGB image */ imageRGB = p.load_image("auto", rgb, ""); if (imageRGB == -1) { cerr << "Error: " << p.get_errmsg() << endl; return 2; } /* * Define all layers which will be used, and their relationships. * This should be done before the first page if the layers are * used on more than one page. */ /* Define the layer "RGB" */ layerRGB = p.define_layer("RGB", ""); /* Define the layer "Grayscale" which is hidden when opening the * document or printing it. */ layerGray = p.define_layer("Grayscale", "initialviewstate=false initialprintstate=false"); /* At most one of the "Grayscale" and "RGB" layers should be visible */ sprintf(buf, "group={%d %d}", layerGray, layerRGB); p.set_layer_dependency("Radiobtn", buf); /* Define the layer "English" */ layerEN = p.define_layer("English", ""); /* Define the layer "German" which is hidden when opening the document * or printing it. */ layerDE = p.define_layer("German", "initialviewstate=false initialprintstate=false"); /* At most one of the "English" and "German" layers should be visible */ sprintf(buf, "group={%d %d}", layerEN, layerDE); p.set_layer_dependency("Radiobtn", buf); /* Start page */ p.begin_page_ext(0, 0, "width=a4.width height=a4.height"); /* Place the RGB image on the layer "RGB" */ p.begin_layer(layerRGB); p.fit_image(imageRGB, 100, 400, "boxsize={400 300} fitmethod=meet"); /* Place the Grayscale image on the layer "Grayscale" */ p.begin_layer(layerGray); p.fit_image(imageGray, 100, 400, "boxsize={400 300} fitmethod=meet"); /* Place an English image caption on the layer "English" */ p.begin_layer(layerEN); sprintf(buf, "font=%d fontsize=20", font); p.fit_textline("This is the Nesrin image.", 100, 370, buf); /* Place a German image caption on the layer "German". */ p.begin_layer(layerDE); sprintf(buf, "font=%d fontsize=20", font); p.fit_textline("Das ist das Nesrin-Bild.", 100, 370, buf); p.end_layer(); p.end_page_ext(""); p.end_document(""); } catch (PDFlib::Exception &ex) { cerr << "PDFlib exception occurred:" << endl; cerr << "[" << ex.get_errnum() << "] " << ex.get_apiname() << ": " << ex.get_errmsg() << endl; return 2; } return 0; }
int main(void) { /* This is where the data files are. Adjust as necessary. */ const wstring searchpath = L"../data"; const wstring outfile = L"starter_opentype.pdf"; wostringstream optlist; PDFlib p; int row, col, table, test, font; const double llx=50, lly=50, urx=800, ury=550; wstring result; /* This font will be used unless another one is specified in the table */ const wstring defaulttestfont = L"DejaVuSerif"; const wstring header[] = { L"OpenType feature", L"Option list", L"Font name", L"Raw input (feature disabled)", L"Feature enabled" }; const int MAXCOL = sizeof(header) / sizeof(header[0]); typedef struct { const wstring description; /* the default test font above will be used if this string is empty */ const wstring fontname; const wstring feature; const wstring text; } testcase; static const testcase testcases[] = { { L"ligatures", L"", L"liga", L"ff fi fl ffi ffl" }, { L"discretionary ligatures", L"", L"dlig", L"st c/o" }, { L"historical ligatures", L"", L"hlig", L"&.longs;b &.longs;t" }, { L"small capitals", L"", L"smcp", L"PostScript" }, { L"ordinals", L"", L"ordn", L"1o 2a 3o" }, { L"fractions", L"", L"frac", L"1/2 1/4 3/4" }, { L"alternate fractions", L"", L"afrc", L"1/2 1/4 3/4" }, { L"slashed zero", L"", L"zero", L"0" }, { L"historical forms", L"", L"hist", L"s" }, { L"proportional figures", L"", L"pnum", L"0123456789" }, { L"old-style figures", L"", L"onum", L"0123456789" }, { L"lining figures", L"", L"lnum", L"0123456789" }, { L"superscript", L"", L"sups", L"0123456789" }, }; const int n_testcases = sizeof(testcases) / sizeof(testcases[0]); try { p.set_parameter(L"SearchPath", searchpath); p.set_parameter(L"charref", L"true"); /* This means that formatting and other errors will raise an * exception. This simplifies our sample code, but is not * recommended for production code. */ p.set_parameter(L"errorpolicy", L"exception"); /* Set an output path according to the name of the topic */ if (p.begin_document(outfile, L"") == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } p.set_info(L"Creator", L"PDFlib starter sample"); p.set_info(L"Title", L"starter_opentype"); /* Start Page */ p.begin_page_ext(0, 0, L"width=a4.height height=a4.width"); table = -1; /* Table header */ for (row=1, col=1; col <= MAXCOL; col++) { optlist.str(L""); optlist << L"fittextline={fontname=Helvetica-Bold encoding=unicode " L"fontsize=12} margin=4"; table = p.add_table_cell(table, col, row, header[col-1], optlist.str()); } /* Create a table with feature samples, one feature per table row */ for (row=2, test=0; test < n_testcases; row++, test++) { wstring testfont; wostringstream buf; /* Use the entry in the test table if available, and the * default test font otherwise. This way we can easily check * a font for all features, as well as insert suitable fonts * for individual features. */ if (testcases[test].fontname.length() > 0) testfont = testcases[test].fontname; else testfont = defaulttestfont; col = 1; /* Common option list for columns 1-3 */ optlist.str(L""); optlist << L"fittextline={fontname=Helvetica encoding=unicode " L"fontsize=12} margin=4"; /* Column 1: feature description */ table = p.add_table_cell(table, col++, row, testcases[test].description,optlist.str()); /* Column 2: option list */ buf << L"features={" << testcases[test].feature << L"}"; table = p.add_table_cell(table, col++, row, buf.str(), optlist.str()); /* Column 3: font name */ table = p.add_table_cell(table, col++, row, testfont, optlist.str()); /* Column 4: raw input text with feature disabled */ optlist.str(L""); optlist << L"fittextline={fontname={" << testfont << L"} " L"encoding=unicode fontsize=12 embedding} margin=4"; table = p.add_table_cell(table, col++, row, testcases[test].text, optlist.str()); /* Column 5: text with enabled feature, or warning if the * feature is not available in the font */ font = p.load_font(testfont, L"unicode", L"embedding"); /* Check whether font contains the required feature table */ optlist.str(L""); optlist << L"name=" << testcases[test].feature; if (p.info_font(font, L"feature", optlist.str()) == 1) { /* feature is available: apply it to the text */ optlist.clear(); optlist.str(L""); optlist << L"fittextline={fontname={" << testfont << L"} " << L"encoding=unicode fontsize=12 embedding features={" << testcases[test].feature << L"}} margin=4"; table = p.add_table_cell(table, col++, row, testcases[test].text, optlist.str()); } else { /* feature is not available: emit a warning */ optlist.str(L""); optlist << L"fittextline={fontname=Helvetica encoding=unicode " L"fontsize=12 fillcolor=red} margin=4"; table = p.add_table_cell(table, col++, row, L"(feature not available in this font)", optlist.str()); } } /* Place the table */ optlist.str(L""); optlist << L"header=1 fill={{area=rowodd fillcolor={gray 0.9}}} " L"stroke={{line=other}}"; result = p.fit_table(table, llx, lly, urx, ury, optlist.str()); if (result == L"_error") { wcerr << L"Couldn't place table: " << p.get_errmsg() << endl; return 2; } p.end_page_ext(L""); p.end_document(L""); } catch (PDFlib::Exception &ex) { wcerr << L"PDFlib exception occurred:" << endl << L"[" << ex.get_errnum() << L"] " << ex.get_apiname() << L": " << ex.get_errmsg() << endl; return 2; } return 0; }
int main(void) { try { /* This is where the data files are. Adjust as necessary. */ const wstring searchpath = L"../data"; PDFlib p; const wstring pdffiles[] = { L"PDFlib-real-world.pdf", L"PDFlib-datasheet.pdf", L"TET-datasheet.pdf", L"PLOP-datasheet.pdf", L"pCOS-datasheet.pdf" }; const int filecount = sizeof(pdffiles) / sizeof(pdffiles[0]); int i; // This means we must check return values of load_font() etc. p.set_parameter(L"errorpolicy", L"return"); p.set_parameter(L"SearchPath", searchpath); if (p.begin_document(L"starter_pdfmerge.pdf", L"") == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } p.set_info(L"Creator", L"PDFlib starter sample"); p.set_info(L"Title", L"starter_pdfmerge"); for (i = 0; i < filecount; i++) { int indoc, endpage, pageno, page; /* Open the input PDF */ indoc = p.open_pdi_document(pdffiles[i], L""); if (indoc == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; return 2; } endpage = static_cast<int>(p.pcos_get_number(indoc, L"length:pages")); /* Loop over all pages of the input document */ for (pageno = 1; pageno <= endpage; pageno++) { page = p.open_pdi_page(indoc, pageno, L""); if (page == -1) { wcerr << L"Error: " << p.get_errmsg() << endl; continue; } /* Dummy page size; will be adjusted later */ p.begin_page_ext(10, 10, L""); /* Create a bookmark with the file name */ if (pageno == 1) p.create_bookmark(pdffiles[i], L""); /* Place the imported page on the output page, and * adjust the page size */ p.fit_pdi_page(page, 0, 0, L"adjustpage"); p.close_pdi_page(page); p.end_page_ext(L""); } p.close_pdi_document(indoc); } p.end_document(L""); } catch (PDFlib::Exception &ex) { wcerr << L"PDFlib exception occurred:" << endl << L"[" << ex.get_errnum() << L"] " << ex.get_apiname() << L": " << ex.get_errmsg() << endl; return 2; } return 0; }
int main(void) { try { /* This is where the data files are. Adjust as necessary. */ string searchpath = "../data"; string imagefile = "nesrin.jpg"; int row, col, font, image, tf=-1, tbl=-1; int rowmax=50, colmax=5; PDFlib p; double llx= 50, lly=50, urx=550, ury=800; string headertext = "Table header (centered across all columns)"; string result; char optlist[256]; /* Dummy text for filling a cell with multi-line Textflow */ string tf_text = "Lorem ipsum dolor sit amet, consectetur adi­pi­sicing elit, \ sed do eius­mod tempor incidi­dunt ut labore et dolore magna \ ali­qua. Ut enim ad minim ve­niam, quis nostrud exer­citation \ ull­amco la­bo­ris nisi ut ali­quip ex ea commodo \ con­sequat. Duis aute irure dolor in repre­henderit in voluptate \ velit esse cillum dolore eu fugiat nulla pari­atur. Excep­teur \ sint occae­cat cupi­datat non proident, sunt in culpa qui officia \ dese­runt mollit anim id est laborum. "; // This means we must check return values of load_font() etc. p.set_parameter("errorpolicy", "return"); p.set_parameter("SearchPath", searchpath); if (p.begin_document("starter_table.pdf", "") == -1) { cerr << "Error: " << p.get_errmsg() << endl; return 2; } p.set_info("Creator", "PDFlib starter sample"); p.set_info("Title", "starter_table"); /* -------------------- Add table cells -------------------- */ /* ---------- Row 1: table header (spans all columns) */ row = 1; col = 1; font = p.load_font("Times-Bold", "winansi", ""); if (font == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } sprintf(optlist,"fittextline={position=center font=%d fontsize=14} " "colspan=%d", font, colmax); tbl = p.add_table_cell(tbl, col, row, headertext, optlist); /* ---------- Row 2: various kinds of content */ /* ----- Simple text cell */ row++; col=1; sprintf(optlist, "fittextline={font=%d fontsize=10 orientate=west}", font); tbl = p.add_table_cell(tbl, col, row, "vertical line", optlist); if (tbl == -1) { cerr << "Error: " << p.get_errmsg() << endl; return 2; } /* ----- Colorized background */ col++; sprintf(optlist, "fittextline={font=%d fontsize=10} " "matchbox={fillcolor={rgb 0.9 0.5 0}}", font); tbl = p.add_table_cell(tbl, col, row, "some color", optlist); /* ----- Multi-line text with Textflow */ col++; font = p.load_font("Times-Roman", "winansi", ""); if (font == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } sprintf(optlist, "charref fontname=Times-Roman encoding=winansi fontsize=8 "); tf = p.add_textflow(tf, tf_text, optlist); if (tf == -1) { cerr << "Error: " << p.get_errmsg() << endl; return(2); } sprintf(optlist, "marginleft=2 marginright=2 margintop=2 marginbottom=2 " "textflow=%d", tf); tbl = p.add_table_cell(tbl, col, row, "", optlist); if (tbl == -1) { cerr << "Error: " << p.get_errmsg() << endl; return 2; } /* ----- Rotated image */ col++; image = p.load_image("auto", imagefile, ""); if (image == -1) { cerr << "Couldn't load image: " << p.get_errmsg() << endl; return 2; } sprintf(optlist, "image=%d fitimage={orientate=west}", image); tbl = p.add_table_cell(tbl, col, row, "", optlist); if (tbl == -1) { cerr << "Error: " << p.get_errmsg() << endl; return 2; } /* ----- Diagonal stamp */ col++; sprintf(optlist, "fittextline={font=%d fontsize=10 stamp=ll2ur}", font); tbl = p.add_table_cell(tbl, col, row, "entry void", optlist); if (tbl == -1) { cerr << "Error: " << p.get_errmsg() << endl; return 2; } /* ---------- Fill row 3 and above with their numbers */ for (row++; row <= rowmax; row++) { for (col = 1; col <= colmax; col++) { char num[80]; sprintf(num, "Col %d/Row %d", col, row); sprintf(optlist, "colwidth=20%% fittextline={font=%d fontsize=10}", font); tbl = p.add_table_cell(tbl, col, row, num, optlist); } } /* ---------- Place the table on one or more pages ---------- */ /* * Loop until all of the table is placed; create new pages * as long as more table instances need to be placed. */ do { p.begin_page_ext(0, 0, "width=a4.width height=a4.height"); /* Shade every other row; draw lines for all table cells. * Add "showcells showborder" to visualize cell borders */ sprintf(optlist, "header=1 fill={{area=rowodd fillcolor={gray 0.9}}} " "stroke={{line=other}} "); /* Place the table instance */ result = p.fit_table(tbl, llx, lly, urx, ury, optlist); if (result == "_error") { cerr << "Couldn't place table: " << p.get_errmsg() << endl; return 2; } p.end_page_ext(""); } while (result == "_boxfull"); /* Check the result; "_stop" means all is ok. */ if (result != "_stop") { if (result == "_error") { cerr << "Error when placing table: " << p.get_errmsg() << endl; return 2; } else { /* Any other return value is a user exit caused by * the "return" option; this requires dedicated code to * deal with. */ cerr << "User return found in Textflow" << endl; return 2; } } /* This will also delete Textflow handles used in the table */ p.delete_table(tbl, ""); p.end_document(""); } catch (PDFlib::Exception &ex) { cerr << "PDFlib exception occurred:" << endl; cerr << "[" << ex.get_errnum() << "] " << ex.get_apiname() << ": " << ex.get_errmsg() << endl; return 2; } return 0; }