How to obtain URL to paper PDF

Hello,

I’m confused with obtaining download URL for paper pdf. Now, I use following code, but it don’t produce correct one

 foreach ($articleFileDao->getBySubmissionId($article->getId())->toArray() as $files) {
   $url = 'http://' . $_SERVER['HTTP_HOST'] . pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME);
   $url .= "/index.php/$jpath/article/view/" . $article->getId() . '/' . $files->getSubmissionId();
   XMLCustomWriter::createChildWithText($doc, $lang_version, 'pdfFileUrl', $url, true);
   }

for more details, please look at github

Hi @a-vodka,

Because OJS needs to operate with disable_path_info set to either On or Off, which results in URLs being generated differently, it’s best to use the built-in URL generation tools. To do this, you can call e.g.:

 $url = $request->url(null, 'article', 'view', $article->getBestArticleId());

Regards,
Alec Smecher
Public Knowledge Project Team

Dear @asmecher

Thank you for your reply.

This code gives url to paper page, not for pdf file. Is it possible to get link to pdf file?

Hi @a-vodka,

There may be none, one, or many PDF files uploaded, so you’ll need to try to find one and identify the best candidate. See e.g. this snippet:

Regards,
Alec Smecher
Public Knowledge Project Team