|
http://bbs.pediy.com/archive/index.php?t-104633.html
¡¾ÎÄÕ±êÌâ¡¿: Îļþ¸ñʽ֮PDF
¡¾ÎÄÕÂ×÷Õß¡¿: youstar
¡¾×÷ÕßÓÊÏä¡¿: youstar@foxmail.com
¡¾¸öÈËÖ÷Ò³¡¿£ºhttp://www.youstar.org.ru
¡¾×÷ÕßÉùÃ÷¡¿: Ö»ÊÇһЩºÜdzµÄÈÏʶ£¬Ï£Íû´ó¼ÒÒ»ÆðÌÖÂÛ¡£
¡¾ÎÄÕÂÏÂÔØ¡¿£º´úÂëÓëÎÄÕ¼û¸½¼þ
²Î¿¼ÁËÍøÉϵĺܶà֪ʶ£¬×÷Ϊ×Ô¼ºÕûÀíѧϰ£¬²»×ãÖ®´¦Çë´ó¼ÒÀí½âÓëÌÖÂÛ¡£
Ŀ¼£º
1¡¢PDF¸ñʽ·ÖÎö
1.1 header
1.2 Obj
1.3 cross reference table
1.4 trailer
1.5 Îļþβ
1.6 Obj¶ÔÏó
2¡¢VCÉú³ÉPDF
2.1 Ç°ÆÚ×¼±¸
2.2 Ô´Â뼰Ч¹û
3¡¢²Î¿¼×ÊÁÏ
ÕýÎÄ£º
1¡¢PDFÎļþ·ÖÎö
PDFÎļþÖ÷Òª°üº¬ÒÔϼ¸Öֽṹ£º
1.1 header
PDFÎļþµÄµÚÒ»ÐУ¬¸ñʽÈçÏ£º
%PDF-1.1 //±íʾµ±Ç°ÎļþµÄ°æ±¾Îª1.1£¨Ä¿Ç°×î¸ß°æ±¾ÊÇ1.7£©
1.2 Obj (ÎļþÌå)
PDFÖÐÓõ½µÄ¶ÔÏ󣬰üÀ¨Îı¾\ͼÏó\ÒôÀÖ\ÊÓƵ\×ÖÌå\³¬Á¬½Ó\¼ÓÃÜÐÅÏ¢µÈ£¬¸ñʽÈçÏ£º
Àý£º
1 0 obj
//1±êʾÕâ¸öobjµÄÐòºÅ£¬±ãÓÚÔÚxrefÖвéÕÒ£¬0ÊÇÓÃÀ´±êʾ²»Í¬µÄobjÏÖÔÚ¶¼ÊÇ0£¬objÊǹؼü×Ö
<< // ´ÓÕâÀ↑ʼ¸÷ÐоÍÊÇobjµÄÊôÐÔÁË ÒÔ¡°/¹Ø¼ü×Ö Öµ¡±µÄÐÎʽÀ´³öÏÖ
/Type /Catalog //objµÄÀàÐÍÊÇĿ¼catalog
/Outlines 2 0 R //µÚ¶þ¸öobjÊÇoutlines
/Pages 3 0 R //µÚÈý¸öobjÊÇPages
/OpenAction 7 0 R // OpenAction ÔÚµÚ7¸öobj
>>
endobj //Ò»¸öobj½áÊø
1.3 cross reference table
xref
0 5
0000000000 65535 f
0000000009 00000 n
0000000074 00000 n
0000000120 00000 n
0000000179 00000 n
xrefÊÇobjµÄË÷Òý±í£¬ÓÃÀ´Ë÷Òý¸÷¸öobjÔÚÎĵµÖеÄÆðʼλÖã¬ËüµÄÐÎʽÈçÏÂͼ£¬ÆäÖÐ0,211·Ö±ð´ú±íÕâ¸öxrefµÄobjµÄÆðʼºÍÖÕÖ¹ÐòºÅ¡£ÏÂÃæ µÄ¸÷Ðоʹú±í¸÷¸öobjÔÚÕâ¸öÎĵµµÄÆðʼλÖã¬ÆäÖеÚÒ»´®×Ö·û£¨10¸ö£©´ú±íÆðʼλÖã¬ÖмäµÄÎå¸ö×Ö·ûÒ²ÊÇΪÁËÇø·ÖÓõģ¬Ö»Óе±Õâ¸ö¶ÔÏó±»É¾³ýµÄʱºò²ÅÓÐ ÓÃ,±íʾÕâ¸ö¶ÔÏó±»É¾³ýºóÓÖ±»ÖØÐÂÉú³ÉºóµÄ¶ÔÏóºÅ£¬ÏÖÔÚ»ù±¾ÉÏȫΪ0¡£ ºóÃæµÄ×ÖĸÓÐÁ½ÖÖ£ºf´ú±íɾ³ýµÄ£¬n´ú±íҪʹÓõġ£
1.4 trailer
trailer
<<
/Size 8
/Root 1 0 R
>>
ºóÃæµÄtrailerÊǶÔÕû¸öxrefµÄÕªÒª£¬ËµÃ÷ÀïÃæÓжàÉÙ¸öOBJ£¬¶ÁµÄʱºò´ÓÄĸöOBJ¿ªÊ¼½âÎö£¬ÐÅÏ¢½ÚµãµÈ£¬ÆäÖУº
/size :Õâ¸öpdfÖÐ×ܹ²Ê¹ÓÃÁ˶àÉÙ¸ö¶ÔÏó
/root :Õâ¸öpdfÎļþµÄcatalog¶ÔÏóµÄ¶ÔÏóºÅ,ÕâÊÇpdfÖÐ×²ãµÄ¶ÔÏ󣬼´PDFÊÇ×éÖ¯¶ÔÏóºÅ£¬´ËÀýÖÐλ 1 0 R
1.5 Îļþβ
startxref
553
%%EOF
ÒòΪһ¸öÎĵµÖпÉÒÔÓжà¸öxref£¬ËùÒÔÕâÀïÒªÖ¸Ã÷Òª´ÓÄĸöxref¿ªÊ¼½øÐнâÎöÕâ¸öÎļþ¡£
/startxref: ºóÃæµÄÊý×Ö±íʾcross reference tableµÄ¿ªÊ¼Î»Öã¬ÀïÃæµÄÊý×ÖÊÇ10½øÖÆ¡£
/%%EOF :Îļþ½áÊø·û.
1.6 OBJ¶ÔÏó
PdfµÄOBJÖеĶÔÏóÓÐÈçϼ¸ÖÖ£¬ÏÖ½éÉÜÈçÏ£º
(1)ÎļþÃèÊö¶ÔÏó£¬ÓÃÀ´ÃèÊöÕâ¸öÎļþµÄ±êÌ⣬×÷Õߣ¬Ê±¼äµÈ
(2)×é¶ÔÏó£¬Ò²¾ÍÊÇÎĵµÄÚÈݵÄÆðʼ½áµã¡£Type ΪCatalog
(3)Ò³¼¯ºÏ£¬ÀïÃæ¾ÛºÏÁË´óÁ¿µÄÒ³¶ÔÏó¡£ Type Ϊpages
(4)Ò³¶ÔÏó£¬ÀïÃæÖ¸Ã÷Á˵±Ç°Ò³ÀïÃæÓõ½µÄ×ÖÌ壬ÄÚÈÝ£¬»î¶¯¶ÔÏó£¬Í¼Æ¬µÈ¡£Type Ϊpage
(5)»î¶¯¶ÔÏó£¬ÓÐÁ´½Ó£¬ÎÄ×Ö£¬ÉùÒô£¬µçÓ°µÈ£¬Type ΪAnnots
(6)ͼƬ¶ÔÏó£¬ Type Ϊ XObject
(7)×ÖÌå¶ÔÏó£¬Type Ϊ Font ¡£PDF¿ÉÒÔÄÚÖÃ×ÖÌ壬ËùÒÔ¼´Ê¹Ä¿±ê»úÆ÷ÉÏûÓУ¬Ö»ÒªËüÄÚÖÃÁË£¬Ò²¿ÉÒÔÕý³£µØÏÔʾ£¬²»ÊÜÓ°Ïì¡£
(8)Á÷¶ÔÏó¡£ËùÓеĶþ½øÖÆÄÚÈݶ¼ÊÇ´æÔÚÕâ¸ö¶ÔÏóÀïÃ棬ÎļþÁ÷µÄ³£¼ûµÄѹËõ·½Ê½ÊÇ£ºÍ¼Æ¬µÄһЩѹËõËã ·¨£¬FlateDecode,ASCIIHexDecode,ASCII85DecodeµÈµÈ£¬FlateDecodeÊÂʵÉϾÍÊÇZIPµÄѹËõËã·¨¡£Á÷¶Ô ÏóµÄ³¤¶ÈÊǹØÁ¬µ½Ò»¸ö³¤¶È¶ÔÏóÉϵÄ/Length 188 0 RÕâÖÖÐÎʽ¡£188¾ÍÊÇ´æÕâ¸ö³¤¶ÈµÄOBJµÄ˳ÐòºÅ¡£
(9)Êý×Ö¶ÔÏó¡£ÀýÈ磺
188 0 obj
2538
endobj
ÀïÃæÖ»ÓÐÒ»¸öÊý×Ö£¬¾³£ÓÃÀ´±íʾ³¤¶È¡£
2¡¢VCÉú³ÉPDF
PDFLibÊÇÓÃÓÚ´´½¨PDFÎĵµµÄ¿ª·¢¿â£¬ÌṩÁ˼òµ¥Ò×ÓõÄAPI£¬Òþ²ØÁË´´½¨PDFµÄ¸´ÔÓϸ½ÚÇÒ²»ÐèÒªµÚ3·½Èí¼þµÄÖ§³Ö¡£ÒÑVC±à¼Ò»¸ö¿ØÖÆÓ¦ÓĄ̃³ÌÐòΪÀýÀ´Éú³ÉÒ»¸öPDF¡£
2.1 Ç°ÆÚ×¼±¸
Ïȵ½PDFLib¹ÙÍøÏÂÔØ¿âÎļþ£¬×îаæΪpdflib8£¬µ«ÊÇÉú³ÉµÄpdfÓÐÒ»¸ö¹ÙÍøµÄÍøÖ·£¬5.0°æ±¾ÒÔÏÂûÓУ¬Á´½ÓµØ Ö·£ºhttp://www.pdflib.com/download/p ... ¢¹¤³Ìºó£¬½«ÏÂÔØ¿âÖÐ pdflib.h,pdflib.dll,pdflib.lib¿½±´µ½¹¤³ÌĿ¼¡£
2.2 Ô´Âë
²ÎÕÕ¹ÙÍøÌṩµÄһЩsample£¬¸Ä±àÁËÒ»¸ö£¬Ô´´úÂëÈçÏ£º
#include "stdafx.h"
#include "pdflib.h"
#pragma comment(lib,"pdflib.lib")
int main()
{
PDF *p;
/* create a new PDFlib object */
if ((p = PDF_new()) == (PDF *) 0)
{
printf("Couldn't create PDFlib object (out of memory)!\n");
return(2);
}
PDF_TRY(p)
{
/* This means we must check return values of load_font() etc. */
PDF_set_parameter(p, "errorpolicy", "return");
if (PDF_begin_document(p, "pediy.pdf", 0, "") == -1)
{
printf("Error: %s\n", PDF_get_errmsg(p));
return(2);
}
// /* This line is required to avoid problems on Japanese systems */
// PDF_set_parameter(p, "hypertextencoding", "host");
PDF_set_info(p, "Creator", "pediy.c");
PDF_set_info(p, "Author", "youstar");
PDF_set_info(p, "Title", "Hello, pediy (C)!");
PDF_begin_page_ext(p, a4_width, a4_height, "");
/* Change "host" encoding to "winansi" or whatever you need! */
font = PDF_load_font(p, "Helvetica-Bold", 0, "host", "");
if (font == -1)
{
printf("Error: %s\n", PDF_get_errmsg(p));
PDF_delete(p);
return(2);
}
PDF_setfont(p, font, 24);
PDF_set_text_pos(p, 50, 700);
PDF_show(p, "pediy");
PDF_continue_text(p, "2010 better!");
PDF_end_page_ext(p, "");
PDF_end_document(p, "");
}
PDF_CATCH(p) {
printf("DFlib exception occurred in hello sample:\n");
printf("[%d] %s: %s\n",
PDF_get_errnum(p), PDF_get_apiname(p), PDF_get_errmsg(p));
PDF_delete(p);
return(2);
}
Ч¹ûÈçÏ£º
37114
3¡¢²Î¿¼×ÊÁÏ
¡¾1¡¿PDF¸ñʽÏê½âhttp://blog.csdn.net/bobob/archive/2006/05/23/751381.aspx
¡¾2¡¿PDFÎļþ¸ñʽhttp://ironsoft.cnblogs.com/archive/2006/01/05/311467.html
¡¾3¡¿PDFLib8ÏÂÔصØÖ·£º http://www.pdflib.com/download/pdflib-family/pdflib-8
¸½¼þÏÂÔØ£º
1¡¢±¾ÎÄÎÄÕ£º37115
2¡¢¹¤³ÌÔ´Â룺37116
3¡¢¿âÎļþ£º37117 |
|