c# - 与当前 android 版本 (8.1) 兼容的 pdf 操纵器
问题描述
我正在开发一个 android 应用程序,该应用程序需要通过填写现有的 .pdf 表单插入应用程序中的信息来生成 .pdf。我可以使用什么与 xamarin 当前的 android 版本一起使用
我试过 Itextsharp、Itext 7 和 PDF Box,但它们都已经过时了。
解决方案
Android 有一个内置的 PDF 生成类。请参阅: https ://developer.android.com/reference/android/graphics/pdf/PdfDocument
API 的典型用法如下所示[移植到 C#]:
// create a new document
PdfDocument document = new PdfDocument();
// crate a page description
PageInfo pageInfo = new PageInfo.Builder(100, 100, 1).Create();
// start a page
Page page = document.StartPage(pageInfo);
// draw something on the page
View content = FindViewById(Android.Resource.Id.Content);
content.Draw(page.Canvas);
// finish the page
document.FinishPage(page);
// add more pages
// write the document content
FileStream fileOutputStream = new FileStream(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), FileMode.CreateNew);
document.WriteTo(fileOutputStream);
// close the document
document.Close();