12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import 'dart:ui' as ui;
- import 'package:flutter/services.dart';
- import 'cpdf_document_error.dart';
- /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
- ///
- /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
- /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
- /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
- /// This notice may not be removed from this file.
- class CPDFDocument {
- int _viewId = 0;
- late final MethodChannel _methodChannel;
- CPDFDocument(this._viewId) {
- _methodChannel =
- MethodChannel('com.compdfkit.flutter.pdfviewer.document.$_viewId');
- }
- CPDFDocument.create() : this(1000);
- Future<PDFDocumentError> open(String document, {String password = ''}) async {
- int errorCode = await _methodChannel.invokeMethod('openPDF',{
- 'document' : document,
- 'password' : password
- });
- return PDFDocumentError.values.firstWhere((element) => element.index == errorCode);
- }
- /// Get the number of pages in a pdf file
- Future<int> getPageCount() async {
- return await _methodChannel.invokeMethod('getPageCount');
- }
- /// Get the page size of the specified page number in the pdf file
- Future<List<double>> getPageSize(int pageIndex) async {
- Map<dynamic, dynamic> map =
- await _methodChannel.invokeMethod('getPageSize', pageIndex);
- return Future(() => [map['width'], map['height']]);
- }
- /// Render the page with the specified page number and return the image
- Future<Uint8List> renderPageAtIndex(
- int pageIndex, int width, int height) async {
- Uint8List imageData = await _methodChannel.invokeMethod('renderPageAtIndex',
- {'pageIndex': pageIndex, 'width': width, 'height': height});
- return imageData;
- }
- }
|