Is there a way to minimize white borders around an image when adding image to a PDF?

I currently have an app that you take a picture using the phone camera and then use syncfusion to append the captured picture to the end of a PDF document. Is there a way to minimize or even get rid of the white borders around the image? And what are the best practices to draw the image to the PDF without losing quality?


1 Reply

GK Gowthamraj Kumar Syncfusion Team September 5, 2022 12:22 PM UTC

Hi Marlon,


Flutter PDF allows you to add an image to the PDF document. You can load image data in PdfBitmap object to draw the images using the drawImage method of the PdfGraphics class. 


Please refer to the below documentation,

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

https://www.syncfusion.com/kb/11965/how-to-convert-image-to-pdf-in-syncfusion-flutter-pdf-library


Please find the below code snippet to draw an image in a PDF document without losing quality,

//Create a new PDF document

PdfDocument document = PdfDocument();

 

//Adds a page to the document

PdfPage page = document.pages.add();

 

//Draw the image

page.graphics.drawImage(

    PdfBitmap(File('image.jpg').readAsBytesSync()),

    Rect.fromLTWH(

        0, 0, page.getClientSize().width, page.getClientSize().height));

 

//Saves the document

File('Output.pdf').writeAsBytes(document.save());

 

//Disposes the document

document.dispose();


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


Regards,

Gowthamraj K


Loader.
Up arrow icon