0

I use this document to create a Pdf file. By hitting a button to create a pdf file, Pdf-Viewer opens the created pdf automatically. I would like to know where that temporary file is saved in the device to get its path and share with socials using ACTION_SEND Intent.

How can I get the created pdf file from below code?

@Override
public void onLayout(PrintAttributes oldAttributes,
          PrintAttributes newAttributes,
          CancellationSignal cancellationSignal,
          LayoutResultCallback callback,
          Bundle metadata) {

myPdfDocument = new PrintedPdfDocument(context, newAttributes);

pageHeight = 
            newAttributes.getMediaSize().getHeightMils()/1000 * 72;
pageWidth = 
            newAttributes.getMediaSize().getWidthMils()/1000 * 72;

if (cancellationSignal.isCanceled() ) {
    callback.onLayoutCancelled();
    return;
}

if (totalpages > 0) {
   PrintDocumentInfo.Builder builder = new PrintDocumentInfo
      .Builder("print_output.pdf") // where is the path for this file
      .setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT)
      .setPageCount(totalpages);

   PrintDocumentInfo info = builder.build();
   callback.onLayoutFinished(info, true);
} else {
   callback.onLayoutFailed("Page count is zero.");
}
}
Davoud
  • 2,576
  • 1
  • 32
  • 53

2 Answers2

0

I don't know about this library but I was used iText Library for create pdf in Android application. This library provide all mathod for pdf create or add different things in pdf file. this is link for iText library for android

in this library we need to enter output file path. so easily we get the path of created pdf file path.

Gunavant Patel
  • 1,413
  • 1
  • 13
  • 17
0

The pdf is saved in the system's PrintSpooler (app)'s storage so it is not externally accessible (you can see the path on the device logs during a print). It is also copied to the underlying Print Service's storage (if the user ends up using an installed Print Service) using the getDocument method.

Nonos
  • 2,450
  • 2
  • 23
  • 34