public void pdfcreates()
{
page = new AbstractViewRenderer(getApplicationContext(), R.layout.viewpd) {
private String _text;
public void setText(String text) {
_text = text;
}
@Override
protected void initView(View view) {
TextView tv_hello = (TextView)view.findViewById(R.id.pdfamount);
ImageView imageView = (ImageView)view.findViewById(R.id.img_logo);
TextView receiversname = (TextView)view.findViewById(R.id.pdfreceiptcontent);
TextView pdfamount = (TextView)view.findViewById(R.id.pdfamount);
TextView pdfdate = (TextView)view.findViewById(R.id.pdfdate);
int phrase = Integer.parseInt(_Amount) ;
// Float num = new Float( phrase ) ;
// int dollars = (int)Math.floor( num ) ;
// int cent = (int)Math.floor( ( num - dollars ) * 100.0f ) ;
String s = " " + EnglishNumberToWords.convert( phrase ) ;
// + " and "
// + EnglishNumberToWords.convert( cent ) + " cents" ;
// imageView.setImageResource(R.drawable.logo_min);
// tv_hello.setText(s_name);
receiversname.setText(" Received with thanks from Mr./Ms./Mrs "+s_name+" a sum of Rs: "+ _Amount+" " +
"( " + s + ") Rupees only. By cash / Demand Draft No:- ............................. date : " +_datecurrent+
" towards pre-recruitment training program ");
pdfdate.setText(_datecurrent);
pdfamount.setText(_Amount);
}
};
runOnUiThread(new Runnable() {
public void run() {
doc1.addPage(page);
doc1.setRenderWidth(1500);
doc1.setRenderHeight(1000);
doc1.setOrientation(PdfDocument.A4_MODE.PORTRAIT);
// doc.setProgressTitle("CREATING".toString());
// doc.setProgressMessage("");
doc1.setFileName("file");
doc1.setInflateOnMainThread(false);
doc1.setListener(new PdfDocument.Callback() {
@Override
public void onComplete(File file) {
pdfviewer(file);
}
@Override
public void onError(Exception e) {
Toast.makeText(CourseActivity.this, "Err", Toast.LENGTH_SHORT).show();
Log.i(PdfDocument.TAG_PDF_MY_XML, "Error");
}
});
doc1.createPdf(CourseActivity.this);
}
});
}
public void pdfviewer(File files){
Uri file= Uri.fromFile(files);
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(file.toString()));
try
{ Intent i; i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(file,mimeType);
startActivity(i);
finish();
}
catch (ActivityNotFoundException e)
{ Toast.makeText(this, "No Application Available to view this file type", Toast.LENGTH_SHORT).show(); }
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:orientation="vertical"
android:paddingTop="40dp"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:layout_height="match_parent">
<LinearLayout
android:layout_marginTop="80dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="150dp">
<RelativeLayout
android:gravity="center"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent">
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:src="@drawable/logo_min"
android:id="@+id/img_logo" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="150dp">
<TextView
android:textSize="30sp"
android:text="Opp. Union Bank, Vazhuthacaud, "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txt_address"
android:textColor="#000000" />
<TextView
android:textSize="30sp"
android:textColor="#000000"
android:text="Thiruvananthapuram-14, Ph. +4712322050"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView5" />
<TextView
android:textSize="30sp"
android:textColor="#000000"
android:text=" | info@napt.in | www.napt.in"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView6" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_marginTop="45dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_marginRight="20dp"
android:layout_alignParentRight="true"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:textColor="#000000"
android:gravity="right"
android:textSize="30sp"
android:text="Date: "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView7"
android:layout_weight="1" />
<TextView
android:textColor="#000000"
android:textSize="30sp"
android:text=" "
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/pdfdate"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_marginTop="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:textColor="#000000"
android:textSize="35sp"
android:text="@string/register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView9"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<LinearLayout
android:layout_marginTop="50dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:textColor="#000000"
android:textSize="32sp"
android:text="Received with thanks from Mr./Ms./Mrs"
android:layout_width="match_parent"
android:layout_weight="4"
android:layout_height="wrap_content"
android:id="@+id/pdfreceiptcontent"
android:lineSpacingMultiplier="1.2"
/>
<LinearLayout
android:layout_marginTop="45dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
>
<TextView
android:textColor="#000000"
android:textSize="28sp"
android:gravity="end"
android:text="Signature"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/pdfsign"
android:layout_weight="2" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
compile 'com.itextpdf:itextg:5.5.10'