package com.qoppa.qpdf.samples; import java.io.FileOutputStream; import java.io.OutputStream; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.Bitmap.Config; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; import android.os.Bundle; import android.util.Log; import com.qoppa.android.pdfProcess.PDFCanvas; import com.qoppa.android.pdfProcess.PDFDocument; import com.qoppa.android.pdfProcess.PDFFontStandard; import com.qoppa.android.pdfProcess.PDFPage; import com.qoppa.android.pdfProcess.PDFPaint; import com.qoppa.android.pdfProcess.PDFFontStandard.PDFFontFamily; import com.qoppa.android.pdfViewer.fonts.StandardFontTF; /** * This sample demonstrates how to load a PDF document and then add * content to the first page, including text, a shape and an image. * */ public class RenderToBitmap 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(); // Load a document and get the first page PDFDocument pdf = new PDFDocument("/sdcard/input.pdf", null); PDFPage page = pdf.getPage(0); // Create a bitmap and canvas to draw the page into int width = (int)Math.ceil (page.getDisplayWidth()); int height = (int)Math.ceil(page.getDisplayHeight()); Bitmap bm = Bitmap.createBitmap(width, height, Config.ARGB_8888); // Create canvas to draw into the bitmap Canvas c = new Canvas (bm); // Fill the bitmap with a white background Paint whiteBgnd = new Paint(); whiteBgnd.setColor(Color.WHITE); whiteBgnd.setStyle(Paint.Style.FILL); c.drawRect(0, 0, width, height, whiteBgnd); // paint the page into the canvas page.paintPage(c); // Save the bitmap OutputStream outStream = new FileOutputStream("/sdcard/output.jpg"); bm.compress(CompressFormat.JPEG, 80, outStream); outStream.close(); } catch(Exception e) { Log.e("error", Log.getStackTraceString(e)); } } }