hello i have created a flutter app and in that i m using this package to create a pdf https://pub.dev/packages/syncfusion_flutter_pdf
i didnt know to add a pdf here so i m attaching a drive link for downloading or viewing the pdf
the pdf or the format i want in my pdf is below u can download it from below link
https://drive.google.com/file/d/1WR1U7fYmBn9Pm1FyXdXfFxEvVhKTU3mw/view?usp=sharing
so far i have created the below pdf u can download it from below link
https://drive.google.com/file/d/1WyyEANBgmDy6RGR82ZgznW4IWhp41th2/view?usp=sharing
i m just trying to create or attach the format from this pdf https://drive.google.com/file/d/1WR1U7fYmBn9Pm1FyXdXfFxEvVhKTU3mw/view?usp=sharing
this is the code i tried to create pdf
Future<void> generateInvoice() async {
//Create a PDF document.
final PdfDocument document = PdfDocument();
//Add page to the PDF
final PdfPage page = document.pages.add();
//Get page client size
final Size pageSize = page.getClientSize();
//Generate PDF grid.
final PdfGrid grid = PdfGrid();
// //Add invoice footer
drawFooter(page, pageSize);
//Secify the columns count to the grid.
grid.columns.add(count: 6);
//Create the header row of the grid.
final PdfGridRow headerRow = grid.headers.add(1)[0];
//Set style
headerRow.style.backgroundBrush = PdfSolidBrush(PdfColor(68, 114, 196));
headerRow.style.textBrush = PdfBrushes.white;
headerRow.cells[0].value = 'Product Image';
headerRow.cells[1].value = 'Product Id';
headerRow.cells[1].stringFormat.alignment = PdfTextAlignment.center;
headerRow.cells[2].value = 'Product Name';
headerRow.cells[3].value = 'Metal';
headerRow.cells[4].value = 'Stone';
headerRow.cells[5].value = 'Quantity';
//Add rows
for(int i = 0; i < _totalItems; i++){
final PdfGridRow row = grid.rows.add();
var imageResponse1 = await get(Uri.parse(photoArray[i]));
row.cells[0].value = PdfBitmap(imageResponse1.bodyBytes.toList());
row.cells[1].value = array[i];
row.cells[2].value = nameArray[i];
row.cells[3].value = metalArray[i];
row.cells[4].value = stoneArray[i];
row.cells[5].value = '1';
grid.rows[i].height = 100;
}
grid.columns[2].width = 200;
for (int i = 0; i < headerRow.cells.count; i++) {
headerRow.cells[i].style.cellPadding =
PdfPaddings(bottom: 5, left: 5, right: 5, top: 5);
}
//Apply the table built-in style
grid.applyBuiltInStyle(PdfGridBuiltInStyle.listTable4Accent5);
grid.draw(
page: page,
bounds: Rect.fromLTWH(0, 0, page.getClientSize().width,
page.getClientSize().height));
//Save the PDF document
final List<int> bytes = document.save();
//Dispose the document.
document.dispose();
//Get external storage directory
Directory directory = (await getExternalStorageDirectory());
//Get directory path
String path = directory.path;
print(path);
//Create an empty file to write PDF data
File file = File('$path/Output.pdf');
//Write PDF data
await file.writeAsBytes(bytes, flush: true);
setState(() {
isApiCallProcess = false;
});
//Open the PDF document in mobile
OpenFile.open('$path/Output.pdf');
}
//Draw the invoice footer data.
void drawFooter(PdfPage page, Size pageSize) {
final PdfPen linePen =
PdfPen(PdfColor(142, 170, 219, 255), dashStyle: PdfDashStyle.custom);
linePen.dashPattern = <double>[3, 3];
//Draw line
page.graphics.drawLine(linePen, Offset(0, pageSize.height - 100),
Offset(pageSize.width, pageSize.height - 100));
const String footerContent =
// ignore: leading_newlines_in_multiline_strings
'''\r\n\r\nAny Questions? [email protected] Or 971529893336''';
//Added 30 as a margin for the layout
page.graphics.drawString(
footerContent, PdfStandardFont(PdfFontFamily.helvetica, 9),
format: PdfStringFormat(alignment: PdfTextAlignment.right),
bounds: Rect.fromLTWH(pageSize.width - 30, pageSize.height - 70, 0, 0));
}
basically in my app when a user click on the download button the data should get download in the format given in the first link.
i tried to create the format but it is a little difficult so please help me to solve this!
please help!!
Thanks in advance!!!!
update question
i tried something but i could not add the grid to the 3rd column and the quantity in footer is coming on first page only
here the pdf i tried
https://drive.google.com/file/d/1sw4cAu3D58ggUZTkI8GIJza06gUMs86E/view?usp=sharing
please help!!!