How to convert text file to pdf
Portable Document Format (PDF) is a universally accepted document formats. It prevents formatting errors from cropping up due to text file incompatibilities, making PDFs is an official documents like resumes and important documentations. Converting from a Text file to PDF is an easy task. We can use Pdfsharp open source library for creating and manipulating PDF documents programmatically from .Net supported languages. From the following steps you can easily convert a text file to a PDF format document.
You can freely download the Assemblies version from the following link: Download PDFsharp Assemblies
After download the zip file, extract it and add the reference to your VB.NET project.
If you want to know the step by step tutorial on how to create your first pdf file programmatically, follow the link : How to create PDF file programmatically
Steps to create PDF file programmatically.
First step you should Imports the necessary namespaces.
In order to read from a text file, you should create a Text Reader Object.
Then you have to create a PDF Object for creating your new PDF file.
and create the page.
Also initialize the Graphics and Font
Now you can read from the text file and write the content to the PDF Object.
In the above code we set X as 40 pixels from the left side and Y set as "yPoint", because after write the each line yPoint will increment 40 pixels line spacs then only you will get a good line space.
yPoint = yPoint + 40
When you finish reading and writing, then you can save the PDF Object.
You can include the path when you specify the file name.
Then close the Reader Object.
After save the file , you can double click and open the pdf file. Then you can see the content in PDF file same as in Text file.
The following program shows how to generate a PDF formatted file from TXT file content.
- How to VB.NET Directory operations
- How to VB.NET File operations
- How to VB.NET FileStream
- How to VB.NET TextReader
- How to VB.NET Simple TextReader
- How to VB.NET TextWriter
- How to VB.NET BinaryReader
- How to VB.NET BinaryWriter
- How to convert xps file to bmp file
- How to VB.Net Path Class
- How to create PDF files in vb.net
- Write database to PDF file