dox_pdf_me 0.0.2
dox_pdf_me: ^0.0.2 copied to clipboard
Make PDF files from pdfme templates in Dart. A port of the pdfme generator on top of dox_pdf_lib.
0.0.2 #
-
Breaking: a typed API. Each schema type has its own class with typed fields and the pdfme defaults:
TextSchema,BarcodeSchema(withBarcodeType.qrcode, ...),TableSchema, and so on. Fixed choices are enums (Alignment,VerticalAlignment,ObjectFit, ...). You can now build a template in Dart with no frontend.generatetakes aTemplate, not aMap. Read pdfme JSON withTemplate.fromJson(json)(both pdfme formats, like before).inputsis aList<Map<String, String>>. Every pdfme input is a string. A table takes a JSON string of rows: usejsonEncode(rows). A list or a map as input is no longer taken.optionsis aGenerateOptions. Read the pdfme options JSON withGenerateOptions.fromJson(json).colorTypeis aColorTypeenum, andextrais gone.Template.basePdfis aBasePdf:BlankPdf(width, height, padding, staticSchema)orPdfFile(bytes).- A plugin is a
SchemaPlugin<S>. It names its own schema class and reads it from JSON (fromJson), andpdfgets aRenderProps<S>with the typed schema.RenderProps.cacheis aRenderCache. - Plugin renames:
ShapePlugin.rectangle()isRectanglePlugin(),ShapePlugin.ellipse()isEllipsePlugin(),DatePlugin.date(),.time()and.dateTime()areDatePlugin(),TimePlugin()andDateTimePlugin(), andBarcodePlugin('qrcode')isBarcodePlugin(BarcodeType.qrcode). - Custom plugins: the old
Schemaclass, a wrapper of the JSON map with[],string(),number(),boolean()andcopyWith(Map), is gone.Schemais now the typed base class. Extend it and read your keys in afromJsonconstructor. The JSON-map wrapper is internal now. PdfLayout.oftakes the typedSchema(it took the old JSON-mapSchema).toJson()andfromJson()on every schema. A schema read from JSON keeps its map, sotoJson()gives the designer JSON back with no change, also keys this package does not know.
Before:
await generate( template: <String, dynamic>{ 'basePdf': <String, dynamic>{'width': 210, 'height': 297, 'padding': <int>[10, 10, 10, 10]}, 'schemas': <List<Map<String, dynamic>>>[ <Map<String, dynamic>>[ <String, dynamic>{'name': 'title', 'type': 'text', 'position': <String, num>{'x': 20, 'y': 20}, 'width': 170, 'height': 15}, ], ], }, inputs: <Map<String, dynamic>>[<String, dynamic>{'title': 'Hello'}], options: <String, dynamic>{'lang': 'en'}, );After:
await generate( template: Template( basePdf: const BlankPdf(), schemas: <List<Schema>>[ <Schema>[ const TextSchema(name: 'title', position: Position(20, 20), width: 170, height: 15), ], ], ), inputs: <Map<String, String>>[<String, String>{'title': 'Hello'}], options: GenerateOptions(lang: 'en'), ); // or, with the pdfme JSON: await generate( template: Template.fromJson(json), inputs: <Map<String, String>>[<String, String>{'title': 'Hello'}], options: GenerateOptions.fromJson(optionsJson), ); -
A deeply nested list as a table input could overflow the stack in
generate(it was turned into JSON there). Inputs are strings now, so this path is gone. -
New
tableschema type (TablePlugin, inbuiltInPluginsasTable). The value is a JSON string of rows. It has the props and defaults of pdfme: head, column widths, table, head, body and column styles. -
Tables grow like in pdfme: on a blank base PDF, a table taller than its box pushes the schemas below it down and goes on over new pages. The head can repeat on each page (
repeatHead). On a PDF base the table draws its full height and makes no new pages, like pdfme. -
Table image columns (
columnStyles.cellType: "image"): PNG and JPEG data URLs in the cells, withimageHeightMode(fixed,auto) andimageHeight, like pdfme. -
A table row with fewer cells than the head throws, like pdfme. A column without a width in
headWidthPercentagesthrows a clear error (pdfme fails on it too). -
New schema types, like in pdfme:
multiVariableText(a text with{name}variables, the input is a JSON object of values),signature(drawn like an image) andcircleMark(a circle line when the input is'true'). They are inbuiltInPlugins. -
PDF417 has the same modules as in pdfme. The
barcodepackage picked other columns, rows and codewords, so the code was wider and lower than in pdfme and did not fill a box made for it. Now a port of the bwip-js (BWIPP) encoder makes the symbol. -
2D codes (QR code, Data Matrix, PDF417) put their module edges on the same grid as bwip-js, so small codes look the same as in pdfme.
-
QR codes have the same modules as in pdfme. bwip-js raises the error correction level when the data still fits the same size, picks the mask with its own scores and mixes number, letter and byte segments (never kanji). The
barcodepackage did not, so the codes looked different. Now a port of the bwip-js (BWIPP) encoder makes the symbol. -
Barcode values that pass pdfme's check but that bwip-js refuses make
generatethrow aBarcodeInputExceptionwith the bwip-js message, like pdfme. Before, they drew a code or nothing. Eg. GS1 Data Matrix data that breaks the GS1 rules (unknown AI, too long, bad date or check digit, AIs that exclude or need each other), a UPC-E with a wrong check digit, Code 39 with white space other than a space, a lowercase NW-7 start or stop letter, too long Code 128, Japan Post or PDF417 data, and text with a lone UTF-16 surrogate (URI malformed). -
GS1 Data Matrix has the same modules and size as in pdfme. Letters now use C40, Text, X12 and EDIFACT like bwip-js, so a value with many letters is no longer one size bigger.
-
Code 128 has the same bars as in pdfme. The
barcodepackage started some texts (likeHELLOor12345) in another code set. Text with letters likeéworks now. -
The bearer box of ITF-14 is black, like in pdfme. It had the bar color.
-
UPC-E has the right check digit, like bwip-js: it comes from the UPC-A the code stands for. The
barcodepackage drew a wrong check digit (and bars) for about 1 in 15 codes, like0481683. -
Date formats: all date-fns tokens work, like
do(7th),PPP(May 7th, 2024),Q,wandB. Other tokens made the format fall back to the default format.iiiigives the full day name (it gaveTue). Seven or moreS(likess.SSSSSSS) madegeneratecrash. -
The crosscheck with pdfme compares every schema box on its own: the ink box (place and size) and the pixels, with tight limits per type, and the bars of linear barcodes. It has many new variants of every type.
0.0.1 #
- First version:
generate(template, inputs, options, plugins), a Dart port of the pdfme generator (pdfme 6.2.8). It reads pdfme template JSON. - Schema types: text, image, svg, line, rectangle, ellipse, qrcode, ean13, ean8, code39, code128, nw7, itf14, upca, upce, japanpost, gs1datamatrix, pdf417, date, time, dateTime, checkbox, radioGroup and select.
- Plugins: extend
SchemaPluginfor your own types.builtInPluginshas all types of this package. - Roboto is the default font, like in pdfme.
- Barcodes are drawn as vectors.
- Images with an EXIF orientation are turned like in pdfme.
- Thai, Lao, Khmer and Myanmar text breaks between words, like pdfme with
Intl.Segmenter(needsdictionaryWordBreaksof dox_pdf_lib 0.0.2).