dart_pdf icon indicating copy to clipboard operation
dart_pdf copied to clipboard

How to resize a PDF after drawing it

Open shinxxxxwon opened this issue 8 months ago • 0 comments

I changed the value of .a4 to match the coordinate system for drawing sheet music on PDF.

static const PdfPageFormat a4 = PdfPageFormat(2480, 3508);

Below is a simple test code.

scorePdf.addPage(
          pdfWidget.Page(
              pageFormat: PdfPageFormat.a4, ///2480 * 3508
              build: (pdfWidget.Context pContext){
                return pdfWidget.Stack(
                  children: [

                    ///test code
                    for(int i=0; i<5; i++)
                        pdfWidget.Positioned(
                          top: (2900 + (100 * i)).toDouble(),
                          left: 200,
                          child: pdfWidget.Text(
                              "AKBO TEST CODE",
                              style: const pdfWidget.TextStyle(
                                  color: PdfColor.fromInt(0xFFFFFFFF)
                              )
                          ),
                        ),

Now create a pdf with that data.

Uint8List uintData = await scorePdf.save();
await drawScore.makePDF(uintData);

 makePDF(Uint8List doc) async {
    final dir = await getTemporaryDirectory();
    String dirPath = dir!.path + '/score.pdf';
    File pdf = File('$dirPath');
    await pdf.writeAsBytes(doc);
    print('make PDF done');
  }

If you proceed with the above process, a PDF will be created, but the size of the PDF will be 2048 * 3508. Is there a way to readjust this size? However, the sheet music in the pdf must not be truncated.

shinxxxxwon avatar Jun 26 '24 05:06 shinxxxxwon