Creating a PDF File in Android Programmatically and Writing in It

Creating a pdf file in android programmatically and writing in it

So apparently the code I was using wasn't compatible with android, hence the error I was getting. Below you'll find the correct code that actually works right (for creating a pdf file, putting some content in it, saving in and the opening the newly created file):

PS: For this you'll need to add the jar of iTextG to your project:

// Method for creating a pdf file from text, saving it then opening it for display
public void createandDisplayPdf(String text) {

Document doc = new Document();

try {
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Dir";

File dir = new File(path);
if(!dir.exists())
dir.mkdirs();

File file = new File(dir, "newFile.pdf");
FileOutputStream fOut = new FileOutputStream(file);

PdfWriter.getInstance(doc, fOut);

//open the document
doc.open();

Paragraph p1 = new Paragraph(text);
Font paraFont= new Font(Font.COURIER);
p1.setAlignment(Paragraph.ALIGN_CENTER);
p1.setFont(paraFont);

//add paragraph to document
doc.add(p1);

} catch (DocumentException de) {
Log.e("PDFCreator", "DocumentException:" + de);
} catch (IOException e) {
Log.e("PDFCreator", "ioException:" + e);
}
finally {
doc.close();
}

viewPdf("newFile.pdf", "Dir");
}

// Method for opening a pdf file
private void viewPdf(String file, String directory) {

File pdfFile = new File(Environment.getExternalStorageDirectory() + "/" + directory + "/" + file);
Uri path = Uri.fromFile(pdfFile);

// Setting the intent for pdf reader
Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(path, "application/pdf");
pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

try {
startActivity(pdfIntent);
} catch (ActivityNotFoundException e) {
Toast.makeText(TableActivity.this, "Can't read pdf file", Toast.LENGTH_SHORT).show();
}
}

How to create a pdf programmatically from Android

You are using iText for Java, while you should use iTextG for Android and GoogleAppEngine. See http://itextgroup.com/product/itextg

In iText for Java you have dependencies on classes in the Java packages java.awt, javax.nio and so on. These classes are forbidden on Android and that explains why you get that error.

In iTextG, we removed all those classes, keeping most of the functionality intact.

Update: looking at your dependencies, I see 'com.itextpdf:itextg:5.5.9' which means you are already using iTextG. Nevertheless, you are using java.awt.Color somewhere and that is forbidden.

When I look at your error message, I see

dex file "/data/data/com.mcsolution.easymanagementandroid.easymanagementandroid/files/instant-run/dex/slice-lowagie-2.1.7

Lowagie, that's me, and you are using iText 2.1.7 (a library that should no longer be used) as well as iTextG (the library you need). You should check how you introduced that old iText version as it shouldn't be used on Android.

Solution:

  • Make sure that you don't import com.lowagie classes. Only import com.itextpdf classes. The general rule is: if you see my name in your code, you're doing something wrong.
  • Make sure you remove all references to iText 2.1.7. You shouldn't use two different versions of iText next to each other.
  • Make sure you don't introduce any of the forbidden classes (java.awt.*, javax.nio.*) in your code.

Unable to create PDF in Android 11(R)

Solution to create and display PDF in Android 11

Create @xml/provide_paths.xml in resource directory

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="external_files"
path="." />
<root-path
name="external_files"
path="/storage/" />
</paths>

Add this is Manifest.xml application tag

     <application
<--other properties-->
android:requestLegacyExternalStorage="true"
android:usesCleartextTraffic="true">

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>

Now create and display PDF

    String fileName1 = "";
Document document = new Document();
// Location to save
fileName1 = "TEST" + ".pdf";
String dest = context.getExternalFilesDir(null) + "/";

File dir = new File(dest);
if (!dir.exists())
dir.mkdirs();

try {
File file = new File(dest, fileName);
file.createNewFile();
FileOutputStream fOut = new FileOutputStream(file, false);
PdfWriter.getInstance(document, fOut);
} catch (DocumentException e) {
e.printStackTrace();
Log.v("PdfError", e.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.v("PdfError", e.toString());

} catch (IOException e) {
e.printStackTrace();
}

// Open to write
document.open();
document.add(new Paragraph(""));
document.add(new Chunk(""));
} catch (DocumentException e) {
e.printStackTrace();
}

document.close();

