如何在C#windows phone编程中绘制PDF或打开PDF并添加注释?

时间:2016-06-23 09:11:26

标签: c# pdf windows-phone

我想有一个示例,它显示我打开或使用C#

中的注释工具创建PDF

1 个答案:

答案 0 :(得分:1)

您需要第三方库才能在Windows Phone上创建PDF文件,因为.NET Framework不包含用于处理PDF文件的API。
下面的代码显示了如何创建PDF文件并添加使用XFINIUM.PDF库对文本进行注释:

// Create a new document and add a page to it
PdfFixedDocument document = new PdfFixedDocument();
PdfPage page = document.Pages.Add();

// Create the text annotation and set its properties.
PdfTextAnnotation ta = new PdfTextAnnotation();
ta.Author = "John Doe";
ta.Contents = "I am a text annotation.";
ta.IconName = "Note";
// Add the annotation to the page
page.Annotations.Add(ta);
ta.Location = new PdfPoint(50, 50);

// Save the document
// Get a local folder for the application.
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;

StorageFile pdfFile = await storageFolder.CreateFileAsync("sample.pdf", CreationCollisionOption.ReplaceExisting);
var pdfStream = await pdfFile.OpenAsync(FileAccessMode.ReadWrite);

// Convert the random access stream to a .NET Stream and save the document.
using (Stream stm = pdfStream.AsStream())
{
    document.Save(stm);
    await stm.FlushAsync();
}
pdfStream.Dispose();

MessageDialog messageDialog = new MessageDialog("File(s) saved with success to application's local folder.");
await messageDialog.ShowAsync();

免责声明:我为开发XFINIUM.PDF库的公司工作。