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

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Recently uploaded (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

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