Hi Guys,
I am having a bit of a problem converting .RTF File format to .PDF using PDFSharp Version 1.50.
My output result is a blank page, I would really appriciate your help and sample code.
Here is my code
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();
}
Your sample code will be much appreciated.
Thanks