我使用richtextbox创建文本块并将其保存到数据库。之后,我试图用字符串创建一个PDF。
我的问题是我无法找到在PDF中显示格式化字符串的方法,它显示了每个< p>等而不是正确使用它们。如果用PDFsharp不可能有其他可能性吗?
// Create a new PDF document
PdfDocument document = new PdfDocument();
// Create an empty page
PdfPage oPage = document.AddPage();
// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(oPage);
//Drawing Images and Rectangles and other things
//sText is just an example of what my DB string looks like
string sText = "<p>Here you can see formattet text<\p> \n
always multiple rows and some gü or /r"
gfx.DrawString(sText, NormalText, XBrushes.Black, new XRect(XUnit.FromCentimeter(3.2), XUnit.FromCentimeter(16.35), oPage.Width, oPage.Height), null);
// Send PDF to browser
MemoryStream stream = new MemoryStream();
document.Save(stream, false);
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", stream.Length.ToString());
Response.BinaryWrite(stream.ToArray());
Response.Flush();
stream.Close();
Response.End();