Nbconvert: how to change pdf title

Created on 19 Feb 2016  路  14Comments  路  Source: jupyter/nbconvert

Besides changing the name of the ipynb file, is there any way to change the title of the saved pdf?

I know that I could first convert the file to .tex and compile the latex file by myself. But this is not what I want. I am looking for an automatic solution.

docs LaTeX question

Most helpful comment

672 Defines a way for this to be set.

From Jupyter notebook: Edit -> Edit Notebook Metadata then add a new field like:

"title":"This is the new title",

Tagging this as documentation.

All 14 comments

There is no (simple) automatic solution.
You need a custom conversion pipeline.

The simple way is to use a preprocessor. append it to the list of preprocessor add change resource['metadata']['name'] to the title you like.

Now there is a way for you to do this: use the --output flag

For example:

jupyter nbconvert mynotebookname.ipynb --to pdf --output yourpdftitle.pdf

@randy3k, when you mentioned pdf title, is it the title in the first page of the pdf, not the filename of the pdf as mentioned by @mpacer? Did you get any way of doing this?

@liushapku yes, it is what I meant. Not sure why @mpacer closed it. I had to convert it to .tex and fixed it myself.

sorry! Misunderstood!

@randy3k I have the same need. Currently, I use the API and call exporter.from_notebook_node(nb, resources={'metadata': {'name': title}}) to achieve this. An alternative way is to call preprocessor.preprocess and pass the resource as the second argument. Hope this feature can be added to the cmdline tool.

672 will make it easier if you set the title metadata in the notebook itself (meaning that exporter.from_notebook_node(nb, resources={}) would work if you had already set the notebook metadata.title field.

Hi,
I am new to this. Can someone explain in a bit detail, how to convert ipynb to .tex to pdf file with custom title. I an using jupyter for creating ipynb files.

@agarnitin86 I know my answer comes late, but for the others that would have had the same question :

  • File > Export Notebook As... > Latex
  • you will get a zip file ; extract it somewhere
  • open the .tex file inside : you will see something like :

% Document parameters \title{TITLE_YOU_WANT_TO_CHANGE}

  • edit TITLE_YOU_WANT_TO_CHANGE to the title of your choice

I used the following commands in a Makefile (Ubuntu):

notebook:
    cp $(file).ipynb '$(title).ipynb'
    jupyter nbconvert '$(title).ipynb' --to=pdf --output=$(file)
    rm '$(title).ipynb'

Then call it with:

make notebook file=yourfile title="Your Title"

Basically, copy the file you want to re-title to a file with the name of the title. Convert it, then delete the copied notebook. You can use quotes around the filename if you need to add spaces.

672 Defines a way for this to be set.

From Jupyter notebook: Edit -> Edit Notebook Metadata then add a new field like:

"title":"This is the new title",

Tagging this as documentation.

@t-makaro's solution works perfectly, an UI option for setting the title would be great, but apart from that this issue could be closed I guess.

:)

672 Defines a way for this to be set.

From Jupyter notebook: Edit -> Edit Notebook Metadata then add a new field like:

"title":"This is the new title",

Tagging this as documentation.

Good point @t-makaro. Looking into the code, I also found out how to change the author:

{
  "kernelspec": {
  },
  "language_info": {
  },
  "title": "It's a woodpecker from space",
  "authors": [
    { "name": "Jorge Gustavo Rocha"  },
    { "name": "Matilde Rocha" }
  ]
}
Was this page helpful?
0 / 5 - 0 ratings