PDF document generated by this article code
first, the introduction of PDF
PDF is an abbreviation for Portable Document format, which is an international standard for electronic document exchange, and is used by many countries as an electronic document exchange. PDF files can be read, edited, and published on a variety of platforms. This file format supports embedding of fonts, images, and even any attachments. You can use the free Adobe Acrobat reader to read and edit PDF documents.
ii. introduction of Pdflib
Pdflib is the development library for creating PDF documents, providing an easy-to-use API that hides the complexities of creating PDFs without the need for 3rd party software support. Pdflib Library for the individual is free, for commercial products need to purchase license, you can go to the VC Knowledge Base Tools and resources column download: http://www.vckbase.com/tools/.
third, the use of Pdflib in VC + +
The pdflib used in this example is version 4.0.2, similar to the 5.0 version. There is a WWW.PDFLIB.COM watermark in the free version of 5.0, not in 4.0.
3.1 Pre-preparation
After the project is established, copy the Except.cpp,except.h,pdflib.cpp,pdflib.h,pdflib.dll,pdflib.lib to the project catalog.
3.2 Encoding
3.2.1 Adding references to the header files and libraries
#include "pdflib.hpp"
#pragma comment (lib, "PDFLib.lib")
3.2.2 The process of generating PDF documents
The process of generating PDF documents is very simple, see the following code:
int main (void) {try {pdflib PDF;
Set compatible parameters pdf.set_parameter ("Compatibility", "1.4"); Compatible with Acrobat 5
Open Document if (Pdf.open ("vckbase.pdf") = =-1) throw ("Error opening file!");
Set Document Information Pdf.set_info ("Creator", "PDF Creator"); Pdf.set_info ("Author", "Wangjun"); Pdf.set_info ("Title", "Convert to PDF"); Pdf.set_info ("Subject", "PDF Creator"); Pdf.set_info ("Keywords", "vckbase.com");
Start A4 page pdf.begin_page (a4_width, a4_height);
Set the font to 12th # arial int font_song = Pdf.findfont ("Stsong-light", "Gb-euc-h", 0); Pdf.setfont (Font_song, 12);
Set the starting point Pdf.set_text_pos (A4_HEIGHT-50);
Set the color to Blue pdf.setcolor ("Fill", "RGB", 0, 0, 1, 0);
Output text Pdf.show ("Vckbase. COM welcome you! ");
Pdf.setcolor ("Fill", "RGB", 0, 0, 0, 0); Pdf.setfont (Font_song, 24); Pdf.continue_text ("online magazine");
Draw two Green Line Pdf.setcolor ("Stroke", "RGB", 0.24f, 0.51f, 0.047f, 0); Pdf.moveto (a4_height-80); Pdf.lineto (a4_width-50, a4_height-80); Pdf.moveto (a4_height-78); Pdf.lineto (a4_width-50, a4_height-78); Pdf.stroke ();
Fill a blue Box Pdf.setcolor ("Fill", "RGB", 0.04f, 0.24f, 0.62f, 0); Pdf.rect (a4_width-100, 70); Pdf.fill ();
Output text Pdf.setcolor at the specified position ("Fill", "RGB", 0, 1, 1, 0); Pdf.setfont (Font_song, 16); Pdf.show_xy ("All rights reserved Vckbase", a4_width-280, 60);
Open and display an image int img = pdf.open_image_file ("JPEG", "vckbase.jpg", "", 0); Pdf.place_image (IMG, 200, 400, 1); Pdf.close_image (IMG);
Add Attachments pdf.attach_file (a4_width-50, 0, 0, a4_height-150, "Vckbase.zip", "Vckbase", "WJ", "Zip", "paperclip");
End this page pdf.end_page ();
Close PDF file Pdf.close ();
} catch (Pdflib::exception &ex) {cerr << "error message:" << ex.get_message () << Endl; return-1; } catch (char *pstrerr) {cerr << pstrerr << Endl; return-1; } catch (...) {Cerr << "An unknown exception occurred!" << Endl; return-1; }
return 0;}
Pdflib also has many functions, such as bookmarks, PDF import and other functions, in particular, can refer to the Pdflib function manual (can be downloaded to the VC Knowledge Base pdflib5.0, which contains the manual).
Generate PDF documents with Pdflib