diff --git a/sphinx_gallery/gen_rst.py b/sphinx_gallery/gen_rst.py
index 5d632a5..4100482 100644
--- a/sphinx_gallery/gen_rst.py
+++ b/sphinx_gallery/gen_rst.py
@@ -857,12 +857,13 @@ def save_rst_example(example_rst, example_file, time_elapsed,
 
     binder_text = (" or to run this example in your browser via Binder"
                    if len(binder_conf) else "")
-    example_rst = (".. note::\n"
-                   "    :class: sphx-glr-download-link-note\n\n"
-                   "    Click :ref:`here <sphx_glr_download_{0}>` "
-                   "to download the full example code{1}\n"
-                   ".. rst-class:: sphx-glr-example-title\n\n"
-                   ".. _sphx_glr_{0}:\n\n"
+    example_rst = (".. only:: html\n\n"
+                   "    .. note::\n"
+                   "        :class: sphx-glr-download-link-note\n\n"
+                   "        Click :ref:`here <sphx_glr_download_{0}>` "
+                   "    to download the full example code{1}\n"
+                   "    .. rst-class:: sphx-glr-example-title\n\n"
+                   "    .. _sphx_glr_{0}:\n\n"
                    ).format(ref_fname, binder_text) + example_rst
 
     if time_elapsed >= gallery_conf["min_reported_time"]:

diff --git a/sphinx_gallery/tests/test_gen_rst.py b/sphinx_gallery/tests/test_gen_rst.py
index 911fc6c..d0d0602 100644
--- a/sphinx_gallery/tests/test_gen_rst.py
+++ b/sphinx_gallery/tests/test_gen_rst.py
@@ -417,6 +417,16 @@ def test_remove_config_comments(gallery_conf):
     assert '# sphinx_gallery_thumbnail_number = 1' not in rst
 
 
+def test_download_link_note_only_html(gallery_conf):
+    """Test html only directive for download_link."""
+    rst = _generate_rst(gallery_conf, 'test.py', CONTENT)
+    download_link_note = (".. only:: html\n\n"
+                          "    .. note::\n"
+                          "        :class: sphx-glr-download-link-note\n\n"
+                          )
+    assert download_link_note in rst
+
+
 @pytest.mark.parametrize('ext', ('.txt', '.rst', '.bad'))
 def test_gen_dir_rst(gallery_conf, fakesphinxapp, ext):
     """Test gen_dir_rst."""

Remove the note linking to the download section at the beginning of the example from latex/pdf output
For latex/pdf output, this note at the beginning of the example linking to the download section does not link to anything (since there are no download buttons). Would it be possible to disable it in that case? The straightforward way would be wrap it into a `.. only:: html` directive.
sphinx_gallery/tests/test_gen_rst.py::test_download_link_note_only_html
sphinx_gallery/tests/test_gen_rst.py::test_split_code_and_text_blocks sphinx_gallery/tests/test_gen_rst.py::test_bug_cases_of_notebook_syntax sphinx_gallery/tests/test_gen_rst.py::test_direct_comment_after_docstring sphinx_gallery/tests/test_gen_rst.py::test_final_rst_last_word sphinx_gallery/tests/test_gen_rst.py::test_rst_block_after_docstring sphinx_gallery/tests/test_gen_rst.py::test_rst_empty_code_block sphinx_gallery/tests/test_gen_rst.py::test_script_vars_globals sphinx_gallery/tests/test_gen_rst.py::test_codestr2rst sphinx_gallery/tests/test_gen_rst.py::test_extract_intro_and_title sphinx_gallery/tests/test_gen_rst.py::test_md5sums sphinx_gallery/tests/test_gen_rst.py::test_fail_example sphinx_gallery/tests/test_gen_rst.py::test_custom_scraper_thumbnail_alpha sphinx_gallery/tests/test_gen_rst.py::test_remove_config_comments sphinx_gallery/tests/test_gen_rst.py::test_gen_dir_rst[.txt] sphinx_gallery/tests/test_gen_rst.py::test_gen_dir_rst[.rst] sphinx_gallery/tests/test_gen_rst.py::test_gen_dir_rst[.bad] sphinx_gallery/tests/test_gen_rst.py::test_pattern_matching sphinx_gallery/tests/test_gen_rst.py::test_thumbnail_number[# sphinx_gallery/tests/test_gen_rst.py::test_thumbnail_number[#sphinx_gallery_thumbnail_number sphinx_gallery/tests/test_gen_rst.py::test_thumbnail_number[ sphinx_gallery/tests/test_gen_rst.py::test_zip_notebooks sphinx_gallery/tests/test_gen_rst.py::test_rst_example sphinx_gallery/tests/test_gen_rst.py::test_output_indentation sphinx_gallery/tests/test_gen_rst.py::test_empty_output_box sphinx_gallery/tests/test_gen_rst.py::test_capture_repr[assign,()] sphinx_gallery/tests/test_gen_rst.py::test_capture_repr[var,()] sphinx_gallery/tests/test_gen_rst.py::test_capture_repr[print(var),()] sphinx_gallery/tests/test_gen_rst.py::test_capture_repr[print+var,()] sphinx_gallery/tests/test_gen_rst.py::test_capture_repr[assign,(repr)] sphinx_gallery/tests/test_gen_rst.py::test_capture_repr[var,(repr)] sphinx_gallery/tests/test_gen_rst.py::test_capture_repr[print(var),(repr)] sphinx_gallery/tests/test_gen_rst.py::test_capture_repr[print+var,(repr)] sphinx_gallery/tests/test_gen_rst.py::test_capture_repr[repr_and_html,(repr)] sphinx_gallery/tests/test_gen_rst.py::test_capture_repr[print sphinx_gallery/tests/test_gen_rst.py::test_capture_repr[repr_only,(html)] sphinx_gallery/tests/test_gen_rst.py::test_capture_repr[repr_and_html,(html)] sphinx_gallery/tests/test_gen_rst.py::test_capture_repr[repr_and_html,(html,repr)] sphinx_gallery/tests/test_gen_rst.py::test_capture_repr[repr_and_html,(repr,html)] sphinx_gallery/tests/test_gen_rst.py::test_capture_repr[repr_only,(html,repr)]