修改内容pdf PrintDocumentAdapter Web视图

时间:2017-04-20 16:57:20

标签: android pdf webview

我使用PrintDocumentAdapter从网页视图内容生成pdf:

PrintManager printManager = (PrintManager) this
                .getSystemService(Context.PRINT_SERVICE);

        PrintDocumentAdapter printAdapter;
        // Get a print adapter instance
        if (Build.VERSION.SDK_INT >= 21) {
            try {
                DateFormat df = new SimpleDateFormat("yyyy_MM_dd_hhmmss", Locale.US);
                String hour = df.format(Calendar.getInstance().getTime());
                printAdapter = webView.createPrintDocumentAdapter(hour + "_" + person.getDocument().getDocumentId());
            } catch (Exception e) {
                printAdapter = webView.createPrintDocumentAdapter("Documento");
                e.printStackTrace();
            }
        } else {
            printAdapter = webView.createPrintDocumentAdapter();
        }

 String jobName = this.getString(R.string.app_name) + "Document";
        printManager.print(jobName, printAdapter,
                new PrintAttributes.Builder().build());

这段代码对我来说很好,但我有一个问题:

¿是否可以为PrintDocumentAdapter生成的pdf添加标题? 我想生成一个包含Web视图内容的pdf,但是要添加到 pdf标题的内容:

通过示例结构最终pdf:

[HEADER]由我的应用生成

[内容] pdf原创内容

0 个答案:

没有答案