File pdfFile = new File(dest+"/"+fileName1);
if (!pdfFile.exists()) {
pdfFile.mkdir();
}

if (pdfFile != null && pdfFile.exists() ) //Checking for the file is exist or not
{

Intent intent = new Intent(Intent.ACTION_VIEW);

Uri mURI = FileProvider.getUriForFile(
context,
context.getApplicationContext()
.getPackageName() + ".provider", pdfFile);
intent.setDataAndType(mURI, "application/pdf");
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_GRANT_READ_URI_PERMISSION);

try {
context.startActivity(intent);
}
catch (Exception e) {
e.printStackTrace();
}
} else {

Toast.makeText(context, "The file not exists! ", Toast.LENGTH_SHORT).show();

}

This is how you can make PDF through iText library and can display it.

how to create pdf file with multiple pages from image file in android

Your search through StackOverflow is less I guess cause I found these answer already there having solution, yes its contained in different answer and looking at the Q/A I guess they can solve your problem, if not then keep trying :)

how to Generate Pdf File with Image in android?

How to create a PDF with multiple pages from a Graphics object with Java and itext

iText Example

How to generate a Pdf using PdfDocument from a long string with proper multiline and multipage in android?

This solution by which I solved the problem by using simple PdfDocument and StaticLayout without using any external paid libraries. The problem as I have shared in my question is that maintaining proper structure of the texts in the generated pdf file.

I used the length and width of a A4 size page and have fixed the number of characters in each page to a limit, after that when it encounters the end of that line it automatically creates next page, also auto next line is handled by StaticLayout no overflowing of text is seen.

If you feel you can try with different character limit for each page and try different size as your need. Also you can try the StaticLayout.Builder which is supported in Android version Q/29 and above not below it.

The code sample I will share with you, which if you use, no matter how long the text you have, it will automatically handle multi page if text is long and generate the pdf, also it maintains paragraphs etc, you can also customise page shape, number of characters etc according to your need. Other details in the code are self-explanatory.

 String text = "Lorem ipsum...very long text";
ArrayList<String> texts = new ArrayList<>();
int tot_char_count = 0;
//Counts total characters in the long text
for (int i = 0; i < text.length(); i++) {
tot_char_count++;
}
int per_page_words = 4900;
int pages = tot_char_count / per_page_words;
int remainder_pages_extra = tot_char_count % per_page_words;
if (remainder_pages_extra > 0) {
pages++;
}
int k = pages, count = 0;
while (k != 0) {
StringBuilder each_page_text = new StringBuilder();
for (int y = 0; y < per_page_words; y++) {
if (count < tot_char_count) {
each_page_text.append(text.charAt(count));
if (y == (per_page_words - 1) && text.charAt(count) != ' ') {
while (text.charAt(count) != '\n') {
count++;
each_page_text.append(text.charAt(count));
}
} else {
count++;
}
}
}
texts.add(each_page_text.toString());
k--;
}

