How to convert a plain text to pdf file using C# [Resolved]

Posted by Mahendrabasutkar under C# on 12/14/2011 | Points: 10 | Views : 10060 | Status : [Member] | Replies : 7
Hi,

How to convert a plain text to pdf file using C#, but without using iTextSharp.dll


Regards,
Mahendra




Responses

Posted by: Ashokst on: 10/29/2015 [Member] Starter | Points: 50

Up
1
Down

Resolved
After searching your topic in Google, I found following code snippet work for your requirements. Pleas check:


using Spire.Pdf;
using System.IO;
using Spire.Pdf.Graphics;
using System.Drawing;

namespace TexttoPDF
{
class Program
{
static void Main(string[] args)
{
string text = File.ReadAllText("TestDocument.txt");
PdfDocument doc = new PdfDocument();
PdfSection section = doc.Sections.Add();
PdfPageBase page = section.Pages.Add();
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 11);
PdfStringFormat format = new PdfStringFormat();
format.LineSpacing = 20f;
PdfBrush brush = PdfBrushes.Black;
PdfTextWidget textWidget = new PdfTextWidget(text, font, brush);
float y = 0;
PdfTextLayout textLayout = new PdfTextLayout();
textLayout.Break = PdfLayoutBreakType.FitPage;
textLayout.Layout = PdfLayoutType.Paginate;
RectangleF bounds = new RectangleF(new PointF(0, y), page.Canvas.ClientSize);
textWidget.StringFormat = format;
textWidget.Draw(page, bounds, textLayout);
doc.SaveToFile("TxtToPDf.pdf", FileFormat.PDF);
}
}


You need import dll from Nuget (http://www.nuget.org/packages/FreeSpire.PDF/ ) to your VS project and add necessary namespace at the beginning.

Mahendrabasutkar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Arefin on: 12/15/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

You can see the below link:
http://www.codeproject.com/KB/graphics/convertexttopdf.aspx

Thanks,
Arefin

Mahendrabasutkar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jonygreen on: 10/10/2015 [Member] Starter | Points: 25

Up
0
Down
I'm not a developer, i always use this free online pdf to text converter(http://www.online-code.net/pdf-to-word.html) to convert pdf to text online.

Mahendrabasutkar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Punjabi87 on: 10/21/2015 [Member] Starter | Points: 25

Up
0
Down
If you don’t want to use iTextSharp then you need to use other PDF library. That is because PDF is not a native Windows format. I used leadtools to generate the PDF files for my application using a class they have called Document Writers and it worked great.
I also did a quick search to find examples for you and found the following links:
https://social.msdn.microsoft.com/Forums/en-US/2cf30017-cd87-4454-8c8f-52a99e76e40c/how-to-convert-text-file-into-pdf-in-c?forum=csharplanguage
http://www.codeproject.com/Articles/12266/Convert-a-Text-File-to-a-PDF-File
http://www.dreamincode.net/forums/topic/95480-text-to-pdf-in-c%23/


Mahendrabasutkar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Narenkumar851 on: 10/22/2015 [Member] Starter | Points: 25

Up
0
Down
use iTextSharp dll file to conver it
like http://dotprogramming.blogspot.com/2015/03/how-to-create-pdf-file-in-windows-form-c.html

Mahendrabasutkar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Evanpan on: 12/12/2015 [Member] Starter | Points: 25

Up
0
Down
I wonder whether there are any differences between the pdf converter I am testing these days and the one you mentioned above?
http://www.pqscan.com/convert-pdf/


Mahendrabasutkar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lucygrey on: 12/15/2015 [Member] Starter | Points: 25

Up
0
Down
Hi,
You can use the iText library (http://itextpdf.com/) to convert the simple text into the PDF files.

For more detail go through the following link
http://www.c-sharpcorner.com/Blogs/10025/convert-text-document-to-pdf-file.aspx

Thanks!!


http://www.keenesystems.com/Services/SoftwareDevelopment.aspx

Mahendrabasutkar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response