Use pdflib to generate PDF document tutorial

Source: Internet
Author: User
Tags pdflib adobe acrobat reader

I. pdf Introduction
PDF is the abbreviation of portable document format. pdf file format is an international standard for the exchange of electronic documents. It is adopted by many countries as an electronic document exchange standard. PDF files can be read, edited, and published on various platforms. The file format supports embedding fonts, images, and even any attachments. You can use Adobe Acrobat Reader for free to read and edit PDF documents.

II. Introduction to pdflib
Pdflib is a development library used to create PDF documents. It provides easy-to-use APIs, hiding the complex details of creating PDF without the support of 3rd-party software. The pdflib library is free for individuals. For commercial products that require a license, you can download it from the tools and resources section of the VC Knowledge Base: http://www.kindeditor.com/pdt/4691.

3. Use pdflib in VC ++
In this example, pdflib is 4.0.2, which is similar to version 5.0. In the free version 5.0, there is a watermark www. pdflib. com, which is not found in 4.0.

3.1 preparations
After the project is created, copy T. cpp, except. H, pdflib. cpp, pdflib. H, pdflib. dll, and pdflib. lib to the project directory.

3.2 Encoding
3.2.1 Add a reference to a file or library

# Include "pdflib. HPP"

# Pragma comment (Lib, "pdflib. lib ")
3.2.2 PDF document Generation Process
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 the document
If (pdf. Open ("vckbase.pdf") =-1)
Throw ("An error occurred while opening the 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 the A4 page
Pdf. begin_page (a4_width, a4_height );

// Set the font to on the 12th.
Int font_song = pdf. findfont ("stsong-light", "GB-EUC-H", 0 );
Pdf. setfont (font_song, 12 );

// Set the start point
Pdf. set_text_pos (50, a4_height-50 );

// Set the color to blue
Pdf. setcolor ("fill", "RGB", 0, 0, 1, 0 );

// Output text
Pdf. Show ("vckbase. COM Welcome! ");

Pdf. setcolor ("fill", "RGB", 0, 0, 0, 0 );
Pdf. setfont (font_song, 24 );
Pdf. continue_text ("online magazine ");

// Draw two green lines
Pdf. setcolor ("stroke", "RGB", 0.24f, 0.51f, 0.047f, 0 );
Pdf. moveTo (50, a4_height-80 );
Pdf. lineto (a4_width-50, a4_height-80 );
Pdf. moveTo (50, a4_height-78 );
Pdf. lineto (a4_width-50, a4_height-78 );
Pdf. Stroke ();

// Fill in a blue box
Pdf. setcolor ("fill", "RGB", 0.04f, 0.24f, 0.62f, 0 );
Pdf. rect (50, 50, a4_width-100, 70 );
Pdf. Fill ();

// Output text at the specified position
Pdf. setcolor ("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 an attachment
Pdf. attach_file (a4_width-50, 0, 0, a4_height-150,
"Vckbase.zip", "vckbase", "WJ", "Zip", "paperclip ");

// End this page
Pdf. end_page ();

// Close the 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 <"unknown exception! "<Endl;
Return-1;
}

Return 0;
}
Pdflib also has many functions, such as bookmarks and PDF import. For details, refer to the pdflib function manual (you can download pdflib5.0 from the VC knowledge base, which contains this Manual ).

Use pdflib to generate PDF document tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.