?? firstpdf.cpp
字號:
// FirstPDF.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
/*
在新的C++標(biāo)準(zhǔn)中,生成新頭文件的方法僅僅是將現(xiàn)有C++頭文件名中的 .h 去掉。例如,<iostream.h>變成了<iostream>,<complex.h>變成了<complex>,等等。對于C頭文件,采用同樣的方法,但在每個(gè)名字前還要添加一個(gè)c。所以C的<string.h>變成了<cstring>,<stdio.h>變成了<cstdio>,等等。
舊的C++頭文件是官方所反對使用的(即,明確列出不再支持),但舊的C頭文件則沒有(以保持對C的兼容性)。
下面是C++頭文件的現(xiàn)狀:
· 舊的C++頭文件名如<iostream.h>將會繼續(xù)被支持,盡管它們不在官方標(biāo)準(zhǔn)中。這些頭文件的內(nèi)容不在名字空間std中。
· 新的C++頭文件如<iostream>包含的基本功能和對應(yīng)的舊頭文件相同,但頭文件的內(nèi)容在名字空間std中。(在標(biāo)準(zhǔn)化的過程中,庫中有些部分的細(xì)節(jié)被修改了,所以舊頭文件和新頭文件中的實(shí)體不一定完全對應(yīng)。)
· 標(biāo)準(zhǔn)C頭文件如<stdio.h>繼續(xù)被支持。頭文件的內(nèi)容不在std中。
· 具有C庫功能的新C++頭文件具有如<cstdio>這樣的名字。它們提供的內(nèi)容和相應(yīng)的舊C頭文件相同,只是內(nèi)容在std中。
*/
#include "..\\PDFLib\\PDFLib.hpp"
//我們經(jīng)常用到的是#pragma comment(lib,"*.lib")這類的。
//#pragma comment(lib,"Ws2_32.lib")表示鏈接Ws2_32.lib這個(gè)
//庫。 和在工程設(shè)置里寫上鏈入Ws2_32.lib的效果一樣,不過
//這種方法寫的 程序別人在使用你的代碼的時(shí)候就不用再設(shè)置
//工程settings了
#pragma comment(lib,"..\\PDFLib\\PDFLib.lib")
int main()
{
try
{
PDFlib pdf;
pdf.set_parameter("compatibility","1.4");//兼容Acrobat 5
if(pdf.open("MyFirstPDF.pdf") == -1)
throw("Opening the file is wrong!");
pdf.set_info("Creator", "PDF Creator");
pdf.set_info("Author", "wangjt");
pdf.set_info("Title", "用VC++實(shí)現(xiàn)pDF的創(chuàng)建");
pdf.set_info("Subject", "PDF Creator");
pdf.set_info("Keywords", "pdf.lib pdf.dll");
pdf.begin_page(a4_width,a4_height);
int font_song = pdf.findfont("STSong-Light", "GB-EUC-H", 0);
pdf.setfont(font_song, 12);
pdf.set_text_pos(50, a4_height - 50);
// 設(shè)置顏色為藍(lán)色
pdf.setcolor("fill", "rgb", 0, 0, 1, 0);
// 輸出文字
pdf.show("歡迎您到來!");
pdf.setcolor("fill", "rgb", 0, 0, 0, 0);
pdf.setfont(font_song, 24);
pdf.continue_text("在線雜志");
// 畫兩根綠線
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();
// 填充一個(gè)藍(lán)色方框
pdf.setcolor("fill", "rgb", 0.04f, 0.24f, 0.62f, 0);
pdf.rect(50, 50, a4_width - 100, 70);
pdf.fill();
// 在指定位置輸出文字
pdf.setcolor("fill", "rgb", 0, 1, 1, 0);
pdf.setfont(font_song, 16);
pdf.show_xy("版權(quán)所有 西北師范大學(xué)", a4_width - 280, 60);
// 打開并顯示一個(gè)圖像
int img = pdf.open_image_file("jpeg", "vckbase.jpg", "", 0);
pdf.place_image(img, 200, 400, 1);
pdf.close_image(img);
// 添加附件
pdf.attach_file(a4_width - 50, 0, 0, a4_height - 150, "explanation.txt", "VCKBASE", "wj", "zip", "paperclip");
// 結(jié)束本頁
pdf.end_page();
// 關(guān)閉PDF文件
pdf.close();
cout << "MyFirstPDF.pdf成功生成!\r\n";
}
catch(PDFlib::Exception &ex)
{
cerr << "錯(cuò)誤信息:" << ex.get_message() << endl;
return -1;
}
catch(char *pStrErr)
{
cerr << pStrErr << endl;
return -1;
}
catch(...)
{
cerr << "發(fā)生未知異常!" << endl;
return -1;
}
return 0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -