【发布时间】:2019-10-15 17:12:38
【问题描述】:
我正在开发一个 .pdf 应用程序,该应用程序需要通过填写现有 .pdf 表单插入应用程序中的信息来生成 .pdf。 我可以使用什么与 xamarin 当前的 android 版本一起使用
我尝试过 Itextsharp、Itext 7 和 PDF Box,但它们都已经过时了。
【问题讨论】:
我正在开发一个 .pdf 应用程序,该应用程序需要通过填写现有 .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();
【讨论】: