We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

ERROR: Unhalded exception: type 'PdfReferenceHolder' is not a subtype of type 'PdfDictionary?' in type cast

Hello,

I'm trying to put an image on a PDF. I have this code:

page1.graphics.drawImage(PdfBitmap(firma.readAsBytesSync()),
        const Rect.fromLTWH(450, 356, 75, 20));

But when I try to initialize the PDF I get the error:

E/flutter ( 1231): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: type 'PdfReferenceHolder' is not a subtype of type 'PdfDictionary?' in type cast


The var "firma" is a File variable. What can I do?


Thanks!


7 Replies

IJ Irfana Jaffer Sadhik Syncfusion Team October 20, 2022 07:06 AM

Hi Ruben,

Syncfusion Flutter Pdf provide support to load the image in JPG and PNG format. So we cannot able to load image using the file stream. We request to follow the below steps to load and draw the image to the pdf document:

//Draw an image.

graphics.drawImage(PdfBitmap(await _readImageData('photo.jpg')),  Rect.fromLTWH(107, 50, 300, 300));


Please follow the below links for more information,

https://help.syncfusion.com/flutter/pdf/working-with-images


If this does not satisfy your requirement, we request you share the image file with us. So that will be helpful for us to assist you further in this.


Regards,

Irfana J





RD Ruben Donat replied to Irfana Jaffer Sadhik October 24, 2022 02:47 AM

Hello Irfana.

 I have tried to follow the steps indicated in the link. But they are not useful to me. Is there any way to show you the code better so that you can help me? 


Thank you!



RD Ruben Donat replied to Irfana Jaffer Sadhik October 24, 2022 03:22 AM

Hi again,

I enclose a screenshot of the error that it gives me even following your steps. Cheers!

Captura.PNG



IJ Irfana Jaffer Sadhik Syncfusion Team October 26, 2022 01:48 AM

Hi Ruben,


We were unable to reproduce the reported behavior from our side. The reported code sample is working as expected without any exceptions. We have attached a simple sample to draw images from assets and URLs from our side and have attached its generated output. Kindly run this sample for reference and let us know the results obtained from your side.


Sample and generated output link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/image_to_pdf_sample-556604858


Regards,

Irfana J



RD Ruben Donat replied to Irfana Jaffer Sadhik October 28, 2022 02:29 AM

Hi Irfana,

It seems that the problem is the version of the SDK. I'm looking to upgrade my project's SDK and see if this was the problem. As soon as I can I'll tell you something



RD Ruben Donat replied to Irfana Jaffer Sadhik October 28, 2022 03:37 AM

Hello again. I have found the problem. The problem was that I had a PDFDocument.fromBase64String. I don't know if you take into account the reason for the failure, but it would be interesting that just as you can enter text in a preloaded PDF, you can also enter images.



IJ Irfana Jaffer Sadhik Syncfusion Team October 31, 2022 06:25 AM

Hi Ruben,


We have tried to reproduce the reported issue with the provided details on our end. but it is working properly. we suspect that the issue may be because of the document specific. we request you share the simple sample, and input documents like pdf and image files with us. so that will be helpful for us to assist you further in this.


Please let us know if you need any further assistance with this.


Regards,

Irfana j.


Loader.
Live Chat Icon For mobile
Up arrow icon