如何在C#windowsphone编程中绘制PDF或打开PDF并添加批注?

How to draw a PDF or open a PDF and add annotation in C# windows phone programming?

我想要一个示例,展示如何在 C# 中打开或创建带有注释功能的 PDF

您将需要第 3 方库来在 Windows Phone 上创建 PDF 文件,因为 .NET Framework 不包含 API 用于处理 PDF 文件。
下面的代码显示了如何创建一个 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 库的公司工作。