extract_pdf_page 0.0.5 copy "extract_pdf_page: ^0.0.5" to clipboard
extract_pdf_page: ^0.0.5 copied to clipboard

A flutter project extact pdf to pages

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:extract_pdf_page/extract_pdf_page.dart';
import 'package:http/http.dart' as http;
import 'package:path_provider/path_provider.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<String> result = List.empty(growable: true);
  final _extractPdfPagePlugin = ExtractPdfPage();

  @override
  void initState() {
    super.initState();
    downloadAndSaveFile();
    initPlatformState();
  }

  Future<void> downloadAndSaveFile() async {
    // Link tải file
    const String fileUrl =
        'https://han01.vstorage.vngcloud.vn/v1/AUTH_f42e8dc502e04ee5b4ff28982239069a/test-1-container/s3_5d4e1e1a-35ac-4e4d-9d36-61e5d3945688.pdf';

    // Lấy thư mục tạm thời
    final Directory tempDir = await getTemporaryDirectory();
    final String filePath = '${tempDir.path}/conversation-game.pdf';

    try {
      // Tải file
      final http.Response response = await http.get(Uri.parse(fileUrl));

      if (response.statusCode == 200) {
        // Lưu file vào thư mục tạm thời
        final File file = File(filePath);
        await file.writeAsBytes(response.bodyBytes);
        print('File đã được lưu tại: $filePath');
        try {
          final listResult =
              await _extractPdfPagePlugin.extractPagesPDF(filePath, "123");
          print('LucTV -- List success : ${listResult.length}');
        } on PlatformException {
          print('LucTV -- List error :');
          result = List.empty();
        }
      } else {
        print('Lỗi tải file: ${response.statusCode}');
      }
    } catch (e) {
      print('Lỗi: $e');
    }
  }

  Future<void> initPlatformState() async {
    List<String> listResult;
    try {
      listResult =
          await _extractPdfPagePlugin.extractPagesPDF("inputUrl", "123");
    } on PlatformException {
      result = List.empty();
    }

    if (!mounted) return;

    setState(() {
      // result.addAll(listResult);
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Running on: ${result.length}\n'),
        ),
      ),
    );
  }
}
0
likes
145
points
13
downloads

Publisher

unverified uploader

Weekly Downloads

A flutter project extact pdf to pages

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, path_provider, plugin_platform_interface

More

Packages that depend on extract_pdf_page

Packages that implement extract_pdf_page