SlideShare a Scribd company logo
1 of 14
Printing Images
•
•

Taking and sharing photos is one of the most popular uses for mobile
devices.

•
•
•

If your application takes photos, displays them, or allows users to
share images, you should consider enabling printing of those images
in your application.

•
•
•

The Android Support Library provides a convenient function for
enabling image printing using a minimal amount of code and simple
set of print layout options.
Printing Images
•

The Android Support Library PrintHelper class provides a simple way to print of images.

•

The class has a single layout option, setScaleMode(), which allows you to print with one of two options:

•
•

•SCALE_MODE_FIT
This option sizes the image so that the whole image is shown within the printable area of the page.

•
•

•SCALE_MODE_FILL
This option scales the image so that it fills the entire printable area of the page. Choosing this setting
means that some portion of the top and bottom, or left and right edges of the image is not printed. This
option is the default value if you do not set a scale mode.

•

Both scaling options for setScaleMode() keep the existing aspect ratio of the image intact. The following
code example shows
how to create an instance of the PrintHelper class, set the scaling option, and start the printing process:

•
Printing HTML Documents
•
•

Printing out content beyond a simple photo on Android requires
composing text and graphics in a print document.

•
•

The Android framework provides a way to use HTML to compose
a document and print it with a minimum of code.

•
•

In Android 4.4 (API level 19), the WebView class has been updated to
enable printing HTML content.

•
•
•

The class allows you to load a local HTML resource or download
a page from the web, create a print job and hand it off to Android's
print services.

•
•

Following Code shows you how to quickly build an HTML document
containing text and graphics and use WebView to print it.
Use following code for layout
file(main.xml)
•<?xml version="1.0" encoding="utf-8"?>
•<LinearLayout android:id="@+id/LinearLayout01"
•
android:layout_width="fill_parent" android:layout_height="fill_parent"
•
xmlns:android="http://schemas.android.com/apk/res/android"
•
android:orientation="vertical">
•<LinearLayout android:id="@+id/LinearLayout02“
android:layout_width="wrap_content"
android:layout_height="wrap_content">

•<Button android:id="@+id/BtnImage" android:layout_width="wrap_content"
•
android:layout_height="wrap_content"
android:text="Image"></Button>
•<Button android:id="@+id/BtnHtml" android:layout_width="wrap_content"
•
android:layout_height="wrap_content"
android:text="HTML"></Button>
•</LinearLayout>
•</LinearLayout>
Create/Add Activity Name: PrintPdf.java
Use Following Code for PrintPdf.java
Code for PrintPdf.java
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.print.PrintAttributes;
import android.print.PrintDocumentAdapter;
import android.print.PrintJob;
import android.print.PrintManager;
import android.support.v4.print.PrintHelper;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

PrintPdf.java code continue….
public class PrintPdf extends Activity implements
OnClickListener {
/** Called when the activity is first created. */
Button Image;
Button Html;
private WebView mWebView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Image = (Button) findViewById(R.id.BtnImage);
Html = (Button) findViewById(R.id.BtnHtml);
Image.setOnClickListener(this);
Html.setOnClickListener(this);
}
Create/Add Activity Name: PrintPdf.java
Use Following Code for PrintPdf.java
PrintPdf.java code continue….
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v == Image) {
doPhotoPrint();
}
if (v == Html) {
doWebViewPrint();
}
}
public class PrintPdf extends Activity implements
OnClickListener {
/** Called when the activity is first created. */
Button Image;
Button Html;
private WebView mWebView;
/** Called when the activity is first created. */

PrintPdf.java code continue….
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Image = (Button) findViewById(R.id.BtnImage);
Html = (Button) findViewById(R.id.BtnHtml);
Image.setOnClickListener(this);
Html.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v == Image) {
doPhotoPrint();
}
if (v == Html) {
doWebViewPrint();
}
}
Create/Add Activity Name: PrintPdf.java
Use Following Code for PrintPdf.java
PrintPdf.java code continue….

