简体   繁体   English

CrossPlatform Xamarin表单:如何在本地存储中创建PDF文件

[英]CrossPlatform Xamarin forms : How to create PDF file in local storage

Hello I am trying to create a PDF file with using a crossplatform APP made by net standard 2.0 Xamarin forms. 您好,我正在尝试使用由网络标准2.0 Xamarin表单制作的跨平台APP创建PDF文件。

I have a photo stream taken by camera and I want to add it to my pdf 我有一个由相机拍摄的照片流,我想将其添加到我的pdf中

// here i check and grant permission


if (status == PermissionStatus.Granted)
{

                        PhotoImage.Source = ImageSource.FromStream(() => { return photo.GetStream(); });
                        Stream a = photo.GetStream();
                        string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "test.pdf");

                        Document document = new Document();

                        using (var stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.Write))
                        {
                            PdfWriter.GetInstance(document, stream);
                            document.Open();
                            using (var imageStream = photo.GetStream())
                            {
                                var image = Image.GetInstance(imageStream);
                                document.Add(image);
                            }
                            document.Close();
                        }

                    }

The file test.pdf isn't created in the path : 未在路径中创建文件test.pdf:

"/data/user/0/com.companyname.XXX/files/.config/test.pdf" “ /data/user/0/com.companyname.XXX/files/.config/test.pdf”

or at least I can't see it when i check in my phone. 或者至少当我检入手机时看不到它。

I tested also the path : "/data/user/0/com.companyname.XXX/files/test.pdf" 我还测试了路径:“ / data / user / 0 / com.companyname.XXX / files / test.pdf”

please help . 请帮忙 。

Edit : I am using iTextSharp 编辑:我正在使用iTextSharp

You can use iTextSharp NuGet to do this. 您可以使用iTextSharp NuGet来做到这一点。 Or first you can try to create a single file in single project page, like MainActivity.cs 或者首先,您可以尝试在单个项目页面中创建单个文件,例如MainActivity.cs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Xamarin Forms-获取保存在本地存储中的图像的文件名 - Xamarin Forms - getting the file name of an image held in local storage 如何使用Xamarin-Forms下载图像并将其保存在本地存储中? - How to download image and save it in local storage using Xamarin-Forms.? 在 Xamarin Forms 中创建本地设置 - Create local setting in Xamarin Forms 如何在 Xamarin.Forms 中将非图像文件(pdf、pptx、docx)从 FirebaseStorage 下载到设备的内部存储? - How to download non-image file(pdf,pptx,docx) from FirebaseStorage to internal storage of device in Xamarin.Forms? 如何在Android上使用Xamarin.Forms创建文件? - How to create a file with Xamarin.Forms on Android? Xamarin中的跨平台 - crossplatform in Xamarin 如何在 xamarin 表单 webview 中加载本地 html 文件 - How to load a local html file in a xamarin forms webview 使用Xamarin Crossplatform在应用程序不在设备的最新历史记录中时如何显示本地通知 - How to display local notification when the app is not in the recent history of the device using Xamarin Crossplatform Xamarin Forms:文件未保存在 android 存储中 - Xamarin Forms: File was not saved on the android storage 使用Xamarin Crossplatform打开开始表单并关闭所有其他表单 - Open start form and close all other Forms with Xamarin Crossplatform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM