Download PDF icon in bookdown

I have a document I'm writing with bookdown. This document will only have a HTML version. However, I want to make a PDF file available for readers to download. I would like to make it available without placing a link in the text, that is, I would like to use the icon in the top bar of the book.

Everything is working locally. However, in GitHub I'm having problems. In GitHub, clicking on the PDF icon shows 404 error. But, locally, it works.

Notes:

  1. In GitHub all the content of the page is in docs/;
  2. The PDF file was named _ main.pdf and was placed inside the docs/ directory.

Note: I already tried to download: 'pdf' and download: ["_main.pdf", "PDF"] but I did not succeed. It works locally but when I send the content to GitHub it works everything; there is only an error clicking on the PDF icon in the top bar.

Below is my file _output.yml:

bookdown::gitbook:
  css: style.css
  config:
    toc:
      collapse: none
    edit: 
      link: https://github.com/prdm0/aulas_computacional/edit/master/%s
      text: "Editar"
    sharing:
      facebook: yes
      twitter: yes
      github: yes
      google: no
      linkedin: no
      weibo: no
      instapaper: no
      vk: no
      all: ['facebook', 'google', 'twitter', 'linkedin']
    toolbar:
      position: fixed
      download: 'docs/_main.pdf'
      search: yes

You may need to just rename your output pdf file without any underscore at the beginning.

See
https://help.github.com/en/articles/files-that-start-with-an-underscore-are-missing

Don't know if this is the issue, but renaming you _main.pdf to main.pdf is worth trying

1 Like

Renaming the _main.pdf file to main.pdf does not work.

I will now read the link you gave me. Anyway, if I can get a solution, I put it here.

Best regards,
Pedro Rafael.

You still have _main.pdf in your docs folder which is rendered by github pages.

This is the one access by the online bookdown; I don't know what you tried, but I meant trying setting this one to main.pdf. You may need to regenerate the book I guess.

I know, I still have _main.pdf because before my question I had already tried main.pdf, that is, I had already thought before asking here in the group.

Best regards.

Ok good to know. You can try another name though. It seem main.pdf is something special.
I tried presentation.pdf and it works

I just renamed in the fork I made:

1 Like

I believe it can be my browser. See:

This is your page after clicking the PDF icon.

Best regards

No this is normal. I just modified the name of the file in the docs folder to see why _main.pdf and main.pdf were not working. I manage to create a working link to pdf by changing the whole name to presentation.pdf. I did not touch to the bookdown files. So the link from the bookdown button did not get modified, but you can use my link above to download the pdf file.

You know need to modify accordingly the _output.yml file with a name to pdf that is ok with you and not main.pdf. Regenerate the bookdown to update the docs folder. Then check the link point to the new file.

1 Like

Here, I modified the filename for presentation.pdf and did download: ["presentation.pdf", "PDF"] in the file _ output.yml. See My GitHub.

The problem continues. Maybe I'm not understanding something, since English is not my native language.

Best regards.

Try just setting in formats like in the documentation

This should be enough

download: ["presentation.pdf"]

I will try your suggestion to consider only download: ["presentation.pdf"], but in the bookdown it says:

Thanks again.

It also says you can use several format

download: ["presentation.pdf"]
download: ["pdf"]
download: [["presentation.pdf", "PDF"]]
download: 
    - ["presentation.pdf", "PDF"]

I think you provide a mixed of those and it may create the issue.

I just try to help without rebuilding your bookdown. Know that the pdf file is accessible from gtihub pages, you just have to correctly configure your bookdown so that the button gets the correct link.

Could you leave the link working on GitHub so I can try clicking the icon here on my machine and certifying if my browser can have any influence?

download: ["presentation.pdf"] did not work here. I'll read more about it and try.

Best regrads.

I think the download field in your yaml should not be under the toolbar one. It should be under config directly.

See the example in the doc or in bookdown book yaml.

Currently, I don't think the download option you put is taken into account. Hence, no button. Just use correct indentation in yaml I guess

Now it's working. I made:

1 - Update the bookdown package;

2 - I added book_filename: "aulas_r" in the file _bookdown.yml;

3 - I entered the file aula_r.pdf in the output directory. In my case the docs directory.

4 - In _output.yml, I made download: ["pdf"].

Best regards,
prdm0.