PDF Not Generated With Android WebView

102 Views Asked by At

I've developed an application using ColdFusion 9.0. Then I converted the app to android app using WebView. There is is process where I used to generate the PDF document and attach to Email using and tags.

My CF Code:

<cfdocument format="PDF" name="Alert">
<cfoutput query="getProdData" group="LineName">
<cfdocumentitem type="header">
<font size="-1"><i>Production Report - #dateFormat(ListFirst(form.prodDate),"dd-mm-yyyy")#</i></font>
<font size="-1"><i>From #ListFirst(form.fromTime)# To #ListFirst(form.toTime)#</i></font>
</cfdocumentitem>
<cfdocumentitem type="footer">
<font size="-1">Page #cfdocument.currentpagenumber#</font>
</cfdocumentitem>

<!--- Some Code --->
</cfdocument>

<cfmail to="[email protected]" 
bcc="[email protected]"
from="[email protected]"  
subject="Alert Message - Production Less Than 40%">
<cfmailparam file="Alert.pdf" content="#Alert#">  
Mail Body
</cfmail>

My MainActivity.Java Code

package com.example.rms;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private WebView mywebView;

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mywebView=(WebView) findViewById(R.id.webview);
        mywebView.setWebChromeClient(new WebChromeClient());
        mywebView.setWebViewClient(new WebViewClient());
        mywebView.getSettings().setJavaScriptEnabled(true);

        if (!DetectConnection.checkInternetConnection(this)) {
            Toast.makeText(getApplicationContext(),"No Internet Connection.",Toast.LENGTH_LONG).show();
            finish();
        } else {
            mywebView.loadUrl("http://IPADDRESS:8500/RescrMobile/");
        }
    }
    public class mywebClient extends WebViewClient{
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon){
            super.onPageStarted(view,url,favicon);
        }
        @Override
        public boolean shouldOverrideUrlLoading(WebView view,String url){
            view.loadUrl(url);
            return true;
        }
    }
    @Override
    public void onBackPressed(){
        if(mywebView.canGoBack()) {
            mywebView.goBack();
        }
        else{
            super.onBackPressed();
        }
    }
}

I Do not want to view the PDF. Just generate the PDF using the CF code and send the mail as attachment. But, unfortunately its not happening. I've tested it by sending an email without Generated PDF attachment and attached some static file, the EMAIL is sent. So I think the issue is with the , and are working fine.

PLEASE HELP

0

There are 0 best solutions below