pdf_document 1.3.2 copy "pdf_document: ^1.3.2" to clipboard
pdf_document: ^1.3.2 copied to clipboard

Document-level PDF semantics: page tree, annotations, AcroForm filling, digital signatures, and an incremental-save editor. Pure Dart, web-ready.

example/main.dart

import 'dart:typed_data';

import 'package:pdf_document/pdf_document.dart';

void main() {
  final document = PdfDocument.open(_minimalPdf());
  final page = document.page(0);

  print('Pages: ${document.pageCount}');
  print('First page size: ${page.mediaBox.width} x ${page.mediaBox.height}');
}

Uint8List _minimalPdf() {
  const objects = [
    '<< /Type /Catalog /Pages 2 0 R >>',
    '<< /Type /Pages /Kids [3 0 R] /Count 1 >>',
    '<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] >>',
  ];
  final buffer = StringBuffer('%PDF-1.4\n');
  final offsets = <int>[];
  for (var i = 0; i < objects.length; i++) {
    offsets.add(buffer.length);
    buffer.write('${i + 1} 0 obj\n${objects[i]}\nendobj\n');
  }
  final xrefOffset = buffer.length;
  buffer
    ..write('xref\n0 ${objects.length + 1}\n')
    ..write('0000000000 65535 f \n');
  for (final offset in offsets) {
    buffer.write('${offset.toString().padLeft(10, '0')} 00000 n \n');
  }
  buffer
    ..write('trailer\n<< /Size ${objects.length + 1} /Root 1 0 R >>\n')
    ..write('startxref\n$xrefOffset\n%%EOF\n');
  return Uint8List.fromList(buffer.toString().codeUnits);
}
0
likes
160
points
3.28k
downloads

Documentation

API reference

Publisher

verified publisherbenmilanko.com

Weekly Downloads

Document-level PDF semantics: page tree, annotations, AcroForm filling, digital signatures, and an incremental-save editor. Pure Dart, web-ready.

Repository (GitHub)
View/report issues
Contributing

Topics

#pdf #annotations #form #digital-signatures

License

Apache-2.0 (license)

Dependencies

archive, crypto, pdf_cos

More

Packages that depend on pdf_document