패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.4.1

flutter_to_pdf

모든 Flutter 위젯을 PDF 문서, PDF 페이지 또는 PDF 파일로 내보내는 패키지입니다. 내보내기 옵션을 통해 내보내기 프로세스를 추가로 사용자 지정할 수 있습니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
5.5천
좋아요
80
Pub 점수
150

패키지 설치

flutter pub add flutter_to_pdf

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

flutter_to_pdf는 어떤 Flutter 위젯도 PDF 문서, 페이지 또는 파일로 변환할 수 있게 해주는 Flutter 패키지입니다. 구성 가능한 옵션을 통해 내보내기 프로세스를 광범위하게 사용자 지정할 수 있어 보고서, 송장, 인쇄 가능한 콘텐츠 생성에 적합합니다. 이 패키지는 Android, iOS, Web, macOS, Windows, Linux 등 모든 주요 플랫폼에서 작동하여 타겟 환경에 관계없이 일관된 출력을 보장합니다.

사용 사례

  • 인쇄 가능한 보고서 생성
  • 송장 및 영수증 생성
  • 양식 및 문서 내보내기
  • 동적 UI에서 PDF 생성하기
  • Flutter로 생성된 콘텐츠를 PDF로 공유하기

주요 기능

  • 모든 Flutter 위젯을 PDF로 변환
  • 사용자 정의 가능한 내보내기 옵션
  • 크로스 플랫폼 지원
  • 다양한 출력 형식 지원
  • 고품질 렌더링
  • 기존 코드와의 간편한 통합

적합한 대상

  • 문서가 많은 앱을 개발하는 개발자
  • 인쇄 준비 출력이 필요한 앱
  • PDF 생성이 필요한 비즈니스 애플리케이션
  • 다운로드 가능한 콘텐츠가 포함된 교육 도구
  • 보고 기능을 갖춘 웹 및 모바일 앱

고려 사항

  • 복잡한 위젯에 따라 성능이 달라질 수 있습니다
  • 큰 PDF 파일은 메모리 사용량에 영향을 줄 수 있습니다
  • 글꼴과 이미지의 주의 깊은 처리가 필요합니다
  • 제한된 네이티브 PDF 편집 기능
  • 고급 레이아웃을 위해 추가 구성이 필요할 수 있습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

codecov Pub

The FlutterToPDF package lets you export any Flutter widget to PDF Documents and is written natively in Dart.

Installing

Depend on it

Run this command:

$ flutter pub add flutter_to_pdf

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  flutter_to_pdf: ^0.4.1

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

Import it

Now in your Dart code, you can use:

import 'package:flutter_to_pdf/flutter_to_pdf.dart';

Features

  • export to PDF Document
  • export to PDF Page
  • export to PDF Widget
  • export with options
    • Page format options
    • Text field options
    • Checkbox options

Usage

Create an instance of the ExportDelegate, wrap your widget with a ExportFrame widget and provide a frameId, as well as the exportDelegate.

When you want to export the widget call the desired export function (either exportToPdfDocument, exportToPdfPage or exportToPdfWidget) and pass in the frameId.

// create instance of ExportDelegate
final ExportDelegate exportDelegate = ExportDelegate();

ExportFrame(
  frameId: 'someFrameId',
  exportDelegate: exportDelegate,
  child: SomeWidget(), // the widget you want to export
)

// export the frame to a PDF Document
final pdf = await exportDelegate.exportToPdfDocument('someFrameId');

// export the frame to a PDF Page
final page = await exportDelegate.exportToPdfPage('someFrameId');

// export the frame to a PDF Widget
final widget = await exportDelegate.exportToPdfWidget('someFrameId');

Note: If you wish to use types on the variables pdf, page and widget, you can use the Document, Page and Widget classes provided by PDF-package.

Custom TTF Fonts

If the widget you want to export contains any custom TTF fonts, you must provide the used ttfFonts to the ExportDelegate.

final ExportDelegate exportDelegate = ExportDelegate(
  ttfFonts: {
    'SomeFontFamily': 'assets/fonts/someFont.ttf',
  },
);
TextFields and Checkboxes

If the widget you want to export contains any TextField, TextFormField or Checkbox, a unique Key must be provided to each TextField, TextFormField and Checkbox.

TextField(
  key: Key('someUniqueTextFieldKey'),
  controller: TextEditingController(),
  ...
)

Checkbox(
  key: Key('someUniqueCheckboxKey'),
  value: false,
  ...
)
Other widgets like CustomPaint and Charts

If the widget you want to export contains any custom widgets like CustomPaint or Charts, the widgets you want to export must be wrapped in a CaptureWrapper widget. Furthermore, the CaptureWrapper must have a unique Key. These widgets will then be captured as an image and exported to the PDF Document.

