@@ -45,22 +45,23 @@ public static synchronized PdfConverter getInstance() {
45
45
46
46
@ Override
47
47
public void run () {
48
- if (mContext == null || mHtmlString == null || mPdfFile == null ) return ;
49
-
50
48
mWebView = new WebView (mContext );
51
49
mWebView .setWebViewClient (new WebViewClient () {
52
50
@ Override
53
51
public void onPageFinished (WebView view , String url ) {
54
- if (Build .VERSION .SDK_INT < Build .VERSION_CODES .KITKAT ) return ;
55
-
56
- PrintDocumentAdapter documentAdapter = mWebView .createPrintDocumentAdapter ();
57
- documentAdapter .onLayout (null , getPdfPrintAttrs (), null , new PrintDocumentAdapter .LayoutResultCallback () {}, null );
58
- documentAdapter .onWrite (new PageRange []{PageRange .ALL_PAGES }, getOutputFileDescriptor (), null , new PrintDocumentAdapter .WriteResultCallback () {
59
- @ Override
60
- public void onWriteFinished (PageRange [] pages ) {
61
- destroy ();
62
- }
63
- });
52
+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .KITKAT )
53
+ throw new RuntimeException ("call requires API level 19" );
54
+ else {
55
+ PrintDocumentAdapter documentAdapter = mWebView .createPrintDocumentAdapter ();
56
+ documentAdapter .onLayout (null , getPdfPrintAttrs (), null , new PrintDocumentAdapter .LayoutResultCallback () {
57
+ }, null );
58
+ documentAdapter .onWrite (new PageRange []{PageRange .ALL_PAGES }, getOutputFileDescriptor (), null , new PrintDocumentAdapter .WriteResultCallback () {
59
+ @ Override
60
+ public void onWriteFinished (PageRange [] pages ) {
61
+ destroy ();
62
+ }
63
+ });
64
+ }
64
65
}
65
66
});
66
67
mWebView .loadData (mHtmlString , "text/HTML" , "UTF-8" );
@@ -75,6 +76,13 @@ public void setPdfPrintAttrs(PrintAttributes printAttrs) {
75
76
}
76
77
77
78
public void convert (Context context , String htmlString , File file ) {
79
+ if (context == null )
80
+ throw new IllegalArgumentException ("context can't be null" );
81
+ if (htmlString == null )
82
+ throw new IllegalArgumentException ("htmlString can't be null" );
83
+ if (file == null )
84
+ throw new IllegalArgumentException ("file can't be null" );
85
+
78
86
if (mIsCurrentlyConverting )
79
87
return ;
80
88
0 commit comments