androidpdfmauiitext7

In android using net Maui what is the Path for the images saved on resources\images\logo.png


I'm creating an app that will generate a balance statement that includes an image on the PDF. I use the IText7 on the following sample: https://dev.to/davidelegbede/create-pdf-in-net-core-using-itext7-3k2i

Here is where I have the problem, finding that path where the Android package stores the image created with build actions "MauiAsset", "MauiImage" and "Resource".

public class PDFHeaderEventHandler : IEventHandler
{
   public void HandleEvent(Event currentEvent)
   {
     try
     {
          PdfDocumentEvent docEvent = (PdfDocumentEvent)currentEvent;
            string logoPath = "Assets/logo.png";   **Here is the path i need to know**
            var logo = ImageDataFactory.Create(logoPath);
            PdfPage page = docEvent.GetPage();

The location returns I/O Exception "File not found", I tried using FileSystem.AppDataDirectory without luck.

System.IO.Path.Combine(FileSystem.AppDataDirectory, "images/logo.png"); System.IO.Path.Combine(FileSystem.AppDataDirectory, "assets/logo.png");

System.IO.Path.Combine(FileSystem.AppDataDirectory, "/images/logo.png"); System.IO.Path.Combine(FileSystem.AppDataDirectory, "/assets/logo.png");


Solution

  • As an answer:

    The static files in the Resources folder will be embed into the apk file when you publish it. And these files are only readable.

    In addition, you can read them with the FileSystem.Current.OpenAppPackageFileAsync. For more information, you can refer to the official document about the File system helpers.