mashispano
Member
- Joined
- Feb 5, 2024
- Messages
- 6
- Programming Experience
- 3-5
Hi Guys, I need help converting .RTF File format to .PDF using PDFSharp Version 1.50 my output result is always a blank page, I would really appreciate your help and sample code.
Here is my ASP.NET C# Code
I have no problem converting flat .TXT file my only problem is converting .RTF(Rich Text File) to .PDF
Thanks
Al
Here is my ASP.NET C# Code
RTF To PDF Help:
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.Adapters;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using TheArtOfDev.HtmlRenderer.PdfSharp;
using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using System.Threading;
using System.Threading.Tasks;
protected void ConvertRtf2Pdf()
{
//- Source RTF Filename and path
var MySourceRTFile = HttpContext.Current.Server.MapPath("~/templates/sample.rtf");
//- Target PDF Filename and path
var _sFileName = "SAMPLE_" + DateTime.Now.ToString("yyyyMMdd") +
DateTime.Now.ToString("HH:mm:ss").Trim().Replace(":", "") + ".pdf";
var MyTragetPDFile = HttpContext.Current.Server.MapPath("~/export/" + FileName);
//- Read the Source RTF file
string docfi = System.IO.File.ReadAllText(MySourceRTFile);
//- Start creating the PDF document
PdfDocument pdfDoc = new PdfDocument();
PdfPage pdfPage = pdfDoc.AddPage();
XGraphics graph = XGraphics.FromPdfPage(pdfPage);
XFont font = new XFont("Time New Roman", 0, XFontStyle.Regular);
graph.DrawString(docfi, font, XBrushes.Black, new XRect(0, 0, 0, 0),
XStringFormats.Default);
//- Final result
pdfDoc.Save(MyTragetPDFile);
pdfDoc.Dispose();
}
I have no problem converting flat .TXT file my only problem is converting .RTF(Rich Text File) to .PDF
Thanks
Al