Download document in local storage

@pawan.verma How are you opening the document? On Android, if you opened a local document, it stays local. If you opened a HTTPS document, it downloads to cache. So documents opened on Android is always saved locally.

Perhaps you are looking for the path to the file? Is that what you want? If you could describe on a higher level your user story or use case, we’ll be able to better suggest. Thanks.

Hi Shirley

As per my user story-

Let us suppose I open a pdf file and draw annotations on that pdf. When we click on save a copy so it should be download in “/download” folder in internal storage with all allotation.
How can we do it please help me to resolve this issue.


In this case, you can set the designated save a copy folder using ViewerConfig.Builder.saveCopyExportPath(String) .

Please keep in mind that if you are specifying the external Download folder, you app will require the proper Android storage permissions.

Hi Branden

Thanks for your response.

Please suggest me click events of save a copy.


For the click event of the save a copy button in the overflow menu, if you are using PdfViewCtrlTabHostFragment2 then you can add a listener with addHostListener and override the onToolbarOptionsItemSelected method to handle menu item clicks.

You can check out our CustomUI sample to see how menu items can be overridden.

As a side note, could you describe at a high level what you are looking to achieve by listening for these click events? We may be able to provide you a better solution if we can better understand the use case.

Hi Braden

Thank you so much for your response.

I tried, it’s exports the doc on the given path but If we export the doc with annotation, don’t know why it’s removing all annotation that we draw on the doc.

Please help me to short out this issue.


When we export the document then we are getting a dialog of “This Document has not been cropped using the “Crop Pages” action, and so a cropped copy can not be saved” and On click of “Copy Now” another dialog is opens after complete this functionality then we have to again click on save a copy button then we can export our document.

So can we skip crop page functionality while export the document ?


Download document in local storage - #10 by pawan.verma

For this issue, are you calling custom code to save the document? Would it be possible if you could send us your project so we can take a closer look at the issue?

Download document in local storage - #11 by pawan.verma

If you are saving a cropped copy of the document, then the crop dialog will show. Are you looking to hide the save crop copy option? If so, you can hide this by calling hideSaveCopyOptions in ViewerConfig

Could you tell us where you are clicking on “Copy Now” (this button is not available in our viewer)? Also, could you describe at a high level what you are looking to achieve with the saving options? We may be able to provide you a better solution if we can better understand the use case.

Hello Braden

Thanks for your response.

Actually, I did something wrong. I write export doc code in “Permanently cropped copy” so that’s why it performs cropped copy option.

Now the problem is that All Save a copy options (Identical, Flattened, Reduce File size, etc…) create a file in download path without using “saveCopyExportPath()” method but annotation is not creating. How we save that doc with exist annotation ?

So Braden what should I pass in “hideSaveCopyOptions (int[] modes)”. From where i will get the modes array, could please give me that array ? so that if my team want to hide any option so i can do that.

All Save a copy options (Identical, Flattened, Reduce File size, etc…) create a file in download path without using “saveCopyExportPath()” method but annotation is not creating.

This is unexpected. It sounds like the annotations in the document are not saving properly before exporting. Do you have any custom code when save a copy options are selected?

Would it be possible if you could send us a sample project with this issue so we can take a look? It would be very helpful to help us investigate this issue. If required, you can send your sample private via our support channel here: PDFTron Systems Inc. | Support

As for hideSaveCopyOptions, you would pass in the button ID for example:,,, (1.3 KB)

Could you please go through with this file? Whole code related to PDFTron written in this file.

Sample project can not be shared by official system.

Could you tell us why you require line 62: mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment().setSavingEnabled(false); ?

If setSavingEnabled is false, then the annotations will not be saved to the document. So when you save a copy to file path, it will not contain the annotations.

Once my preset bar was going to disappear. So I put a question on the community below is link of that question in which Shirley Gong suggest me to turn off saving using setSavingEnabled(false) and this my problem was resolve.

Second things, I removed these lines and try to export via click on Save a copy>> Identical copy with annotation. Its behaving same document is downloading but without annotation.

I see, thanks for the information.

It seems you have enabled AnnotManager in your viewer. In this case, the save options will not work by default. You will need to handle save options manually by calling AnnotManager.exportToFile(String) when the save menu button is clicked.

This exportToFile() method export all annotation on existing document but as per my user story I have to download same document with annotation in different location when we click on save a copy.

In simple words, I want to save a copy of my document with annotation in desired path. How can we do it?


It is possible to use the exportToFile function to save a copy of the file with the annotation. To do this you can specify a new target file, please see sample code below:

 File copy = new File("Your desired target file path");
 FileUtils.copyFile(currentFile, copy);

Hi Emallon

I tried this in kotlin.
val dFile=File(getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)?.getPath() + “/” + cFile.nameWithoutExtension + “.” + cFile.extension)

FileUtils.copyFile(cFile, dFile)

It creates a new file on the target path, but annotation is not exporting.


Here is an sample project with exportToFile working:

With this I am able to export my current file with annotations to a different file (asdf.pdf) in my downloads folder. Is it possible for you to provide a working sample project that shows the issue with exportToFile not behaving as you expected?


Hi Andrew

Thanks for your response.

There are many projects, Could you please tell me in which project I can get export-file-test sample.



The changes are contained within the CustomUI project folder. Here is the commit changes I made: