我使用richtextbox創建文本塊並將它們保存到數據庫。之後,我嘗試用字符串創建一個PDF。PDFSharp解析富文本字符串
我的問題是,我不能找到一種方法來顯示在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();
是pdfsharp能夠解釋html標籤嗎? –
我不是很確定,但是現在對我的情況來說,它是最好的,可以免除html字符串。 – MaxW
我覺得通常你會用手做。 PdfSharp中有一些方法可以創建一個'Section'並在頁面中添加'Paragraphs'並以這種方式構造它。看看[這](http://www.pdfsharp.net/wiki/invoice-sample.ashx) –