import 'dart:io';

import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';

class PdfController extends GetxController {
  var localPdfPath = Rx<String?>(null);

  // 加载 PDF 文件
  Future<void> loadPdf() async {
    final byteData = await rootBundle.load('assets/img/test.pdf');
    final tempDir = await getTemporaryDirectory();
    
    // 使用 path 包拼接路径
    final filePath = p.join(tempDir.path, 'test.pdf');
    final file = File(filePath);

    // 保存文件到临时目录
    await file.writeAsBytes(byteData.buffer.asUint8List());
    localPdfPath.value = filePath;  // 更新 PDF 路径
  }
}
