@@ -45,22 +45,23 @@ public static synchronized PdfConverter getInstance() {
4545
4646 @ Override
4747 public void run () {
48- if (mContext == null || mHtmlString == null || mPdfFile == null ) return ;
49-
5048 mWebView = new WebView (mContext );
5149 mWebView .setWebViewClient (new WebViewClient () {
5250 @ Override
5351 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+ }
6465 }
6566 });
6667 mWebView .loadData (mHtmlString , "text/HTML" , "UTF-8" );
@@ -75,6 +76,13 @@ public void setPdfPrintAttrs(PrintAttributes printAttrs) {
7576 }
7677
7778 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+
7886 if (mIsCurrentlyConverting )
7987 return ;
8088
0 commit comments