|
//Create a PdfDocument
final PdfDocument document = PdfDocument();
//Add page to PdfDocument
final PdfPage page = document.pages.add();
//Create image from file
final File file = File('data/faceImage.png');
final PdfImage image = PdfBitmap(file.readAsBytesSync());
//Get page graphics
final PdfGraphics pageGraphics = page.graphics;
//Save Pdf graphics state
final PdfGraphicsState state = pageGraphics.save();
//Create PdfPath and clip the rectangle bounds in page graphics
final PdfPath path = PdfPath();
path.addEllipse(Rect.fromLTWH(150, 50, 200, 200));
pageGraphics.setClip(path: path);
//Draw the image in page rectangle clip bounds
pageGraphics.drawImage(image, const Rect.fromLTWH(150, 50, 200, 200));
//Restore the graphics state
pageGraphics.restore(state);
//Save PDF document
final List<int> bytes = document.save(); |