CaptureWrapper(
  key: const Key('someUniqueCustomPaintKey'),
  child: CustomPaint(
    size: const Size(300, 300),
    painter: SomePainter(),
  ),
)

Export Options

The ExportDelegate´s constructor has a named optional parameter options which can be used to customize the export process.

final ExportOptions options = ExportOptions(
  pageFormatOptions: PageFormatOptions.a3(),
  textFieldOptions: TextFieldOptions.uniform(
    interactive: false,
  ),
  checkboxOptions: CheckboxOptions.uniform(
    interactive: false,
  ),
);

final ExportDelegate exportDelegate = ExportDelegate(options: options);

The ExportDelegate´s options can also be overriden using the named optional parameter overrideOptions in the export function.

final ExportOptions options = ExportOptions(
  pageFormatOptions: PageFormatOptions.a3(),
  textFieldOptions: TextFieldOptions.uniform(
    interactive: false,
  ),
  checkboxOptions: CheckboxOptions.uniform(
    interactive: false,
  ),
);

final ExportDelegate exportDelegate = ExportDelegate(options: options);

final ExportOptions overrideOptions = ExportOptions(
  pageFormatOptions: PageFormatOptions.a4(),
  textFieldOptions: TextFieldOptions.uniform(
    interactive: true,
  ),
  checkboxOptions: CheckboxOptions.uniform(
    interactive: true,
  ),
);

// export the frame to a PDF Document, using the override options
final pdf = await exportDelegate.exportToPdfDocument('someFrameId', overrideOptions: overrideOptions);

// export the frame to a PDF Page, using the override options
final page = await exportDelegate.exportToPdfPage('someFrameId', overrideOptions: overrideOptions);

// export the frame to a PDF Widget, using the override options
final widget = await exportDelegate.exportToPdfWidget('someFrameId', overrideOptions: overrideOptions);
Page Format Options

The PageFormatOptions class can be used to customize the page format of the exported PDF Document.

All constructors have an optional parameter clip which can be used to define if the content of the page should be clipped to the page format. The default value is true.

For the PageFormatOptions class there are several predefined constructors available:

  • PageFormatOptions.a3 - A3 page format
  • PageFormatOptions.a4 - A4 page format
  • PageFormatOptions.a5 - A5 page format
  • PageFormatOptions.a6 - A6 page format
  • PageFormatOptions.letter - Letter page format
  • PageFormatOptions.legal - Legal page format
  • PageFormatOptions.roll57 - Roll57 page format
  • PageFormatOptions.roll80 - Roll80 page format
  • PageFormatOptions.custom - Custom page format

    The custom page format can be used to define a custom page format.
    It therefore requires at least the width parameter, and has the following optional parameters: height, marginTop, marginBottom, marginLeft, marginRight and marginAll.

Text Field Options

The TextFieldOptions class can be used to customize the text fields of the exported PDF Document.

All constructors have an optional parameter interactive which can be used to define if the text fields should be interactive. The default value is true. If interactive is set to false, the text fields will be rendered as Text.

For the TextFieldOptions class there are several predefined constructors available:

  • TextFieldOptions.uniform - Uniform text field options

    The uniform text field options can be used to define a uniform TextStyle for all text fields.
    It therefore has an optional parameter textstyle which can be used to define a custom TextStyle for all text fields.

  • TextFieldOptions.individual - Individual text field options

    The individual text field options can be used to define an individual TextStyle for each text field.
    It has an optional parameter styleMap which maps the textfield´s Key to a TextStyle.
    Note: The TextField therefore requires a Key to be able to map the TextStyle to the text field.

  • TextFieldOptions.none - No text field options

    The text fields will be interactive and will be styled as found in the widget tree.

Checkbox Options

The CheckboxOptions class can be used to customize the checkboxes of the exported PDF Document.

All constructors have an optional parameter interactive which can be used to define if the checkboxes should be interactive. The default value is true. If interactive is set to false, the checkboxes will be rendered as a Container and will not be clickable.

For the CheckboxOptions class there are several predefined constructors available:

  • CheckboxOptions.uniform - Uniform checkbox options

    The uniform checkbox options can be used to define a uniform BoxDecoration for all checkboxes.
    It therefore has an optional parameter boxDecoration which can be used to define a custom BoxDecoration for all checkboxes.

  • CheckboxOptions.individual - Individual checkbox options

    The individual checkbox options can be used to define an individual BoxDecoration for each checkbox.
    It has an optional parameter decorationMap which maps the checkbox´s Key to a BoxDecoration.
    Note: The Checkbox therefore requires a Key to be able to map the BoxDecoration to the checkbox.

  • CheckboxOptions.none - No checkbox options

    The checkboxes will be interactive and will be styled as found in the widget tree.

카테고리

의존성

의존성 목록 1 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.