PdfDocument pdfDocument = new PdfDocument();
int pageNumber = 0;
try {
pageNumber++;
for (String each_page_text : texts) {
PdfDocument.PageInfo mypageInfo = new PdfDocument.PageInfo.Builder(595, 842, pageNumber).create();
PdfDocument.Page myPage = pdfDocument.startPage(mypageInfo);
Canvas canvas = myPage.getCanvas();
TextPaint mTextPaint = new TextPaint();
mTextPaint.setTextSize(11);
mTextPaint.setTypeface(ResourcesCompat.getFont(context, R.font.roboto));
StaticLayout mTextLayout = new StaticLayout(each_page_text, mTextPaint, canvas.getWidth() - 60, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
canvas.save();
int textX = 30;
int textY = 30;
canvas.translate(textX, textY);
mTextLayout.draw(canvas);
canvas.restore();
pdfDocument.finishPage(myPage);
}
File file = new File(context.getFilesDir(), "GeneratedFile.pdf");
FileOutputStream fOut = new FileOutputStream(file);
pdfDocument.writeTo(fOut);
// Toast.makeText(context, "PDF file generated successfully.", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
pdfDocument.close();

Trying to create a PDF from a listview

After hours of Struggle I found my own answer in creating multiple pages in a single PDF using android also image annotating with text here is the following source code

import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;

public class DisplayPreview extends AppCompatActivity {

String TAG = DisplayPreview.class.getName();

ListView imagesLV;

FloatingActionButton fabPDF;

Bitmap anImage;

TextView tv_link;
ImageView iv_image;
LinearLayout ll_pdflayout;
public static int REQUEST_PERMISSIONS = 1;
boolean boolean_permission;
boolean boolean_save;
Bitmap bitmap;
ProgressDialog progressDialog;
ArrayList<String> selectedImagesList;
String targetPdf;

DisplayPreviewAdapter displayPreviewAdapter;
String familyStatus, userNameStr;

public static final Integer[] IMAGES = {
R.drawable.img_1,
R.drawable.img_2,
R.drawable.img_3,
R.drawable.img_4,
R.drawable.img_5,
R.drawable.img_6,
R.drawable.img_7
// ,R.drawable.img_8,
// R.drawable.img_9
};

private ProgressDialog pDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_preview);

Intent intent = getIntent();
selectedImagesList = intent.getStringArrayListExtra("selectedArray");
familyStatus = intent.getStringExtra("familyStatus");
userNameStr = intent.getStringExtra("userNameStr");

targetPdf = "mnt/sdcard/testing_2.pdf";

imagesLV = findViewById(R.id.imagesLV);

displayPreviewAdapter = new DisplayPreviewAdapter(this, selectedImagesList, IMAGES);
// imagesLV.setAdapter(displayPreviewAdapter);

fabPDF = findViewById(R.id.fabPDF);

Drawable myDrawable = getResources().getDrawable(R.drawable.img_1);
anImage = ((BitmapDrawable) myDrawable).getBitmap();

createMultiPagePDF();

fabPDF.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

if (boolean_save) {
Intent intent = new Intent(getApplicationContext(), PDFViewActivity.class);
intent.putExtra("pdfFile", targetPdf);
startActivity(intent);

} else {
if (boolean_permission) {
progressDialog = new ProgressDialog(DisplayPreview.this);
progressDialog.setMessage("Please wait");
// bitmap = loadBitmapFromView(imagesLV, imagesLV.getWidth(), imagesLV.getHeight());
bitmap = loadBitmapFromView(imagesLV, imagesLV.getWidth(), imagesLV.getHeight());
// makePDF();

createMultiplePDF();
} else {

}

createMultiplePDF();
// makePDF();
}
}
});

}

private void createMultiPagePDF() {

pDialog = new ProgressDialog(DisplayPreview.this);
pDialog.setMessage("Please wait...Creating Invitation");
pDialog.setCancelable(false);
pDialog.show();

new Handler().postDelayed(new Runnable() {

@Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity

if (boolean_save) {
Intent intent = new Intent(getApplicationContext(), PDFViewActivity.class);
intent.putExtra("pdfFile", targetPdf);
startActivity(intent);

} else {
if (boolean_permission) {
progressDialog = new ProgressDialog(DisplayPreview.this);
progressDialog.setMessage("Please wait");
// bitmap = loadBitmapFromView(imagesLV, imagesLV.getWidth(), imagesLV.getHeight());
bitmap = loadBitmapFromView(imagesLV, imagesLV.getWidth(), imagesLV.getHeight());
// makePDF();

createMultiplePDF();
} else {

}

createMultiplePDF();
// makePDF();
}
}
}, 4000);
}

public static Bitmap loadBitmapFromView(View v, int width, int height) {
Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.draw(c);
return b;
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_PERMISSIONS) {

if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

boolean_permission = true;

} else {
Toast.makeText(getApplicationContext(), "Please allow the permission", Toast.LENGTH_LONG).show();

}
}
}

