在Xamarin.Forms中,我想将我的xaml页面UI(有时我的页面在有更多内容时是可滚动的)转换为PDF。我已经尝试过PDFSharp (https://github.com/akgulebubekir/PDFSharp.Xamarin.Forms https://github.com/akgulebubekir/PDFSharp.Xamarin.Forms)开源。但它仅适用于 UWP,并且在 iOS 和 Android 中存在一些问题。
那么有没有免费的开源插件可以在所有三个平台上将 XAML UI 转换为 PDF?如果开源不可用,是否有其他方法或解决方法可以在 android、ios 和 UWP 中实现它?
提前致谢。
我在这方面遇到了一些麻烦,并设法使用 UIkit 和 PdfKit 工具来做到这一点。
这是一个例子:
using UIKit;
using PdfKit;
//Calculate scroll View height
double xamlHeight = XamlFullPage.Height;
int numberOfPages = (int)Math.Ceiling(xamlHeight / Application.Current.MainPage.Height);
// Create a new PDF document
PdfDocument document = new PdfDocument();
for (int i = 0; i<numberOfPages; i++) //while all the page have not been taken into account
{
await SummaryScrollView.ScrollToAsync(0, i*Application.Current.MainPage.Height, false).ConfigureAwait(false); //find the beginning of the current page
//Captures the XAML page as an image and returns the image in memory stream
var image = UIScreen.MainScreen.Capture();
// Create a page with the printscreen
PdfPage page = new PdfPage(image);
//insert page in the i position
document.InsertPage(page, i);
page.Dispose();
}
//Write file in temp folder
document.Write(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "TuitionFees" + fileName + ".pdf"));`
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)