Android 4.4 인쇄 프레임 워크를 사용하여 이미 다운로드 한 PDF를 인쇄하는 방법은 무엇입니까?안드로이드를 사용하여 PDF를 인쇄하는 방법 4.4 인쇄 프레임 워크
개발자 설명서를 보았습니다. 운이 없다. 모든 예제가 도움이 될 것입니다
Android 4.4 인쇄 프레임 워크를 사용하여 이미 다운로드 한 PDF를 인쇄하는 방법은 무엇입니까?안드로이드를 사용하여 PDF를 인쇄하는 방법 4.4 인쇄 프레임 워크
개발자 설명서를 보았습니다. 운이 없다. 모든 예제가 도움이 될 것입니다
Google에서 몇 시간을 보낸 후 해결책을 찾았습니다.
PrintManager printManager = (PrintManager) this.getSystemService(Context.PRINT_SERVICE);
String jobName = this.getString(R.string.app_name) + " Document";
printManager.print(jobName, pda, null);
PrintDocumentAdapter pda = new PrintDocumentAdapter(){
@Override
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback){
InputStream input = null;
OutputStream output = null;
try {
input = new FileInputStream(file to print);
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;
}
PrintDocumentInfo pdi = new PrintDocumentInfo.Builder("Name of file").setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT).build();
callback.onLayoutFinished(pdi, true);
}
};
어떤 종류의 프린터가 지원됩니까 ?? – abhishek
@abhishek http://www.google.com/cloudprint/learn/printers.html –
감사합니다. 시간이 많이 걸렸습니다. –
kitkat의 의미는 무엇입니까? –
예 @AvinashBabu –