PrintPdf.java code continue….

// Method for Image to PDF
private void doPhotoPrint() {

@Override
public boolean shouldOverrideUrlLoading(WebView view, String
url) {
return false;
}
@Override
public void onPageFinished(WebView view, String url) {
Log.i("print", "page finished loading " + url);
createWebPrintJob(view);
mWebView = null;
}
});
// Generate an HTML document on the fly:
String htmlDocument = "<html><body><h1>World's First PDF using
Android's PrintManager</h1><p>This is going to be fun for " +
"every android developer...</p></body></html>";

PrintHelper photoPrinter = new PrintHelper(this);
// PrintHelper photoPrinter = new PrintHelper(this);
photoPrinter.setScaleMode(PrintHelper.SCALE_MODE_FIT);
Bitmap bitmap =
BitmapFactory.decodeResource(getResources(),R.drawable.icon);
photoPrinter.printBitmap("droids.jpg - test print",
bitmap);
}
// Method for HTML -> PDF Conversion
private void doWebViewPrint() {
// Create a WebView object specifically for printing
//WebView webView = new WebView(getActivity());
WebView webView = new WebView(this);
webView.setWebViewClient(new WebViewClient() {

webView.loadDataWithBaseURL(null, htmlDocument, "text/HTML",
"UTF-8", null);
Create/Add Activity Name: PrintPdf.java
Use Following Code for PrintPdf.java
PrintPdf.java code continue….
Research prospect company.
Identify audience.
Define presales support (for example, engineers).
Plan // Keep a reference to WebView object until you pass the
PrintDocumentAdapter to the PrintManager
mWebView = webView;
}
private void createWebPrintJob(WebView webView) {
// Get a PrintManager instance
PrintManager printManager =
(PrintManager)this.getSystemService(Context.PRINT_SERVICE
);
// Get a print adapter instance
PrintDocumentAdapter printAdapter =
webView.createPrintDocumentAdapter();

PrintPdf.java code continue….
// Create a print job with name and adapter instance
String jobName = getString(R.string.app_name) + "
Document";
PrintJob printJob = printManager.print(jobName,
printAdapter,
new PrintAttributes.Builder().build());
// Save the job object for later status checking
//mPrintJobs.add(printJob);
}
}
meeting agenda.
Call and confirm meeting ahead of time.
Manifest File Code
Main Code

New Classes used in the above code:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Viewflipper"
android:versionCode="1"
android:versionName="1.0">

PrintHelper Helper for printing bitmaps.
PrintHelperKitkat Kitkat specific PrintManager API
implementation.

<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk android:minSdkVersion="19"
android:targetSdkVersion="19"/>

PrintManager
System level service for accessing the printing
capabilities of the platform.

<application android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".PrintPdf"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

PrintDocumentAdapter
Base class that provides the content of a document
to be printed.
PrintJob
This class represents a print job from the perspective
of an application.
App Screen with two options for Image and
HTML Printing and PDF Generation
Save as PDF Dialog Box, Enter
Filename and Hit Save
PDF Files Generated With App
For more details on Printing Content using Android visit following link:
https://developer.android.com/training/printing/index.html

HTML to PDF

Image to PDF
Contact Us
Lets Nurture UK

Lets Nurture INDIA

Gumption Business Centre
Glydegate
Bradford
West Yorkshire
BD5 0BQ
United Kingdom
+44(01274)271727
www.letsnurture.co.uk

312 Kalasagar Mall
Nr. Satadhar Cross Road
Ahmedabad
Gujarat
380061
India
(+91) 7940095953
www.letsnurture.com

More Related Content

Viewers also liked

Educational Technology Webquest
Educational Technology WebquestEducational Technology Webquest
Educational Technology Webquesteag2014
 
Marshall Cassidy-horse-around-lyrics
Marshall Cassidy-horse-around-lyricsMarshall Cassidy-horse-around-lyrics
Marshall Cassidy-horse-around-lyricsVOCAL SPIN
 
структура сказки для 5 класса
структура сказки для 5 классаструктура сказки для 5 класса
структура сказки для 5 классаkryljanauki
 
เรื่องประทับใจ ให้ข้อคิด 4
เรื่องประทับใจ ให้ข้อคิด 4เรื่องประทับใจ ให้ข้อคิด 4
เรื่องประทับใจ ให้ข้อคิด 4Na Tak
 
Улицы и площади
Улицы и площадиУлицы и площади
Улицы и площадиkryljanauki
 
jacando for business
jacando for businessjacando for business
jacando for businessMatthias Falk
 
Master trening startup_shevchuk 2015 v1.1
Master trening startup_shevchuk 2015 v1.1Master trening startup_shevchuk 2015 v1.1
Master trening startup_shevchuk 2015 v1.1Aleksei Shevchuk
 
Assignment Brief New
Assignment Brief NewAssignment Brief New
Assignment Brief NewSalfordmedia
 
รอยธรรมคำสอนพระเถระ 2
รอยธรรมคำสอนพระเถระ  2รอยธรรมคำสอนพระเถระ  2
รอยธรรมคำสอนพระเถระ 2Na Tak
 
Local Notification Tutorial
Local Notification TutorialLocal Notification Tutorial
Local Notification TutorialKetan Raval
 
10 amazing routines using the dynamic coins gimmick
10 amazing routines using the dynamic coins gimmick10 amazing routines using the dynamic coins gimmick
10 amazing routines using the dynamic coins gimmickRafael Ferreira
 
Feasibility study
Feasibility  studyFeasibility  study
Feasibility studyjilly17
 
Kespontanan Reaksi Kimia
Kespontanan Reaksi KimiaKespontanan Reaksi Kimia
Kespontanan Reaksi KimiaImam Gazali
 
для 5в класса
для 5в классадля 5в класса
для 5в классаkryljanauki
 
Project Management SKills Training Programme (Japanese)
Project Management SKills Training  Programme (Japanese)Project Management SKills Training  Programme (Japanese)
Project Management SKills Training Programme (Japanese)m_beresford
 
термины литер в презентации
термины литер в презентациитермины литер в презентации
термины литер в презентацииkryljanauki
 

Viewers also liked (20)

Educational Technology Webquest
Educational Technology WebquestEducational Technology Webquest
Educational Technology Webquest
 
365 powerpoint ad
365 powerpoint ad365 powerpoint ad
365 powerpoint ad
 
Marshall Cassidy-horse-around-lyrics
Marshall Cassidy-horse-around-lyricsMarshall Cassidy-horse-around-lyrics
Marshall Cassidy-horse-around-lyrics
 
структура сказки для 5 класса
структура сказки для 5 классаструктура сказки для 5 класса
структура сказки для 5 класса
 
เรื่องประทับใจ ให้ข้อคิด 4
เรื่องประทับใจ ให้ข้อคิด 4เรื่องประทับใจ ให้ข้อคิด 4
เรื่องประทับใจ ให้ข้อคิด 4
 
лекція № 2
лекція № 2лекція № 2
лекція № 2
 
Улицы и площади
Улицы и площадиУлицы и площади
Улицы и площади
 
jacando for business
jacando for businessjacando for business
jacando for business
 
хялбар тэгш 2012
хялбар тэгш 2012 хялбар тэгш 2012
хялбар тэгш 2012
 
Master trening startup_shevchuk 2015 v1.1
Master trening startup_shevchuk 2015 v1.1Master trening startup_shevchuk 2015 v1.1
Master trening startup_shevchuk 2015 v1.1
 
Assignment Brief New
Assignment Brief NewAssignment Brief New
Assignment Brief New
 
лекція № 4
лекція № 4лекція № 4
лекція № 4
 
รอยธรรมคำสอนพระเถระ 2
รอยธรรมคำสอนพระเถระ  2รอยธรรมคำสอนพระเถระ  2
รอยธรรมคำสอนพระเถระ 2
 
Local Notification Tutorial
Local Notification TutorialLocal Notification Tutorial
Local Notification Tutorial
 
10 amazing routines using the dynamic coins gimmick
10 amazing routines using the dynamic coins gimmick10 amazing routines using the dynamic coins gimmick
10 amazing routines using the dynamic coins gimmick
 
Feasibility study
Feasibility  studyFeasibility  study
Feasibility study
 
Kespontanan Reaksi Kimia
Kespontanan Reaksi KimiaKespontanan Reaksi Kimia
Kespontanan Reaksi Kimia
 
для 5в класса
для 5в классадля 5в класса
для 5в класса
 
Project Management SKills Training Programme (Japanese)
Project Management SKills Training  Programme (Japanese)Project Management SKills Training  Programme (Japanese)
Project Management SKills Training Programme (Japanese)
 
термины литер в презентации
термины литер в презентациитермины литер в презентации
термины литер в презентации
 

Similar to Print Images and HTML Documents with Android PrintManager

01 09 - graphical user interface - basic widgets
01  09 - graphical user interface - basic widgets01  09 - graphical user interface - basic widgets
01 09 - graphical user interface - basic widgetsSiva Kumar reddy Vasipally
 
Fragments: Why, How, What For?
Fragments: Why, How, What For?Fragments: Why, How, What For?
Fragments: Why, How, What For?Brenda Cook
 
android layouts
android layoutsandroid layouts
android layoutsDeepa Rani
 
4.preference management
4.preference management 4.preference management
4.preference management maamir farooq
 
06. Android Basic Widget and Container
06. Android Basic Widget and Container06. Android Basic Widget and Container
06. Android Basic Widget and ContainerOum Saokosal
 
Mobile Software Engineering Crash Course - C03 Android
Mobile Software Engineering Crash Course - C03 AndroidMobile Software Engineering Crash Course - C03 Android
Mobile Software Engineering Crash Course - C03 AndroidMohammad Shaker
 
3. file external memory
3. file external memory3. file external memory
3. file external memorymaamir farooq
 
How to use data binding in android
How to use data binding in androidHow to use data binding in android
How to use data binding in androidInnovationM
 
Android Development : (Android Studio, PHP, XML, MySQL)
Android Development : (Android Studio, PHP, XML, MySQL)Android Development : (Android Studio, PHP, XML, MySQL)
Android Development : (Android Studio, PHP, XML, MySQL)Kavya Barnadhya Hazarika
 
Trimantra - Project Portfolio_NET
Trimantra - Project Portfolio_NETTrimantra - Project Portfolio_NET
Trimantra - Project Portfolio_NETMihir G.
 
Responsive websites. Toolbox
Responsive websites. ToolboxResponsive websites. Toolbox
Responsive websites. ToolboxWojtek Zając
 
Dynamic Graph Plotting with WPF
Dynamic Graph Plotting with WPFDynamic Graph Plotting with WPF
Dynamic Graph Plotting with WPFIJERD Editor
 
Android Workshop
Android WorkshopAndroid Workshop
Android WorkshopJunda Ong
 
Lecture #1 Creating your first android project
Lecture #1  Creating your first android projectLecture #1  Creating your first android project
Lecture #1 Creating your first android projectVitali Pekelis
 

Similar to Print Images and HTML Documents with Android PrintManager (20)

01 09 - graphical user interface - basic widgets
01  09 - graphical user interface - basic widgets01  09 - graphical user interface - basic widgets
01 09 - graphical user interface - basic widgets
 
Ap quiz app
Ap quiz appAp quiz app
Ap quiz app
 
Fragments: Why, How, What For?
Fragments: Why, How, What For?Fragments: Why, How, What For?
Fragments: Why, How, What For?
 
android layouts
android layoutsandroid layouts
android layouts
 
4.preference management
4.preference management 4.preference management
4.preference management
 
06. Android Basic Widget and Container
06. Android Basic Widget and Container06. Android Basic Widget and Container
06. Android Basic Widget and Container
 
Mobile Software Engineering Crash Course - C03 Android
Mobile Software Engineering Crash Course - C03 AndroidMobile Software Engineering Crash Course - C03 Android
Mobile Software Engineering Crash Course - C03 Android
 
3. file external memory
3. file external memory3. file external memory
3. file external memory
 
How to use data binding in android
How to use data binding in androidHow to use data binding in android
How to use data binding in android
 
Android Development : (Android Studio, PHP, XML, MySQL)
Android Development : (Android Studio, PHP, XML, MySQL)Android Development : (Android Studio, PHP, XML, MySQL)
Android Development : (Android Studio, PHP, XML, MySQL)
 
06 UI Layout
06 UI Layout06 UI Layout
06 UI Layout
 
Responsive web design
Responsive web designResponsive web design
Responsive web design
 
AspNetWhitePaper
AspNetWhitePaperAspNetWhitePaper
AspNetWhitePaper
 
AspNetWhitePaper
AspNetWhitePaperAspNetWhitePaper
AspNetWhitePaper
 
Trimantra - Project Portfolio_NET
Trimantra - Project Portfolio_NETTrimantra - Project Portfolio_NET
Trimantra - Project Portfolio_NET
 
Android Button
Android ButtonAndroid Button
Android Button
 
Responsive websites. Toolbox
Responsive websites. ToolboxResponsive websites. Toolbox
Responsive websites. Toolbox
 
Dynamic Graph Plotting with WPF
Dynamic Graph Plotting with WPFDynamic Graph Plotting with WPF
Dynamic Graph Plotting with WPF
 
Android Workshop
Android WorkshopAndroid Workshop
Android Workshop
 
Lecture #1 Creating your first android project
Lecture #1  Creating your first android projectLecture #1  Creating your first android project
Lecture #1 Creating your first android project
 

More from Ketan Raval

Amazon Alexa Auto Software Development Kit (SDK)
Amazon Alexa Auto Software Development Kit (SDK)Amazon Alexa Auto Software Development Kit (SDK)
Amazon Alexa Auto Software Development Kit (SDK)Ketan Raval
 
Proximity Marketing Solutions enhancing Businesses leveraging iBeacon SDK Int...
Proximity Marketing Solutions enhancing Businesses leveraging iBeacon SDK Int...Proximity Marketing Solutions enhancing Businesses leveraging iBeacon SDK Int...
Proximity Marketing Solutions enhancing Businesses leveraging iBeacon SDK Int...Ketan Raval
 
Zero ui future is here
Zero ui   future is hereZero ui   future is here
Zero ui future is hereKetan Raval
 
Android n and beyond
Android n and beyondAndroid n and beyond
Android n and beyondKetan Raval
 
IoT and Future of Connected world
IoT and Future of Connected worldIoT and Future of Connected world
IoT and Future of Connected worldKetan Raval
 
#Instagram API Get visibility you always wanted
#Instagram API   Get visibility you always wanted#Instagram API   Get visibility you always wanted
#Instagram API Get visibility you always wantedKetan Raval
 
Keynote - Devfest 2015 organized by GDG Ahmedabad
Keynote - Devfest 2015 organized by GDG AhmedabadKeynote - Devfest 2015 organized by GDG Ahmedabad
Keynote - Devfest 2015 organized by GDG AhmedabadKetan Raval
 
Android notifications
Android notificationsAndroid notifications
Android notificationsKetan Raval
 
How to make your Mobile App HIPPA Compliant
How to make your Mobile App HIPPA CompliantHow to make your Mobile App HIPPA Compliant
How to make your Mobile App HIPPA CompliantKetan Raval
 
3 d touch a true game changer
3 d touch a true game changer3 d touch a true game changer
3 d touch a true game changerKetan Raval
 
OBD Mobile App - Fault Codes, Driving Behaviour and Fuel Economy
OBD Mobile App - Fault Codes, Driving Behaviour and Fuel EconomyOBD Mobile App - Fault Codes, Driving Behaviour and Fuel Economy
OBD Mobile App - Fault Codes, Driving Behaviour and Fuel EconomyKetan Raval
 
Vehicle to vehicle communication using gps
Vehicle to vehicle communication using gpsVehicle to vehicle communication using gps
Vehicle to vehicle communication using gpsKetan Raval
 
Obd how to guide
Obd how to guideObd how to guide
Obd how to guideKetan Raval
 
Garmin api integration
Garmin api integrationGarmin api integration
Garmin api integrationKetan Raval
 
Beacon The Google Way
Beacon The Google WayBeacon The Google Way
Beacon The Google WayKetan Raval
 
Edge detection iOS application
Edge detection iOS applicationEdge detection iOS application
Edge detection iOS applicationKetan Raval
 
Google calendar integration in iOS app
Google calendar integration in iOS appGoogle calendar integration in iOS app
Google calendar integration in iOS appKetan Raval
 
Big data cloudcomputing
Big data cloudcomputingBig data cloudcomputing
Big data cloudcomputingKetan Raval
 
All about Apple Watchkit
All about Apple WatchkitAll about Apple Watchkit
All about Apple WatchkitKetan Raval
 

More from Ketan Raval (20)

Amazon Alexa Auto Software Development Kit (SDK)
Amazon Alexa Auto Software Development Kit (SDK)Amazon Alexa Auto Software Development Kit (SDK)
Amazon Alexa Auto Software Development Kit (SDK)
 
Proximity Marketing Solutions enhancing Businesses leveraging iBeacon SDK Int...
Proximity Marketing Solutions enhancing Businesses leveraging iBeacon SDK Int...Proximity Marketing Solutions enhancing Businesses leveraging iBeacon SDK Int...
Proximity Marketing Solutions enhancing Businesses leveraging iBeacon SDK Int...
 
Keynote 2016
Keynote 2016Keynote 2016
Keynote 2016
 
Zero ui future is here
Zero ui   future is hereZero ui   future is here
Zero ui future is here
 
Android n and beyond
Android n and beyondAndroid n and beyond
Android n and beyond
 
IoT and Future of Connected world
IoT and Future of Connected worldIoT and Future of Connected world
IoT and Future of Connected world
 
#Instagram API Get visibility you always wanted
#Instagram API   Get visibility you always wanted#Instagram API   Get visibility you always wanted
#Instagram API Get visibility you always wanted
 
Keynote - Devfest 2015 organized by GDG Ahmedabad
Keynote - Devfest 2015 organized by GDG AhmedabadKeynote - Devfest 2015 organized by GDG Ahmedabad
Keynote - Devfest 2015 organized by GDG Ahmedabad
 
Android notifications
Android notificationsAndroid notifications
Android notifications
 
How to make your Mobile App HIPPA Compliant
How to make your Mobile App HIPPA CompliantHow to make your Mobile App HIPPA Compliant
How to make your Mobile App HIPPA Compliant
 
3 d touch a true game changer
3 d touch a true game changer3 d touch a true game changer
3 d touch a true game changer
 
OBD Mobile App - Fault Codes, Driving Behaviour and Fuel Economy
OBD Mobile App - Fault Codes, Driving Behaviour and Fuel EconomyOBD Mobile App - Fault Codes, Driving Behaviour and Fuel Economy
OBD Mobile App - Fault Codes, Driving Behaviour and Fuel Economy
 
Vehicle to vehicle communication using gps
Vehicle to vehicle communication using gpsVehicle to vehicle communication using gps
Vehicle to vehicle communication using gps
 
Obd how to guide
Obd how to guideObd how to guide
Obd how to guide
 
Garmin api integration
Garmin api integrationGarmin api integration
Garmin api integration
 
Beacon The Google Way
Beacon The Google WayBeacon The Google Way
Beacon The Google Way
 
Edge detection iOS application
Edge detection iOS applicationEdge detection iOS application
Edge detection iOS application
 
Google calendar integration in iOS app
Google calendar integration in iOS appGoogle calendar integration in iOS app
Google calendar integration in iOS app
 
Big data cloudcomputing
Big data cloudcomputingBig data cloudcomputing
Big data cloudcomputing
 
All about Apple Watchkit
All about Apple WatchkitAll about Apple Watchkit
All about Apple Watchkit
 

Recently uploaded

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 

Recently uploaded (20)

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 

Print Images and HTML Documents with Android PrintManager

  • 1.
  • 2. Printing Images • • Taking and sharing photos is one of the most popular uses for mobile devices. • • • If your application takes photos, displays them, or allows users to share images, you should consider enabling printing of those images in your application. • • • The Android Support Library provides a convenient function for enabling image printing using a minimal amount of code and simple set of print layout options.
  • 3. Printing Images • The Android Support Library PrintHelper class provides a simple way to print of images. • The class has a single layout option, setScaleMode(), which allows you to print with one of two options: • • •SCALE_MODE_FIT This option sizes the image so that the whole image is shown within the printable area of the page. • • •SCALE_MODE_FILL This option scales the image so that it fills the entire printable area of the page. Choosing this setting means that some portion of the top and bottom, or left and right edges of the image is not printed. This option is the default value if you do not set a scale mode. • Both scaling options for setScaleMode() keep the existing aspect ratio of the image intact. The following code example shows how to create an instance of the PrintHelper class, set the scaling option, and start the printing process: •
  • 4. Printing HTML Documents • • Printing out content beyond a simple photo on Android requires composing text and graphics in a print document. • • The Android framework provides a way to use HTML to compose a document and print it with a minimum of code. • • In Android 4.4 (API level 19), the WebView class has been updated to enable printing HTML content. • • • The class allows you to load a local HTML resource or download a page from the web, create a print job and hand it off to Android's print services. • • Following Code shows you how to quickly build an HTML document containing text and graphics and use WebView to print it.
  • 5. Use following code for layout file(main.xml) •<?xml version="1.0" encoding="utf-8"?> •<LinearLayout android:id="@+id/LinearLayout01" • android:layout_width="fill_parent" android:layout_height="fill_parent" • xmlns:android="http://schemas.android.com/apk/res/android" • android:orientation="vertical"> •<LinearLayout android:id="@+id/LinearLayout02“ android:layout_width="wrap_content" android:layout_height="wrap_content"> •<Button android:id="@+id/BtnImage" android:layout_width="wrap_content" • android:layout_height="wrap_content" android:text="Image"></Button> •<Button android:id="@+id/BtnHtml" android:layout_width="wrap_content" • android:layout_height="wrap_content" android:text="HTML"></Button> •</LinearLayout> •</LinearLayout>
  • 6. Create/Add Activity Name: PrintPdf.java Use Following Code for PrintPdf.java Code for PrintPdf.java import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.print.PrintAttributes; import android.print.PrintDocumentAdapter; import android.print.PrintJob; import android.print.PrintManager; import android.support.v4.print.PrintHelper; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Button; PrintPdf.java code continue…. public class PrintPdf extends Activity implements OnClickListener { /** Called when the activity is first created. */ Button Image; Button Html; private WebView mWebView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Image = (Button) findViewById(R.id.BtnImage); Html = (Button) findViewById(R.id.BtnHtml); Image.setOnClickListener(this); Html.setOnClickListener(this); }
  • 7. Create/Add Activity Name: PrintPdf.java Use Following Code for PrintPdf.java PrintPdf.java code continue…. @Override public void onClick(View v) { // TODO Auto-generated method stub if (v == Image) { doPhotoPrint(); } if (v == Html) { doWebViewPrint(); } } public class PrintPdf extends Activity implements OnClickListener { /** Called when the activity is first created. */ Button Image; Button Html; private WebView mWebView; /** Called when the activity is first created. */ PrintPdf.java code continue…. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Image = (Button) findViewById(R.id.BtnImage); Html = (Button) findViewById(R.id.BtnHtml); Image.setOnClickListener(this); Html.setOnClickListener(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub if (v == Image) { doPhotoPrint(); } if (v == Html) { doWebViewPrint(); } }
  • 8. Create/Add Activity Name: PrintPdf.java Use Following Code for PrintPdf.java PrintPdf.java code continue…. PrintPdf.java code continue…. // Method for Image to PDF private void doPhotoPrint() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return false; } @Override public void onPageFinished(WebView view, String url) { Log.i("print", "page finished loading " + url); createWebPrintJob(view); mWebView = null; } }); // Generate an HTML document on the fly: String htmlDocument = "<html><body><h1>World's First PDF using Android's PrintManager</h1><p>This is going to be fun for " + "every android developer...</p></body></html>"; PrintHelper photoPrinter = new PrintHelper(this); // PrintHelper photoPrinter = new PrintHelper(this); photoPrinter.setScaleMode(PrintHelper.SCALE_MODE_FIT); Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.icon); photoPrinter.printBitmap("droids.jpg - test print", bitmap); } // Method for HTML -> PDF Conversion private void doWebViewPrint() { // Create a WebView object specifically for printing //WebView webView = new WebView(getActivity()); WebView webView = new WebView(this); webView.setWebViewClient(new WebViewClient() { webView.loadDataWithBaseURL(null, htmlDocument, "text/HTML", "UTF-8", null);
  • 9. Create/Add Activity Name: PrintPdf.java Use Following Code for PrintPdf.java PrintPdf.java code continue…. Research prospect company. Identify audience. Define presales support (for example, engineers). Plan // Keep a reference to WebView object until you pass the PrintDocumentAdapter to the PrintManager mWebView = webView; } private void createWebPrintJob(WebView webView) { // Get a PrintManager instance PrintManager printManager = (PrintManager)this.getSystemService(Context.PRINT_SERVICE ); // Get a print adapter instance PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter(); PrintPdf.java code continue…. // Create a print job with name and adapter instance String jobName = getString(R.string.app_name) + " Document"; PrintJob printJob = printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build()); // Save the job object for later status checking //mPrintJobs.add(printJob); } } meeting agenda. Call and confirm meeting ahead of time.
  • 10. Manifest File Code Main Code New Classes used in the above code: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.Viewflipper" android:versionCode="1" android:versionName="1.0"> PrintHelper Helper for printing bitmaps. PrintHelperKitkat Kitkat specific PrintManager API implementation. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19"/> PrintManager System level service for accessing the printing capabilities of the platform. <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".PrintPdf" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> PrintDocumentAdapter Base class that provides the content of a document to be printed. PrintJob This class represents a print job from the perspective of an application.
  • 11. App Screen with two options for Image and HTML Printing and PDF Generation
  • 12. Save as PDF Dialog Box, Enter Filename and Hit Save
  • 13. PDF Files Generated With App For more details on Printing Content using Android visit following link: https://developer.android.com/training/printing/index.html HTML to PDF Image to PDF
  • 14. Contact Us Lets Nurture UK Lets Nurture INDIA Gumption Business Centre Glydegate Bradford West Yorkshire BD5 0BQ United Kingdom +44(01274)271727 www.letsnurture.co.uk 312 Kalasagar Mall Nr. Satadhar Cross Road Ahmedabad Gujarat 380061 India (+91) 7940095953 www.letsnurture.com