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

Android studio does not search res/xml folder to find usage
Build errors with new kotlin 1.1 , kapt cant parse databinding params
How to get the actual index of a child in a ListView?
Running parallel test in TestNG Appium Selenium
Android 7.1.2 QuickSettings tile not being tinted
Embedding Cordova app inside Native Android APP
Espresso - Validate TextView contents Android
Two images captured by camera and not able to delete one from DCIM/Camera folder
Twilio SMs Two factor authentication
How can I pass Facebook sdk (Android) access token to Rails 5 devise backend?
Launch Homescreen on Notification Click
How can I optimize Multiple image stitching?
TextInputEdit Text Counter about text length
Implement Click event of the MPPie chart library on one slice click
Android JsonObjectRequest VolleyManager specific port
How to load PreferenceFragments expanded in the same screen?

Categories

HOME
phantom-dsl
assembly
cheerio
ggplot2
apache-flink
rdbms
case
vscode-extensions
aws-cli
pyqt4
hugo
onclick
vsm
boto3
mel
why3
ycsb
ipmitool
code-generation
frequency-distribution
3nf
android-intent
internationalization
scsi
atlassian-stash
cfml
squashfs
ember-cli
dapper-extensions
windows-server-2003
xcode-ui-testing
google-cloud-print
pic32
android-sharedpreferences
has-and-belongs-to-many
8051
intersystems-cache
paperjs
gp
sqlpackage
gitlab-api
aws-codecommit
weather
deltaspike
jmockit
memory-address
catch-unit-test
hard-drive
android-maps-extensions
demo
google-data-api
jvmti
laravel-elixir
plr
fwrite
jquery-ui-draggable
mschart
identification
singleinstance
aquamacs
avx
bbpress
branch-prediction
restore
cronexpression
preprocessor
tooleap
gogs
simevents
clipboard.js
angular-ui-typeahead
sklearn-pandas
ikiwiki
ascii-art
crouton-os
dynatree
flock
intel-c++
coda
.bash-profile
evolus-pencil
finalbuilder
viola-jones
snoop
bufferedinputstream
broadband
bcache
punycode
ss7
renderer
menubar
windows-embedded-standard
artemis
oocss
observium
cardreader
mysql-error-2013
saleslogix
josql
stress
luabind
xcelsius
cuteeditor
nhprof
squishit
delimited-text
vs-android
ajax-polling
nstokenfield
web-application-project
xpsdocument
mathematical-typesetting
appliance
great-circle

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