Java Code Examples for com.itextpdf.text.Image#scaleToFit()

The following examples show how to use com.itextpdf.text.Image#scaleToFit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PDFMigrationReportWriter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private com.itextpdf.text.Image getImageForStatus(int status) throws BadElementException, MalformedURLException, IOException {
	switch (status) {
	case IStatus.OK: Image im =  Image.getInstance(FileLocator.toFileURL(MigrationPlugin.getDefault().getBundle().getResource("/icons/valid.png")));im.setCompressionLevel(12);im.scaleToFit(12, 12);return im;
	case IStatus.WARNING:  im = Image.getInstance(FileLocator.toFileURL(MigrationPlugin.getDefault().getBundle().getResource("/icons/warning.gif")));im.setCompressionLevel(12);im.scaleToFit(16, 16);return im;
	case IStatus.ERROR:  im = Image.getInstance(FileLocator.toFileURL(MigrationPlugin.getDefault().getBundle().getResource("/icons/error.png")));im.setCompressionLevel(12);im.scaleToFit(12, 12);return im;
	default:break;
	}

	return null;
}
 
Example 2
Source File: eReceipt.java    From smartcoins-wallet with MIT License 4 votes vote down vote up
private void generatePdf() {
    try {
        showProgressBar();
        verifyStoragePermissions(this);
        final String path = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + getResources().getString(R.string.folder_name) + File.separator + "eReceipt-" + transactionId + ".pdf";
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(path));
        document.open();
        Bitmap bitmap = Bitmap.createBitmap(
                llall.getWidth(),
                llall.getHeight(),
                Bitmap.Config.ARGB_8888);


        Canvas c = new Canvas(bitmap);
        llall.draw(c);

        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
        byte[] imageInByte = stream.toByteArray();
        Image myImage = Image.getInstance(imageInByte);
        float documentWidth = document.getPageSize().getWidth();
        float documentHeight = document.getPageSize().getHeight() - document.topMargin() - document.bottomMargin();
        myImage.scaleToFit(documentWidth, documentHeight);
        myImage.setAlignment(Image.ALIGN_CENTER | Image.MIDDLE);
        document.add(myImage);
        document.close();
        this.runOnUiThread(new Runnable() {
            public void run() {
                Intent email = new Intent(Intent.ACTION_SEND);
                Uri uri = Uri.fromFile(new File(path));
                email.putExtra(Intent.EXTRA_STREAM, uri);
                email.putExtra(Intent.EXTRA_SUBJECT, "eReceipt " + date);
                email.setType("application/pdf");
                email.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(email);
            }
        });
        hideProgressBar();
    } catch (Exception e) {
        Log.e(TAG, "Exception while tryig to share receipt info. Msg: " + e.getMessage());
    }
}