Wednesday, 5 May 2021

How to get the final address to the PDF file stored by PrintManager.print

I create a report using html file and moustache. After that I load it in a WebView and use the PrintManage and PrintDocumentAdaptor to preview the report. Then user can store the file as a PDF. In the following snippet I can detect when the file is stored using onFinsih(), but I cannot find where it is stored.

public class PrintDocumentAdapterWrapper extends PrintDocumentAdapter {
    private PrintDocumentAdapter delegate;
    private String jobName;
    private WebView wv;

    public PrintDocumentAdapterWrapper(WebView wv,String jobName) {
        super();
        this.wv = wv;
        this.jobName = jobName;
        delegate = wv.createPrintDocumentAdapter(jobName);
    }

    @Override
    public void onLayout(PrintAttributes printAttributes, PrintAttributes printAttributes1, CancellationSignal cancellationSignal, LayoutResultCallback layoutResultCallback, Bundle bundle) {
        this.delegate.onLayout(printAttributes, printAttributes1, cancellationSignal, layoutResultCallback, bundle);
    }

    @Override
    public void onWrite(PageRange[] pageRanges, ParcelFileDescriptor parcelFileDescriptor, CancellationSignal cancellationSignal, WriteResultCallback writeResultCallback) {
        this.delegate.onWrite(pageRanges, parcelFileDescriptor, cancellationSignal, writeResultCallback);
    }

    public void onFinish() {
        delegate.onFinish();
        System.out.println("File is stored in this address: " + ADDRESS???!!!!!);
    while (!pj.isCompleted() && !pj.isCancelled() ){
            System.out.println("Print job is finished: " + pj.isCompleted() + "; canceled: " + pj.isCancelled());
        }
        if(pj.isCompleted()) {
            System.out.println("Print job is finished: " + pj.isCompleted() + "; canceled: " + pj.isCancelled());
            startShareIntent(null);
        }
    }
}

Is there any way to get the final address where the PDF file is stored? I need that to attache the file to an email programmatically after saving the file.

========= EDIT ==========

onFinish() does not catch the end of Print Job so I added some basic code to wait until the print job is either finished or canceled



from How to get the final address to the PDF file stored by PrintManager.print

No comments:

Post a Comment