我在android中有一个打印机应用程序。主要活动包含一个网页。我通过webview.capturePicture()获取完整的webview。然后我将它添加到pdf中。我使用itext来做到这一点。然后我将其传递给Google云打印进行打印。我可以把它打印出来。
这是我的主要活动:
pv.btnPrint.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.e("VIEWWWWWWWWWWWWWWWWWWWWW", "kaj korce..............");
runOnUiThread(new Runnable() {
public void run() {
// Show and set focus.
pv.btnPrint.setVisibility(View.INVISIBLE);
//String mPath = Environment
//.getExternalStorageDirectory().toString()
// + "/"
//+ "dse.jpg";
/*
* Bitmap bitmap; View v1 = pv.wev.getRootView();
* v1.setDrawingCacheEnabled(true);
*
* bitmap = Bitmap.createBitmap(v1.getDrawingCache());
* v1.setDrawingCacheEnabled(false); OutputStream fout =
* null; File imageFile = new File(mPath); try { fout =
* new FileOutputStream(imageFile);
* bitmap.compress(Bitmap.CompressFormat.JPEG, 40,
* fout); fout.flush(); fout.close();
*
* } catch (FileNotFoundException e) { // TODO
* Auto-generated catch block e.printStackTrace(); }
* catch (IOException e) { // TODO Auto-generated catch
* block e.printStackTrace(); }
*/
Picture picture = pv.wev.capturePicture();
Bitmap b = Bitmap.createBitmap(picture.getWidth(),
picture.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
picture.draw(c);
ByteArrayOutputStream out = null;
byte[] byteArchadeImage = null;
try {
out = new ByteArrayOutputStream();
if (out != null) {
b.compress(Bitmap.CompressFormat.JPEG, 100, out);
byteArchadeImage = out.toByteArray();
out.flush();
out.close();
}
} catch (Exception e) {
Log.e("MSG", e.getLocalizedMessage());
}
Document document = new Document();
try {
PdfWriter.getInstance(document,
new FileOutputStream(Environment
.getExternalStorageDirectory()
.toString()
+ "/" + "dse.pdf"));
document.open();
//document.add(new Paragraph("This Is For You!!!!"));
try {
Image image = Image.getInstance(byteArchadeImage);
image.scaleAbsolute(600,
800);
image.setAlignment(Image.MIDDLE |Image.ALIGN_MIDDLE);
document.add(image);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
document.close();
Intent printIntent = new Intent(
VividViewerActivity.this,
PrintDialogActivity.class);
Uri uri = Uri.fromFile(new File(Environment
.getExternalStorageDirectory().toString()
+ "/"
+ "dse.pdf"));
printIntent.setDataAndType(uri, "application/pdf");
// printIntent.putExtra(Intent.EXTRA_STREAM,
// Uri.fromFile(new
// File(ur)));
String time = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
printIntent.putExtra("title", "vividworks_report_"+time+".pdf");
startActivity(printIntent);
}
});
以下是Google云打印的打印副本:
现在我的问题是:
帮助我,因为这对我来说非常重要。