1

The line in the code below HtmlConverter.ConvertToPdf() is throwing an error stating "Invalid URI: The format of the URI could not be determined." and I can't figure it out.

Do I need a protocol prefix like file:// or is it something else?

The variable path resolves to '/data/user/0/com.companyname.worksmanager/files'

            try
            {

                string strCPP;
                using (StreamReader reader = new StreamReader(Application.Context.Assets.Open("CPP.html"), true))
                {
                    strCPP = reader.ReadToEnd();
                }

                PdfWriter pdfWriter = new PdfWriter(new FileInfo(Path.Combine(path, "CPP.pdf")));
                HtmlConverter.ConvertToPdf("<h1>test</h1>", pdfWriter);

            }
            catch(Exception ex)
            { }

Changing the way I create the file and changing the save directory still produces the same error message.

                string pathPDF = Path.Combine(Android.App.Application.Context.GetExternalFilesDir(null).ToString(), "CPP.pdf");
                HtmlConverter.ConvertToPdf(strCPP, new FileStream(pathPDF, FileMode.Create));
luigivampa
  • 377
  • 7
  • 22
  • Hi, can you attach the full stacktrace you get? Also, to minimize the amount of code and make sure the problem is in iText and not in the code fetching the resource, can you change your code sample a bit so that the resource `Application.Context.Assets.Open("CPP.html")` is not fetched and just plain conversion e.g. from `String` is used? Attaching this HTML will be necessary to reproduce the problem as well – Alexey Subach Dec 07 '21 at 06:58

0 Answers0