Android 从服务器URL打印pdf
我有一个pdf url,并使用以下代码在webview中显示:Android 从服务器URL打印pdf,android,pdf,printing,Android,Pdf,Printing,我有一个pdf url,并使用以下代码在webview中显示: WebView webview = (WebView) findViewById(R.id.wb); webview.getSettings().setJavaScriptEnabled(true); String pdf = "http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf"; webview.
WebView webview = (WebView) findViewById(R.id.wb);
webview.getSettings().setJavaScriptEnabled(true);
String pdf = "http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf";
webview.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdf);
我需要打印此pdf而不下载pdf。
在文档中,它只告诉如何通过在PDF画布上呈现自定义内容并发送由此创建的PDF文档进行打印来打印自定义内容。但是没有关于如何发送webview pdf进行打印的信息?
请告诉我,任何人都知道如何处理这件事。
提前感谢也许您可以尝试使用pdf从网络视图中捕获一张图片并打印此图片。您可以使用类似于
WebView.capturePicture()
的东西。这是我的原始文档
PrintDocumentAdapter pda = new PrintDocumentAdapter() {
@Override
public void onWrite(PageRange[] pages, final ParcelFileDescriptor destination, CancellationSignal cancellationSignal, final WriteResultCallback callback) {
!!THIS MUST BE RUN ASYNC!!
InputStream input = null;
OutputStream output = null;
try {
input = new URL(YOUR URL HERE).openStream();
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) {
//TODO Handle Exception
} catch (Exception e) {
//TODO Handle 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 DOCUMENT").setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT).build();
callback.onLayoutFinished(pdi, true);
}
};
PrintManager printManager = (PrintManager) this.getSystemService(Context.PRINT_SERVICE);
printManager.print("JOB NAME", pda, null);