0

I am trying to generate a pdf using rst2pdf, but keep getting the error "format not resolved, probably missing URL or undefined destination for target".

I use sphinx to generate the .rst files and am able to generate the HTML output just fine.

To generate the pdf I followed the instructions at: https://gist.github.com/alfredodeza/7fb5c667addb1c6963b9

Directory Structure: - sphinxtext
* docs
** source
** build
* test.py

Conf.py:

# -*- coding: utf-8 -*-
#
# Test documentation build configuration file, created by
# sphinx-quickstart on Fri Jun 30 12:08:40 2017.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('..\..'))


# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
    'sphinx.ext.coverage','rst2pdf.pdfbuilder']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = u'Test'
copyright = u'2017, m.a.'
author = u'm.a.'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u'1.0.0'
# The full version, including alpha/beta/rc tags.
release = u'1.0.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = []

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False


# -- Options for HTML output ----------------------------------------------

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'

# Theme options are theme-specific and customize the look and feel of a theme
# further.  For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'Testdoc'


# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
    # The paper size ('letterpaper' or 'a4paper').
    #
    'papersize': 'letterpaper',

    # The font size ('10pt', '11pt' or '12pt').
    #
    'pointsize': '10pt',

    # Additional stuff for the LaTeX preamble.
    #
    'preamble': '',

    # Latex figure (float) alignment
    #
    # 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
#  author, documentclass [howto, manual, or own class]).
latex_documents = [
    (master_doc, 'Test.tex', u'Test Documentation',
     u'm.a.', 'manual'),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
    (master_doc, 'test', u'Test Documentation',
     [author], 1)
]


# -- Options for Texinfo output -------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
#  dir menu entry, description, category)
texinfo_documents = [
    (master_doc, 'Test', u'Test Documentation',
     author, 'Test', 'One line description of project.',
     'Miscellaneous'),
]

# -- Options for pdf output -------------------------------------------

pdf_documents = [('index', u'rst2pdf', u'Sample rst2pdf doc', u'Your Name'),]
# index - master document
# rst2pdf - name of the generated pdf
# Sample rst2pdf doc - title of the pdf
# Your Name - author name in the pdf

test.py

class Test(object):
    '''
    Test class
    '''

    def __init__(self,**kwargs):
        """
        Constructor
        """



    def some_func(self,a,b,c,d,e,f,g):
        """
        Function that does something TEST

        :param a: Identifier
        :param b: b
        :param c: c
        :param d: d
        :param e: e
        :param f: f
        :param g: g
        :type a: int
        :type b: float
        :type c: float
        :type d: float
        :type e: float
        :type f: float
        :type h: float
        :returns: Test obj


        :Example:

        >>> test=Test()
        >>> test.some_func(10, 42164., 0.0, 0., -132.0, 0.0, 0.0)




        """


        self.a=a
        self.b = b
        self.c = c
        self.d = d
        self.e = e
        self.f = f
        self.g = g

        return self

When building as html I see the following warning: checking consistency... C:\PATH\docs\source\modules.rst: WARNING: document isn't included in any toctree

My index.rst file:

.. Test documentation master file, created by

sphinx-quickstart on Fri Jun 30 12:08:40 2017. You can adapt this file completely to your liking, but it should at least contain the root toctree directive.

Welcome to Test's documentation!
================================

.. toctree::
   :maxdepth: 2
   :caption: Contents:

   test


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

My test.rst:

Test Module!
================================

.. automodule:: test
   :members:
bad_coder
  • 11,289
  • 20
  • 44
  • 72
Mohammad Ahmad
  • 133
  • 1
  • 1
  • 8
  • The problem is probably what the error message indicates. You cannot have invalid links in PDF. Try building it as HTML and look for any warnings instead of errors. Maybe there is something more helpful? – Steve Piercy Jun 29 '17 at 20:25
  • When building via html the warning I see is: checking consistency... C:\PATH\docs\source\modules.rst: WARNING: document isn't included in any toctree – Mohammad Ahmad Jun 29 '17 at 20:36
  • Does `modules` exist as an entry in `index.rst`? When you add a new `.rst` file, you need to add it to a TOC list, else it won't show up in the HTML docs. See http://www.sphinx-doc.org/en/stable/markup/toctree.html – Steve Piercy Jun 29 '17 at 21:16
  • So I went ahead and modified my example to be even simpler. Now I only have a single python file that I am trying to generate documentation for. (I've edited my original question to reflect the changes). I am no longer seeing the original error I was seeing, and now see ValueError: too many values to unpack. Looking around I also saw others with this issue (https://github.com/rst2pdf/rst2pdf/pull/576), but it seems the issue was never resolved. I am running python2.7, so I don't know if there is any workaround. Is rst2pdf just not the solution? – Mohammad Ahmad Jun 30 '17 at 19:35
  • No idea. You need to provide a [MCVE](https://stackoverflow.com/help/mcve) – Steve Piercy Jun 30 '17 at 20:21

2 Answers2

1

This has now been resolved in rst2pdf via PR 619.

You can install the version of rst2pdf that has this fix by doing this:

$ cd {some directory where you keep 3rd-party projects, e.g. ~/projects}
$ git clone https://github.com/rst2pdf/rst2pdf.git
$ cd rst2pdf
$ python setup.py install
Rob Allen
  • 12,643
  • 1
  • 40
  • 49
  • this did not work for me. Are there any updates to this? – joel.wilson Jul 03 '20 at 13:08
  • @joel.wilson see my answer for a possible alternate solution. – Ian Feb 12 '21 at 01:54
  • Any updates, I still face the same error in 2022. My html build succeeds without any error, but fails for PDF generation. Although when I searched for the link in html, it is proper. What is the solution to this problem, I dont find the fix in the PR link above? – Sach Aug 03 '22 at 08:04
  • @sach: Please raise an issue on rst2pdf's GitHub with the smallest sample project you can manage, along with information on which version of rst2pdf and Sphinx that you are using. – Rob Allen Aug 04 '22 at 09:04
1

If you are still getting this message in 2021, it likely means rst2pdf can't figure out where one or more of your links is pointed. For example, I had in-page nav links in my .rst code like this that were ok when building HTML but causing the error referred to by the OP during PDF generation:

`Back to top ↑ <#top>`_

The most reliable solution seems to be to remove these in-page links.

Alternatively, you could just convert these implicit links to raw html blocks like below, which could be a solution if you can get rst2pdf to render raw html using xhtml2pdf (this isn't working for me, but perhaps someone else can get it).

.. |top| raw:: html

   <a href="#top">Back to top ↑</a>

|top|

Note that in this alternative solution, the in-page links probably will not work in most PDF viewers, so this is really only a solution to get .rst files to compile to both PDF and HTML (as the OP asked), rather than one that will allow identical behavior.

Ian
  • 172
  • 1
  • 13