android


How to print PDF, image and HTML documents from android device to a printer on wifi?


I need to implement document printing functionality in my android app.
I was able to print image file using the android printing framework code mentioned below :
private void doPhotoPrint(Bitmap bigbitmap)
{
PrintHelper photoPrinter = new PrintHelper(MainActivity.this);
photoPrinter.setScaleMode(PrintHelper.SCALE_MODE_FIT);
photoPrinter.printBitmap("droids.jpg - test print", bigbitmap);
}
I went through the existing threads discussing the same question, but none of them help much.
The issue I am facing is with other document types like PDF and HLML.
It would be helpful if someone could give some insight on the same.
you can check this code
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
PrintManager printManager = (PrintManager) this.getSystemService(Context.PRINT_SERVICE);
String jobName = this.getString(R.string.app_name) + " Document";
PrintDocumentAdapter pda = new PrintDocumentAdapter() {
#Override
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback) {
InputStream input = null;
OutputStream output = null;
try {
AssetManager assetManager = getAssets();
File file = new File(getFilesDir(), "fact_sheet.pdf");
input = assetManager.open("fact_sheet.pdf");
output = new FileOutputStream(destination.getFileDescriptor());
byte[] buf = new byte[1024];
int bytesRead;
while ((bytesRead = input.read(buf)) > 0) {
output.write(buf, 0, bytesRead);
}
callback.onWriteFinished(new PageRange[]{PageRange.ALL_PAGES});
} catch (FileNotFoundException ee) {
//Catch exception
} catch (Exception e) {
//Catch exception
} finally {
try {
input.close();
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
#Override
public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras) {
if (cancellationSignal.isCanceled()) {
callback.onLayoutCancelled();
return;
}
// int pages = computePageCount(newAttributes);
PrintDocumentInfo pdi = new PrintDocumentInfo.Builder("Name of file").setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT).build();
callback.onLayoutFinished(pdi, true);
}
};
printManager.print(jobName, pda, null);
}

Related Links

The size of the buttons depending on the screen resolution
android app using .this
What is preventing Google Play from listing my app for my compatible device?
Images not appearing on Emulator or Phone
Android Color Interpolation
Android toolbar doesn't expand when scrolling up
How to properly save and restore Activity and Fragment status in Android?
using a camera in android (and Parse)
android.widget.EditText cast issue on tablet device
What is the difference between title and display name
Integer in place of Ids and Layouts
Android dragndrop surfaceview
Android - What is outputX/outputY and aspectX/aspectY when crop an image from gallery or camera?
How to implement dynamic page curl in android?
Can I create multiple account with same ip in google play console?
How to make Level as per total no?

Categories

HOME
twitter-bootstrap-3
telegram
static-site
onclick
vsm
elasticsearch-5
google-schemas
gson
mxgraph
ipmitool
parameter-passing
modbus-tcp
scsi
symfony-console
topology
windows-xp
undertow
dpdk
roslyn
monit
direct3d11
custom-post-type
clickjacking
reactjs.net
swagger-php
metaprogramming
cin
resolution
azure-arm
levenshtein-distance
movilizer
android-checkbox
oim
pom.xml
ntvs
serde
pair-programming
appdomain
git-flow
skin
arules
otp
cmp
baidu
restore
choice
cronexpression
actor-platform
simevents
refinerycms
shopping
cda
httpruntime.cache
binomial-theorem
liquid-layout
typeconverter
zend-currency
cross-join
theos
punycode
rmysql
jqmodal
ray
draw2d-js
radiant
getopt
hibernate-entitymanager
gd-graph
solace-mq
c++builder-xe5
css-reset
joomla-template
cardreader
swfobject
fragmenttransaction
thttpd
jdb
multiplexing
http-daemon
undefined-index
django-piston
lobo-cobra
visualj#
sun
fdf
wspbuilder

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App