public void createMultiplePDF() {

// targetPdf = "mnt/sdcard/testing_1.pdf";
targetPdf = "mnt/sdcard/" + userNameStr + ".pdf";
File filePath = new File(targetPdf);

// Document document = new Document();
Document document = new Document(PageSize.A4, 0, 0, 0, 0);
// step 2
PdfWriter writer = null;
try {
writer = PdfWriter.getInstance(document, new FileOutputStream(filePath));
} catch (DocumentException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// step 3
document.open();
// step 4
try {

Drawable myDrawable = null;

for (int i = 0; i < selectedImagesList.size(); i++) {
//

String imagePath = selectedImagesList.get(i).replaceAll("^\"|\"$", "");
Log.i(TAG, "Image Path is :: 271 :: " + imagePath);

// if (imagePath.equals("R.drawable.img_8")) {
if (imagePath.equals(userNameStr)) {

Bitmap processedBitmap = ProcessingBitmap();

ByteArrayOutputStream stream = new ByteArrayOutputStream();
processedBitmap.compress(Bitmap.CompressFormat.JPEG, 40, stream);
Image myImg = Image.getInstance(stream.toByteArray());

DisplayMetrics displaymetrics = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
float hight = (float) ((displaymetrics.heightPixels / 2) * (1.1));
float width = (float) ((displaymetrics.widthPixels / 2) * (1.6));

// myImg.scaleToFit(hight, width);
myImg.scaleToFit(PageSize.ARCH_A);
myImg.setAlignment(Image.ALIGN_CENTER);
document.add(myImg);
writer.setPageEmpty(false);

}
if (imagePath.equals("R.drawable.img_2")) {
myDrawable = getResources().getDrawable(R.drawable.img_2);

Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();

ByteArrayOutputStream stream = new ByteArrayOutputStream();
myLogo.compress(Bitmap.CompressFormat.JPEG, 40, stream);
Image myImg = Image.getInstance(stream.toByteArray());

DisplayMetrics displaymetrics = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
float hight = (float) ((displaymetrics.heightPixels / 2) * (1.1));
float width = (float) ((displaymetrics.widthPixels / 2) * (1.6));

// myImg.scaleToFit(hight, width);
myImg.scaleToFit(PageSize.ARCH_A);
myImg.setAlignment(Image.ALIGN_CENTER);
document.add(myImg);
writer.setPageEmpty(false);
}
if (imagePath.equals("R.drawable.img_3")) {
myDrawable = getResources().getDrawable(R.drawable.img_3);

Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();

ByteArrayOutputStream stream = new ByteArrayOutputStream();
myLogo.compress(Bitmap.CompressFormat.JPEG, 40, stream);
Image myImg = Image.getInstance(stream.toByteArray());

DisplayMetrics displaymetrics = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
float hight = (float) ((displaymetrics.heightPixels / 2) * (1.1));
float width = (float) ((displaymetrics.widthPixels / 2) * (1.6));

// myImg.scaleToFit(hight, width);
myImg.scaleToFit(PageSize.ARCH_A);
myImg.setAlignment(Image.ALIGN_CENTER);
document.add(myImg);
writer.setPageEmpty(false);
}
if (imagePath.equals("R.drawable.img_4")) {
myDrawable = getResources().getDrawable(R.drawable.img_4);

Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();

ByteArrayOutputStream stream = new ByteArrayOutputStream();
myLogo.compress(Bitmap.CompressFormat.JPEG, 40, stream);
Image myImg = Image.getInstance(stream.toByteArray());

DisplayMetrics displaymetrics = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
float hight = (float) ((displaymetrics.heightPixels / 2) * (1.1));
float width = (float) ((displaymetrics.widthPixels / 2) * (1.6));

// myImg.scaleToFit(hight, width);
myImg.scaleToFit(PageSize.ARCH_A);
myImg.setAlignment(Image.ALIGN_CENTER);
document.add(myImg);
writer.setPageEmpty(false);
}
if (imagePath.equals("R.drawable.img_5")) {
myDrawable = getResources().getDrawable(R.drawable.img_5);

Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();

ByteArrayOutputStream stream = new ByteArrayOutputStream();
myLogo.compress(Bitmap.CompressFormat.JPEG, 40, stream);
Image myImg = Image.getInstance(stream.toByteArray());

DisplayMetrics displaymetrics = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
float hight = (float) ((displaymetrics.heightPixels / 2) * (1.1));
float width = (float) ((displaymetrics.widthPixels / 2) * (1.6));

// myImg.scaleToFit(hight, width);
myImg.scaleToFit(PageSize.ARCH_A);
myImg.setAlignment(Image.ALIGN_CENTER);
document.add(myImg);
writer.setPageEmpty(false);
}
if (imagePath.equals("R.drawable.img_6")) {
myDrawable = getResources().getDrawable(R.drawable.img_6);

Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();

ByteArrayOutputStream stream = new ByteArrayOutputStream();
myLogo.compress(Bitmap.CompressFormat.JPEG, 40, stream);
Image myImg = Image.getInstance(stream.toByteArray());

DisplayMetrics displaymetrics = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
float hight = (float) ((displaymetrics.heightPixels / 2) * (1.1));
float width = (float) ((displaymetrics.widthPixels / 2) * (1.6));

// myImg.scaleToFit(hight, width);
myImg.scaleToFit(PageSize.ARCH_A);
myImg.setAlignment(Image.ALIGN_CENTER);
document.add(myImg);
writer.setPageEmpty(false);
}
if (imagePath.equals("R.drawable.img_7")) {
myDrawable = getResources().getDrawable(R.drawable.img_7);

Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();

ByteArrayOutputStream stream = new ByteArrayOutputStream();
myLogo.compress(Bitmap.CompressFormat.JPEG, 40, stream);
Image myImg = Image.getInstance(stream.toByteArray());

DisplayMetrics displaymetrics = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
float hight = (float) ((displaymetrics.heightPixels / 2) * (1.1));
float width = (float) ((displaymetrics.widthPixels / 2) * (1.6));

// myImg.scaleToFit(hight, width);
myImg.scaleToFit(PageSize.ARCH_A);
myImg.setAlignment(Image.ALIGN_CENTER);
document.add(myImg);
writer.setPageEmpty(false);
}
/* if (imagePath.equals("R.drawable.img_8")) {
myDrawable = getResources().getDrawable(R.drawable.img_8);

Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();

ByteArrayOutputStream stream = new ByteArrayOutputStream();
myLogo.compress(Bitmap.CompressFormat.JPEG, 40, stream);
Image myImg = Image.getInstance(stream.toByteArray());

DisplayMetrics displaymetrics = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
float hight = (float) ((displaymetrics.heightPixels / 2) * (1.1));
float width = (float) ((displaymetrics.widthPixels / 2) * (1.6));

// myImg.scaleToFit(hight, width);
myImg.scaleToFit(PageSize.ARCH_A);
myImg.setAlignment(Image.ALIGN_CENTER);
document.add(myImg);
writer.setPageEmpty(false);
} if (imagePath.equals("R.drawable.img_9")) {
myDrawable = getResources().getDrawable(R.drawable.img_9);

Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();

ByteArrayOutputStream stream = new ByteArrayOutputStream();
myLogo.compress(Bitmap.CompressFormat.JPEG, 40, stream);
Image myImg = Image.getInstance(stream.toByteArray());

DisplayMetrics displaymetrics = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
float hight = (float) ((displaymetrics.heightPixels / 2) * (1.1));
float width = (float) ((displaymetrics.widthPixels / 2) * (1.6));

// myImg.scaleToFit(hight, width);
myImg.scaleToFit(PageSize.ARCH_A);
myImg.setAlignment(Image.ALIGN_CENTER);
document.add(myImg);
writer.setPageEmpty(false);
}*/

}
document.close();

pDialog.dismiss();

Intent intent = new Intent(getApplicationContext(), PDFViewActivity.class);
intent.putExtra("pdfFile", targetPdf);
startActivity(intent);
finish();
} catch (DocumentException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

@SuppressLint("ResourceAsColor")
private Bitmap ProcessingBitmap() {

Resources resources = DisplayPreview.this.getResources();
float scale = resources.getDisplayMetrics().density;

Bitmap bm1 = BitmapFactory.decodeResource(getResources(), R.drawable.img_1);

Bitmap.Config config = bm1.getConfig();
if (config == null) {
config = Bitmap.Config.ARGB_8888;
}

// newBitmap = Bitmap.createBitmap(bm1.getWidth(), bm1.getHeight(), config);
anImage = Bitmap.createBitmap(bm1.getWidth(), bm1.getHeight(), config);
// Canvas newCanvas = new Canvas(newBitmap);
Canvas newCanvas = new Canvas(anImage);

newCanvas.drawBitmap(bm1, 0, 0, null);

String captionString = userNameStr.trim();
if (captionString != null) {

TextPaint paintText = new TextPaint(Paint.ANTI_ALIAS_FLAG);
paintText.setColor(R.color.wedding_guest_name);
paintText.setTextSize(100);
paintText.setStyle(Paint.Style.FILL_AND_STROKE);
paintText.setTextAlign(Paint.Align.CENTER);


Related Topics



Leave a reply



Submit