Skip to content

Instantly share code, notes, and snippets.

@tank777
Created June 25, 2017 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tank777/a99dabc8dbc899167d9c914bdfe45a28 to your computer and use it in GitHub Desktop.
Save tank777/a99dabc8dbc899167d9c914bdfe45a28 to your computer and use it in GitHub Desktop.
package com.qoppa.qpdf.samples;
import com.bta.android.pdfProcess.PDFCanvas;
import com.bta.android.pdfProcess.PDFDocument;
import com.bta.android.pdfProcess.PDFFontStandard;
import com.bta.android.pdfProcess.PDFFontStandard.PDFFontFamily;
import com.bta.android.pdfProcess.PDFPa
import com.bta.android.pdfProcess.PDFPaint;
import com.bta.android.pdfViewer.fonts.StandardFontTF;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Matrix;
import android.os.Bundle;
import android.util.Log;
public class CreatePDF extends Activity
{
public void onCreate(Bundle saveInstBundle)
{
super.onCreate(saveInstBundle);
try
{
//this static allows the sdk to access font assets,
//it must be set prior to utilizing libraries
StandardFontTF.mAssetMgr = getAssets();
//create a new document and append a page
PDFDocument pdf = new PDFDocument();
PDFPage page = pdf.appendNewPage(612, 792);
//the PDFCanvas object is used to draw to the page
PDFCanvas canvas = page.createCanvas();
//add some text
PDFFontStandard font = new PDFFontStandard(PDFFontFamily.HELVETICA, PDFFontStandard.Style.NORMAL, 22);
canvas.drawText("Some example text", Color.BLACK, 20, 20, font);
// Create paint object to draw shapes
PDFPaint paint = new PDFPaint();
paint.setStyle(PDFPaint.Style.STROKE);
paint.setStrokeWidth(1);
paint.setStrokeColor(Color.RED);
//draw a red rectangle
canvas.drawRect(40, 100, 120, 240, paint);
// Load a bitmap to draw to the page
Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
//the matrix is used to size and position the bitmap on the page
Matrix matrix = new Matrix();
matrix.preTranslate(300, 300);
matrix.preScale(2, 2);
//add an image to the page
canvas.drawBitmap(image, matrix, null);
//save the document
pdf.saveDocument("/sdcard/outdoc.pdf");
}
catch(Exception e)
{
Log.e("error", Log.getStackTraceString(e));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment