Click here to Skip to main content
Click here to Skip to main content

Text2PDF

, 3 Aug 2003
Rate this:
Please Sign up or sign in to vote.
A free utility to convert text files to Adobe PDF.

Introduction

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.

For conversion of text file to PDF, I use PDFLib library, 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.

What is 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 family.

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.

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.

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.

What is PDFlib?

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?

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.

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.

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.

If you checked "Launch PDF after conversion" check box, Acrobat Reader will be launched and shows your PDF (Figure 4).

Final PDF - Text2PDF Utility

Using the library

After downloading PDFlib library, add following header files and *.cpp files to your project: pdflib.h, pdflib.hpp, pdflib.cpp

Then add pdflib.lib to your project and at the top of your source code include pdflib.h (APIs) or pdflib.hpp (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();
}

If you do not have Acrobat Reader, download it by clicking this icon: Sample screenshot

Enjoy!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

A. Riazi
CEO Misbah3Com
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
I was born in Shiraz, a very beautiful famous city in Iran. I started programming when I was 12 years old with GWBASIC. Since now, I worked with various programming languages from Basic, Foxpro, C/C++, Visual Basic, Pascal to MATLAB and now Visual C++.
I graduated from Iran University of Science & Technology in Communication Eng., and now work as a system programmer for a telecommunication industry.
I wrote several programs and drivers for Synthesizers, Power Amplifiers, GPIB, GPS devices, Radio cards, Data Acqusition cards and so many related devices.
I'm author of several books like Learning C (primary and advanced), Learning Visual Basic, API application for VB, Teach Yourself Object Oriented Programming (OOP) and etc.
I'm winner of January, May, August 2003 and April 2005 best article of month competetion, my articles are:

You can see list of my articles, by clicking here


Comments and Discussions

 
QuestionHow about html to pdf? Pinmemberactivexbuff30-Jan-06 1:58 
AnswerRe: How about html to pdf? PinmemberA. Riazi30-Jan-06 5:54 
QuestionProperty Pinmemberamir mortazavi23-Oct-05 20:02 
AnswerRe: Property PinmemberA. Riazi23-Oct-05 22:12 
GeneralRe: Property Pinmemberamir mortazavi23-Oct-05 23:32 
GeneralRe: Property PinmemberA. Riazi23-Oct-05 23:52 
GeneralGuillermina PinsussGuillermina10-Jul-05 17:50 
GeneralRe: Guillermina PinmemberA. Riazi10-Jul-05 20:28 
Generalunable to download PDFlib Pinmemberleojose26-May-05 21:00 
GeneralRe: unable to download PDFlib PinmemberA. Riazi26-May-05 22:46 
QuestionDoest it support multi-language ? PinmemberNoradYeh25-May-05 20:29 
AnswerRe: Doest it support multi-language ? PinmemberA. Riazi26-May-05 22:47 
QuestionWin CE PDF create??? PinmemberSekar_Mokachandra30-Mar-05 12:10 
GeneralColorize Text PinmemberDavid A. Robinson2-Mar-05 9:48 
QuestionFREE????????????? PinmemberEarl Allen28-Aug-04 22:56 
AnswerRe: FREE????????????? PinmemberA. Riazi28-Aug-04 23:06 
GeneralPDFLib Library PinmemberCDRom8-Aug-04 5:07 
QuestionHow about PDF2Txt ? PinmemberJackyBear30-May-04 19:36 
AnswerRe: How about PDF2Txt ? PinmemberA. Riazi31-May-04 2:39 
GeneralRe: How about PDF2Txt ? PinmemberJackyBear1-Jun-04 3:21 
AnswerRe: How about PDF2Txt ? Pinmembermomo4602014-Aug-05 4:48 
QuestionCan you extract text with this library? Pinmemberno_reg_name20-May-04 5:02 
AnswerRe: Can you extract text with this library? PinmemberA. Riazi22-May-04 0:18 
QuestionI can't understand some properties? Pinmemberjurist27-Apr-04 3:28 
AnswerRe: I can't understand some properties? PinmemberA. Riazi27-Apr-04 4:41 
GeneralRe: I can't understand some properties? Pinmemberjurist29-Apr-04 2:47 
GeneralRe: I can't understand some properties? PinmemberA. Riazi30-Apr-04 17:59 
GeneralNice, but PinmemberAris Adrianto14-Feb-04 1:08 
GeneralRe: Nice, but PinmemberA. Riazi14-Feb-04 18:21 
Generala problem of changing the font Pinmemberweine_h11-Feb-04 7:33 
GeneralRe: a problem of changing the font PinmemberA. Riazi14-Feb-04 18:30 
GeneralPDF creation Pinmembermlariau21-Jan-04 4:23 
GeneralRe: PDF creation PinmemberA. Riazi21-Jan-04 22:01 
GeneralProgram cuts last 2 chars of a line Pinmemberdragomir6-Jan-04 1:43 
Questionhow to insert image? Pinmembergok2-Dec-03 12:57 
AnswerRe: how to insert image? PinmemberA. Riazi2-Dec-03 19:26 
GeneralProblems with barcode fonts Pinmemberviktor.v10-Nov-03 21:52 
GeneralRe: Problems with barcode fonts PinmemberA. Riazi10-Nov-03 22:48 
GeneralNice job PinmemberArash Sabet30-Sep-03 14:24 
GeneralRe: Nice job PinmemberA. Riazi30-Sep-03 20:35 
GeneralPrinting PDF PinmemberOBRon30-Sep-03 4:18 
GeneralRe: Printing PDF PinmemberA. Riazi30-Sep-03 5:05 
GeneralRe: Printing PDF Pinsusswithout money1-Oct-03 1:17 
GeneralRe: Printing PDF PinmemberA. Riazi1-Oct-03 1:41 
GeneraliTextSharp PinmemberFredrikT29-Sep-03 21:17 
GeneralRe: iTextSharp PinmemberA. Riazi29-Sep-03 23:03 
GeneralCongrats PinmemberColinDavies29-Sep-03 18:46 
GeneralRe: Congrats PinmemberA. Riazi29-Sep-03 19:44 
QuestionHow to perform reverse job PinmemberSasan6-Aug-03 5:18 
AnswerRe: How to perform reverse job PinmemberA. Riazi6-Aug-03 5:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141216.1 | Last Updated 4 Aug 2003
Article Copyright 2003 by A. Riazi
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid