如何在uwp c#中创建pdf文档

时间:2018-02-07 13:48:33

标签: c# pdf uwp-xaml

我搜索了如何创建具有通用Windows平台的pdf文档。

我一直在寻找解决方案而且我找到了这个,但它根本不起作用:

 string path = "test.pdf";
 byte[] byteArray = Encoding.UTF8.GetBytes(path);
 Stream stream = new MemoryStream(byteArray);

 PdfDocument pdf = new PdfDocument();
 PdfPage pdfPage = new PdfPage();
 using (PdfDocument document = new PdfDocument())
 {
     //Add a page in the PDF document.
     PdfPage page = document.Pages.Add();
     //Access the PDF graphics instance of the page.
     PdfGraphics graphics = page.Graphics;
     //Create the PDF font instance.
     PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 15);
     //Draw the text in PDF page.
     graphics.DrawString("Hello world!", font, PdfBrushes.Black, new PointF(20, 20));
     //Save the PDF document to disk
     pdf.Save(stream);
}

感谢您的阅读

错误pdf.Save(stream):System.NotSupportedException:'内存流不可扩展。'

0 个答案:

没有答案