pdfmakr 0.0.1+1

pdfmakr

A dart wrapper for PDFMake in browser - example

Usage

HTML

add pdfmake scripts file to your repo and your html page

<script src='js/pdfmake.min.js'></script>
<script src='js/vfs_fonts.js'></script>

Dart

Future downloadPdf() async {
  final pdfFile = await pdf.createPdf(new pdf.PDFContent(
      content: [
        new pdf.Image(image: await loadImg64("img/rx.png")),
        new pdf.TextBloc(text: "text example", bold: true, color: 'blue'),
        new pdf.TextBloc(text: "text example with style", style: 'header'),
        new pdf.TextBloc(text: " "),
        new pdf.Columns(columns: [
          new pdf.Column(text: 'col 1 80%', width: '80%'),
          new pdf.Column(text: 'col 2'),
        ]),
        new pdf.TextBloc(text: " "),
        new pdf.Table(
            table: new pdf.TableBody(body: [
          [
            new pdf.TextBloc(text: "cell example 1", bold: true, color: 'blue'),
            new pdf.TextBloc(
                text: "cell example - col 2",
                bold: true,
                color: 'green',
                fillColor: 'yellow'),
          ],
          [
            new pdf.TextBloc(text: "bold row 2 - col 1", bold: true),
            new pdf.TextBloc(text: "italic row 2 - col 2", italics: true),
          ]
        ]))
      ],
      styles: new pdf.Styles(
          header: new pdf.Style(color: 'red', fontSize: 24),
          basic: new pdf.Style(color: 'green'))));

  pdfFile.download();
  //pdfFile.print();
  //pdfFile.open();
}

Future<String> loadImg64(String url) async {
  HttpRequest response =
      await HttpRequest.request(url, responseType: "arraybuffer");

  String contentType = response.getResponseHeader('Content-Type');

  var list = new Uint8List.view((response.response as ByteBuffer));

  String header = 'data:$contentType;base64,';
  String base64 = BASE64.encode(list);
  String image = "${header}${base64}";

  return image;
}

Example

works with DDC

cd example
pub get
pub serve

# open in chrome

Features / Todos

  • [x] createPdf

  • Content types

    • [x] text
    • [ ] image :
      • [x] url
      • [ ] size
    • [ ] Columns
      • [x] text, width
      • [ ] multitype columns content
    • [ ] Table
      • [x] body
      • [ ] more ?
  • [x] Styles dictionaries ( user needs implements its own class )

  • [x] pdf.download()

  • [x] pdf.open()

  • [x] pdf.print()

  • dart-ier api : cascade ?

  • lists : ul, ol

  • headers, footers

  • background layer

  • margins

  • text decorations

  • paragraphs

  • image sizes

  • pageBreak

  • page dimensions, orientation and margins

  • more internal properties

  • browser preview */

Changelog

0.0.1

  • createPdf(PDFContent)
  • Content types
    • text : size, color, bold, italic
    • Image : url
    • basic text Columns
    • Table : body
  • Styles dictionaries ( implies implementing its own class )
  • pdfDoc.download(),pdfDoc.open(),pdfDoc.print()

1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  pdfmakr: "^0.0.1+1"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:pdfmakr/pdfmakr.dart';

Platforms

Web

About

A dart wrapper for http://pdfmake.org/ (browser only)

Author

rxlabz

Homepage

github.com/rxlabz/pdfmakr

Documentation

www.dartdocs.org/documentation/pdfmakr/0.0.1%2B1/

Uploader

rxlabz@gmail.com

License

BSD (LICENSE)

Published

Sep 13, 2017