On any modern TeX system, assuming you are using the pdfTeX engine (which is the default on Overleaf), you can print the number of pages of an external PDF file with a macro like this:
\def\numberofpages#1{\pdfximage{#1}\the\pdflastximagepages}
where the argument is the relative path to the PDF file in question. There are versions for other engines at Get number of pages of external PDF. This part is not specific to Overleaf, you can use it on your own local TeX distribution if you want.
With documents spread across multiple Overleaf projects
The trick on Overleaf (Full disclosure: I'm on support staff at Overleaf.) then will be accessing the PDF file from your other project(s) within your summary project that's counting the pages (let's call it the summary project). This can be done by including the other projects' output files as new files in your summary project.
I would not recommend doing this, because it relies on remembering to keep all the external files updated. But if you absolutely need to do this, it can be done.
Open the summary project, then choose "New File" -> "From Another Project". Then select the project of which you want to count the pages. Under the "Select a File" dropdown, click on "select from output files" and then choose output.pdf
.
Then choose a suitable name for the output PDF file within the summary project. (This will have to be unique if you want to count the pages of multiple external pages.)
Then define the \numberofpages
macro listed above somewhere in the preamble of your summary project. Say I bring in an external PDF with a filename PaperA.pdf
, then I can print its number of pages anywhere in the summary project with
\numberofpages{PaperA.pdf}
The caveat is that as you edit your other project(s) and return to the summary project, you need to remember to "Refresh" each of your external PDF files with the button that will appear on each external PDF file you add to the summary project:
Because of the architecture of Overleaf, it's not possible for these external files to be updated automatically as the other project changes. This has to be done manually with the "Refresh" button.
With multiple documents within a single Overleaf project
If you have multiple documents within one single Overleaf project, it can be done more automatically with some combination of xr
-like code and this \numberofpages
macro or lastpage
as John mentioned in a comment. But there are other trade-offs with this method on Overleaf too, depending on exactly what you have in each of these other documents. Refer to Can I choose which file is the main tex file in a project on Overleaf for more information about compiling multiple documents within a single Overleaf project.
If you end up consolidating multiple documents into one Overleaf project, this help article shows how to use a latexmkrc
file on Overleaf to trigger other files to be compiled within a single Overleaf project: Cross referencing with the xr package in Overleaf. That article talks about it in terms of using the xr
package, but the same type of approach could be used to get an updated PDF in the project's output files area, in order to use with the \numberofpages
macro described above.
\number\Hy@pagecounter
from hyperref