|
C# PDF Text Converter Library
How to convert text file (txt) to PDF document using C#.NET in ASP.NET, Windows apps
C#.NET Demo code for Creating PDF from Text with XDoc.PDF Library for .NET in C#
- Best C# text to PDF converter SDK for converting adobe PDF from TXT in Visual Studio .NET project
- .NET control for batch converting text formats to editable & searchable PDF document
- Free .NET library for creating PDF from TXT in both C#.NET WinForms and ASP.NET application
-
More about PDF converter library:
pdf to image conversion using c#,
c# generate pdf with images,
convert powerpoint to pdf c#,
convert pdf to tiff in c#.net,
c# convert doc to pdf free,
c# pdf page to bitmap,
c# pdf converter.
- Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
- All text message can be copied and pasted to PDF file by keeping original layout
- C#.NET class source code for creating PDF document from rich text in .NET framework project
- Convert plain text to PDF text with multiple fonts, sizes and colors
How to convert text file to PDF document in C#.NET
Now you can convert text file to PDF document using the C# demo code we have offered below.
#region text to pdf (file to file)
internal static void textToPdf()
{
String inputFilePath = @"C:\demo.txt";
String outputFilePath = @"C:\output.pdf";
DocumentConverter.ToDocument(inputFilePath, outputFilePath, FileType.DOC_PDF);
}
#endregion
#region text to pdf (stream to stream)
internal static void textStreamToPdf()
{
String inputFilePath = @"C:\demo.txt";
Stream stream = File.Open(inputFilePath, FileMode.Open);
Stream outputStream = new MemoryStream();
DocumentConverter.ToDocument(stream, outputStream, FileType.DOC_PDF);
}
#endregion
C# convert two or multiple Text files to PDF (batch convert)
#region text to pdf (batch files)
internal static void convertTextFilesToPdf()
{
String inputDirectory = @"C:\input\";
String outputDirectory = @"C:\output\";
String[] files = Directory.GetFiles(inputDirectory, "*.txt");
foreach (String filePath in files)
{
int startIdx = filePath.LastIndexOf("\\");
int endIdx = filePath.LastIndexOf(".");
String docName = filePath.Substring(startIdx + 1, endIdx - startIdx - 1);
DocumentConverter.ToDocument(filePath, outputDirectory + docName + ".pdf", FileType.DOC_PDF);
}
}
#endregion
C# combine multiple Text files into PDF
#region combine text files and convert to pdf
internal static void combineAndConvertToPdf()
{
String[] files = new String[] { @"C:\demo1.txt", @"C:\demo2.txt", @"C:\demo3.txt" };
String outputFilePath = @"C:\output.pdf";
List<MemoryStream> streams = new List<MemoryStream>();
foreach (String filePath in files)
{
FileStream inputStream = File.Open(filePath, FileMode.Open);
MemoryStream outputStream = new MemoryStream();
DocumentConverter.ToDocument(inputStream, outputStream, FileType.DOC_PDF);
streams.Add(outputStream);
inputStream.Close();
}
PDFDocument.CombineDocument(streams.ToArray(), outputFilePath);
}
#endregion
C# insert Text file into pdf document, and create a new PDF file
#region insert text to pdf
internal static void insertTextToPdf()
{
String filePath = @"C:\demo.txt";
Stream inputStream = File.Open(filePath, FileMode.Open);
MemoryStream desStream = new MemoryStream();
DocumentConverter.ToDocument(inputStream, desStream, FileType.DOC_PDF);
PDFDocument pdf = new PDFDocument(desStream);
int pageCount = pdf.GetPageCount();
List<BasePage> pages = new List<BasePage>();
for (int i = 0; i < pageCount; i++)
{
pages.Add(pdf.GetPage(i));
}
String outputPdf = @"C:\output.pdf";
PDFDocument desDoc = new PDFDocument(outputPdf);
int insertLocation = 2;
desDoc.InsertPages(pages.ToArray(), insertLocation);
desDoc.Save(@"C:\desDocumcnet.pdf");
}
#endregion
|