# Introduction to Conversion SDK Flutter

ComPDFKit Conversion SDK for Flutter is a powerful conversion library. Developers can seamlessly integrate PDF documents to Office documents conversion SDK into their applications and services running.

## Overview

### Key Features
* Convert PDF documents to Word documents.
    * Reconstruct content from PDF files into reusable data.
    * Reconstruction (recover page layout, columns, formatting, graphics, and preserve text flow).
    * Support mapping conversion to split-column function.
    * Support the function of combining letters into a string of text.
    * Support floating insertion such as picture rotation cutting.
    * Support converting partial Math or Chemistry function.
    * Support font size, color, bold, italic, and underline recognition.
    * Support two layout options to choose from: Retain Flowing Text and Retain Page Layout.
* Convert PDF documents to Excel documents.
    * Support data mapping to Excel cells.
    * Support recognition of a small number, currency, and other formats.
    * Support multiple cells merge function.
    * Support different types of content, including text, table, or all content in PDF.
    * Support multiple Worksheet options, including converting one table to one sheet, all tables on one page to one sheet, or all tables in the entire document to one sheet.
* Convert PDF documents to PPT documents.
    * Convert each page to an editable slide.
    * Support converting text to a PowerPoint text box.
    * Support picture rotation cutting and other floating insertion.
    * Support converting partial Math or Chemistry function.
* Convert PDF documents to TXT documents.
* Convert PDF documents to CSV documents.
    * Support extracting only tables from PDF accurately and converting them to CSV, and one table is converted to one CSV file. Or you can also merge multiple tables into one CSV file.
* Convert PDF documents to Image documents.
    * Support converting PDF to high-quality image formats, including PNG and JPEG. All image quality and resolution will remain intact. And the image DPI can be set freely.
* Convert PDF documents to RTF documents.
    * Support converting PDF to Rich Text Format documents, including text and images.
* Convert PDF documents to HTML documents.
    * Support converting PDF to HTML, including single-page and multiple-page.

More information can be found at [https://www.compdf.com/guides/conversion-sdk/android/overview](https://www.compdf.com/guides/conversion-sdk/android/overview)


## Installation
1. First follow the Flutter getting started guides to [Install](https://docs.flutter.dev/get-started/install), [set up an editor](https://docs.flutter.dev/get-started/editor), and [Create a Flutter Project.](https://docs.flutter.dev/get-started/test-drive?tab=terminal#create-app)  The rest of this guide assumes your project is created by running `flutter create myapp.`

2. Add the following dependency to your Flutter project in `myapp/pubspec.yaml` file:

* If you want to use our null safe package from pub.dev:
```diff
dependencies:
    flutter:
      sdk: flutter
+   kmpdfkit_conversion_flutter:
```
3. Run the following command in the myapp directory to retrieve the dependencies:
```
flutter packages get
```


## Usage

1. Open `lib/main.dart`, and add the following code:

```diff
  @override
  void initState() {
    super.initState();
+   CPDFConverter.init("your ComPDFKit key","your ComPDFKit secret");
  }
```

2. To select a local PDF file, add the following dependencies to the `myapp/pubspec.yaml` file:

```diff
dependencies:
    flutter:
      sdk: flutter
    kmpdfkit_conversion_flutter:
+   file_picker: ^5.2.5
+   permission_handler: ^10.2.0
```

3. After obtaining the storage permission, use the `FilePicker` plugin to select the PDF file that needs to be converted:

```dart
  ///request storage permission
  Future<bool> getPermission() async {
    var status = await Permission.storage.request();
    return status.isGranted;
  }

  ///Select pdf files from android\ios using 'file_picker'
  Future<List<String>> getPDFFileList(BuildContext context) async {
    bool isGranted = await getPermission();
    if (!isGranted) {
      return List.empty();
    }
    FilePickerResult? result = await FilePicker.platform.pickFiles(
        type: FileType.custom, allowedExtensions: ['pdf'], allowMultiple: true);
    if (result != null) {
      List<String?> pdfFiles = result.paths;
      var files = pdfFiles.where((element) => element != null);
      return List.from(files);
    } else {
      return List.empty();
    }
  }
```

4. Convert file formats using the Conversion SDK:

```dart
  List<String> files = await getPDFFileList(context);

  CPDFConverter.convert(
        taskId: const Uuid().v4(),
        filePath: files.get(0),
        convertType: ConvertType.ppt,
        options: ConvertPPTOptions(),
        callback: (TaskResult result) {
          var taskId = result.taskId;
          var progress = result.progress;
          var taskStatus = result.taskStatus;
          var outPutPath = result.outPutPath;
        });
```

5. Cancel the conversion task:
```dart
  CPDFConverter.cancelTask();
```

## Changelog
See Changelog

## License
See License

