@@ -67,51 +67,54 @@ - (instancetype)initWithFrame:(CGRect)frame
67
67
NSInteger defaultPage = [args[@" defaultPage" ] integerValue ];
68
68
69
69
NSString * filePath = args[@" filePath" ];
70
+ FlutterStandardTypedData* pdfData = args[@" pdfData" ];
70
71
72
+ PDFDocument * document;
71
73
if ([filePath isKindOfClass: [NSString class ]]) {
72
- NSURL * sourcePDFUrl = [NSURL fileURLWithPath: filePath];
73
- PDFDocument * document = [[PDFDocument alloc ] initWithURL: sourcePDFUrl];
74
+ NSURL * sourcePDFUrl = [NSURL fileURLWithPath: filePath];
75
+ document = [[PDFDocument alloc ] initWithURL: sourcePDFUrl];
76
+ } else if ([pdfData isKindOfClass: [FlutterStandardTypedData class ]]) {
77
+ NSData * sourcePDFdata = [pdfData data ];
78
+ document = [[PDFDocument alloc ] initWithData: sourcePDFdata];
79
+ }
74
80
75
- if (document == nil ) {
76
- [_channel invokeMethod: @" onError" arguments: @{@" error" : @" cannot create document: File not in PDF format or corrupted." }];
81
+ if (document == nil ) {
82
+ [_channel invokeMethod: @" onError" arguments: @{@" error" : @" cannot create document: File not in PDF format or corrupted." }];
83
+ } else {
84
+ _pdfView.autoresizesSubviews = YES ;
85
+ _pdfView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
86
+ _pdfView.backgroundColor = [UIColor colorWithWhite: 0.95 alpha: 1.0 ];
87
+ BOOL swipeHorizontal = [args[@" swipeHorizontal" ] boolValue ];
88
+ if (swipeHorizontal) {
89
+ _pdfView.displayDirection = kPDFDisplayDirectionHorizontal ;
77
90
} else {
78
- _pdfView.autoresizesSubviews = YES ;
79
- _pdfView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
80
-
81
- _pdfView.backgroundColor = [UIColor colorWithWhite: 0.95 alpha: 1.0 ];
82
- BOOL swipeHorizontal = [args[@" swipeHorizontal" ] boolValue ];
83
- if (swipeHorizontal) {
84
- _pdfView.displayDirection = kPDFDisplayDirectionHorizontal ;
85
- } else {
86
- _pdfView.displayDirection = kPDFDisplayDirectionVertical ;
87
- }
91
+ _pdfView.displayDirection = kPDFDisplayDirectionVertical ;
92
+ }
88
93
89
- [_pdfView usePageViewController: pageFling withViewOptions: nil ];
90
- _pdfView.displayMode = enableSwipe ? kPDFDisplaySinglePageContinuous : kPDFDisplaySinglePage ;
91
- _pdfView.document = document;
92
- _pdfView.autoScales = autoSpacing;
93
-
94
- NSString * password = args[@" password" ];
95
- if ([password isKindOfClass: [NSString class ]] && [_pdfView.document isEncrypted ]) {
96
- [_pdfView.document unlockWithPassword: password];
97
- }
94
+ [_pdfView usePageViewController: pageFling withViewOptions: nil ];
95
+ _pdfView.displayMode = enableSwipe ? kPDFDisplaySinglePageContinuous : kPDFDisplaySinglePage ;
96
+ _pdfView.document = document;
97
+ _pdfView.autoScales = autoSpacing;
98
+ NSString * password = args[@" password" ];
99
+ if ([password isKindOfClass: [NSString class ]] && [_pdfView.document isEncrypted ]) {
100
+ [_pdfView.document unlockWithPassword: password];
101
+ }
98
102
99
- NSUInteger pageCount = [document pageCount ];
103
+ NSUInteger pageCount = [document pageCount ];
100
104
101
- if (pageCount <= defaultPage) {
102
- defaultPage = pageCount - 1 ;
103
- }
105
+ if (pageCount <= defaultPage) {
106
+ defaultPage = pageCount - 1 ;
107
+ }
104
108
105
- PDFPage * page = [document pageAtIndex: defaultPage];
106
- [_pdfView goToPage: page];
109
+ PDFPage * page = [document pageAtIndex: defaultPage];
110
+ [_pdfView goToPage: page];
107
111
108
- _pdfView.minScaleFactor = _pdfView.scaleFactorForSizeToFit ;
109
- _pdfView.maxScaleFactor = 4.0 ;
112
+ _pdfView.minScaleFactor = _pdfView.scaleFactorForSizeToFit ;
113
+ _pdfView.maxScaleFactor = 4.0 ;
110
114
111
- dispatch_async (dispatch_get_main_queue (), ^{
112
- [weakSelf handleRenderCompleted: [NSNumber numberWithUnsignedLong: [document pageCount ]]];
113
- });
114
- }
115
+ dispatch_async (dispatch_get_main_queue (), ^{
116
+ [weakSelf handleRenderCompleted: [NSNumber numberWithUnsignedLong: [document pageCount ]]];
117
+ });
115
118
}
116
119
117
120
if (@available (iOS 11.0 , *)) {
0 commit comments