[译]文字2PDF
By robot-v1.0
本文链接 https://www.kyfws.com/applications/text2pdf-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 6 分钟阅读 - 2612 个词 阅读量 0[译]文字2PDF
原文地址:https://www.codeproject.com/Articles/4690/Text2PDF
原文作者:A. Riazi
译文由本站 robot-v1.0 翻译
前言
A free utility to convert text files to Adobe PDF.
一个免费的实用程序,可将文本文件转换为Adobe PDF.
介绍(Introduction)
这是一个免费的实用程序,可将任何文本文件转换为PDF格式.如您所知,PDF是可移植文档格式的缩写.这意味着,您可以在许多平台上查看,编辑和打印此类文档,包括Microsoft Windows(3.1\9X,ME,2000,XP,2003),Linux,BSD,Sun Solaris,Unix,Mac等.(This is a free utility to convert any text file to PDF format. As you know PDF is an abbreviation of Portable Document Format. This means, you can view, edit and print this type of document in many platforms including Microsoft Windows (3.1, 9X, ME, 2000, XP, 2003), Linux, BSD, Sun Solaris, Unix, Mac, etc.)
为了将文本文件转换为PDF,我使用(For conversion of text file to PDF, I use) PDFLib库(PDFLib library) ,这是一个非常简单的API集合,用于即时创建PDF文件.该库可供个人免费使用,并且需要商业产品的许可.换句话说,您必须购买(, a very simple collection of APIs for creating PDF files on the fly. This library is free for personal usage and requires a license for commercial products. In other words, you must purchase a) 执照(license) 用于开发商业产品.(for developing commercial products.)
什么是PDF?(What is PDF?)
便携式文档格式(PDF)是在全球范围内安全可靠地分发和交换电子文档和表格的事实上的标准,具有十年的记录. PDF是一种通用文件格式,可以保留任何源文档的字体,图像,图形和布局,而与创建它的应用程序和平台无关. Adobe®PDF文件紧凑而完整,任何拥有免费AdobeReader®软件的人都可以共享,查看和打印.迄今为止,已经分发了超过5亿个软件副本.您可以使用AdobeAcrobat®软件产品将任何文档转换为Adobe PDF,使业务,工程和创意专业人士可以创建,分发和交换安全可靠的Adobe PDF文档.有关更多信息,请参见(Portable Document Format (PDF) is the de facto standard for secure and reliable distribution and exchange of electronic documents and forms around the world, with a ten-year track record. PDF is a universal file format that preserves the fonts, images, graphics, and layout of any source document, regardless of the application and platform used to create it. Adobe® PDF files are compact and complete, and can be shared, viewed, and printed by anyone with free Adobe Reader® software. To date, more than 500 million copies of the software has been distributed. You can convert any document to Adobe PDF using Adobe Acrobat® software products, enabling business, engineering, and creative professionals to create, distribute, and exchange secure and reliable Adobe PDF documents. For more information, see the) Adobe Acrobat系列(Adobe Acrobat family) .(.)
全世界的政府和企业都采用PDF来简化文档管理,提高生产率并减少对纸张的依赖.例如,PDF是用于以电子方式向美国食品和药物管理局(FDA)提交药品批准以及在美国联邦法院进行电子案件归档的标准格式.英国和德国政府也使用它进行电子文档交换.最后,ISO的PDF/X规范是用于发布的广告的数字分发的标准文件格式.(Governments and enterprises around the world have adopted PDF to streamline document management, increase productivity, and reduce reliance on paper. For example, PDF is the standard format for the electronic submission of drug approvals to the U.S. Food and Drug Administration (FDA), and for electronic case filing in U.S. federal courts. It is also used by the governments of the United Kingdom and Germany for electronic document exchange. Finally, the ISO’s PDF/X specification is the standard file format used for the digital distribution of advertisements for publication.)
PDF是一种开放文件格式规范,可供所有想要开发工具来创建,查看或操作PDF文档的人使用.实际上,有1,800多家供应商提供基于PDF的解决方案,从而确保采用PDF标准的组织拥有各种工具来利用可移植文档格式和自定义文档流程.(An open file format specification, PDF is available to anyone who wants to develop tools to create, view, or manipulate PDF documents. Indeed, more than 1,800 vendors offer PDF-based solutions, ensuring that organizations that adopt the PDF standard have a variety of tools to leverage the Portable Document Format and to customize document processes.)
消费者也将从PDF平台的普遍性中受益,因为Adobe Reader允许他们查看使用AdobePhotoshop®Album软件创建的多媒体PDF幻灯片显示和电子卡.(Consumers benefit from PDF’s platform ubiquity as well, because Adobe Reader lets them view rich-media PDF slide shows and electronic cards created using Adobe Photoshop® Album software.)
什么是PDFlib?(What is PDFlib?)
PDFlib是一个开发工具,用于使软件支持PDF或在服务器上生成PDF. PDFlib通过提供一个简单易用的API,可从您自己的服务器或客户端软件中以编程方式创建PDF文件,从而节省了PDF生成的复杂细节. PDFlib不使用第三方软件来生成PDF,也不需要任何其他工具.(PDFlib is a development tool for PDF-enabling your software, or generating PDF on your server. PDFlib saves you the intricate details of PDF generation by offering a simple-to-use API for programmatically creating PDF files from within your own server- or client-side software. PDFlib doesn’t make use of third-party software for generating PDF, nor does it require any other tools.)
该程序如何工作?(How the program works?)
起点是选择要转换为PDF的文本文件(图1).此后,您必须选择所需的字体. Arial 12是用于转换的默认字体,但是您的手可以自由选择任何真型字体.所选字体将嵌入到PDF文件中.(Starting point is selecting a text file that you want to convert to PDF (figure 1). After this, you must select your desired font. Arial 12 is default font for converting, but your hand is free to choose any true type font. The selected font will be embedded in the PDF file.)
该程序的逻辑非常简单.只需读取整个文本文件,然后计算字符串的宽度,然后将它们逐行添加到PDF文件即可.添加文本,页面和字体是PDFLib的职责.图2显示了这种逻辑.(Logic of the program is very simple. Just read entire text file, then compute width of strings and add them to PDF file line by line. Adding text, page and font is the duty of PDFLib. Figure 2 shows this logic.)
为了控制您的PDF文件,有一些选项.例如,Acrobat如何显示PDF,页面大小(A4,Letter,…),页边距和打开模式(缩略图,书签…)是多少.图3显示了Text2PDF实用程序的选项对话框.(For controlling on your PDF file, there is some options. For example, how Acrobat shows your PDF, what is your page size (A4, Letter, …), margins and open mode (thumbnail, bookmark, …). Figure 3 shows options dialog of Text2PDF utility.)
如果选中了"转换后启动PDF"复选框,Acrobat Reader将启动并显示您的PDF(图4).(If you checked “Launch PDF after conversion” check box, Acrobat Reader will be launched and shows your PDF (Figure 4).)
使用图书馆(Using the library)
下载PDFlib库后,添加以下头文件并(After downloading PDFlib library, add following header files and)** .cpp(**.cpp*)*文件到您的项目:(*files to your project:*)*pdflib.h(*pdflib.h*)*,(*,*)*pdflib.hpp(*pdflib.hpp*)*,(*,*)*pdflib.cpp(*pdflib.cpp*)*
然后加(Then add)pdflib.lib(pdflib.lib)到您的项目,并且在源代码的顶部包括(to your project and at the top of your source code include)pdflib.h(pdflib.h)(API)或((APIs) or)pdflib.hpp(pdflib.hpp)(PDFLib类定义).这是一个示例:((PDFLib class definition). Here is a sample:)
#include <span class="code-string">"pdflib.hpp"</span>
void CreatePDF()
{
PDFlib pdf;
pdf.set_parameter("compatibility", "1.4"); //Compatible for Acrobat 5
if (pdf.open("test.pdf")==-1)
{
AfxMessageBox("Can not create PDF file.", MB_ICONERROR);
return;
}
pdf.begin_page(a4_width, a4_height);
//Font will be embedded in PDF
int font=pdf.findfont("Arial", "winansi", 1);
pdf.setfont(font, 12);
pdf.set_text_pos(10, a4_height - 10);
pdf.show("Hello World!");
pdf.end_page();
pdf.close();
}
如果您没有Acrobat Reader,请单击以下图标下载它:(If you do not have Acrobat Reader, download it by clicking this icon:)
请享用!(Enjoy!)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ VC6 WinXP Win2003 Windows Win2K Visual-Studio Dev 新闻 翻译