Risposta alle domande più comuni

Print of encrypted documents
Ultimo aggiornamento 11 mesi fa

To support the print of encrypted documents, you have to decrypt it first.

To do so, you need to change PDFViewController.printPDF as follows:

public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal,
               WriteResultCallback callback) {
   InputStream input;
   OutputStream output;
   try {
      String mDocPath = m_view.PDFGetDoc().getDocPath();
      if(!TextUtils.isEmpty(mDocPath)) {
         if(m_view.PDFGetDoc().IsEncrypted() && m_view.PDFGetDoc().SaveAs(m_parent.getContext().getFilesDir() +
               File.separator + "temp.pdf",true))
            mDocPath = m_parent.getContext().getFilesDir() + File.separator + "temp.pdf";

         input = new FileInputStream(mDocPath);
         output = new FileOutputStream(destination.getFileDescriptor());
         byte[] buf = new byte[1024];
         int bytesRead;

         // check for cancellation
         if (cancellationSignal.isCanceled()) {
            callback.onWriteCancelled();
            input.close();
            output.close();
            return;
         }

         while ((bytesRead = input.read(buf)) > 0) {
            output.write(buf, 0, bytesRead);
         }
         callback.onWriteFinished(new PageRange[]{PageRange.ALL_PAGES});

         input.close();
         output.close();
      } else
         callback.onWriteFailed(m_parent.getContext().getString(R.string.pdf_print_not_available));
   } catch (Exception e) {
      e.printStackTrace();
      callback.onWriteFailed(e.toString());
   }
}

And add the onFinish callback:

@Override
 public void onFinish() {
     super.onFinish();
    if(m_view.PDFGetDoc().IsEncrypted())
        new File(m_parent.getContext().getFilesDir() + File.separator + "temp.pdf").delete();
 }


Caricamento in corso ...