47
calibre User Manual, Release 2.57.1
particular for the iPhone/Android phones, choose the SONY output profile. If you know your EPUB files will not be
read on a SONY orsimilar device, use the default output profile. If you are producing MOBIfiles thatare notintended
for the Kindle,choose the Mobipocket books output profile.
The Output profile also controls the screen size. This will cause,for example,images to be auto-resized tobe fit to the
screen in some output formats. So choose a profile of a device that has a screen size similar to your device.
1.4.4 Heuristic Processing
Heuristic Processingprovides a variety offunctions which canbe usedto tryanddetect andcorrect common problems
in poorly formatted input documents. Use these functions if your input document suffers from poor formatting.
Because these functions rely on common patterns, be aware that in some cases an option may lead to worse results,
so use with care. As an example, several of these options will remove all non-breaking-space entities, or may include
false positive matches relating to the function.
Enable heuristic processing This option activates calibre’s Heuristic Processing stage of the conversion pipeline.
This must be enabled in order for various sub-functions to be applied
Unwrap lines Enabling this optionwill causecalibre to attempt to detect and correct hard line breaks that exist within
adocument using punctuation clues and line length. calibre will first attempt to detect whether hard line breaks
exist, if they do not appear to exist calibre will not attempt to unwrap lines. The line-unwrap factor can be
reduced if you want to ‘force’calibre tounwrap lines.
Line-unwrap factor This option controls the algorithm calibre uses to remove hard line breaks. For example, if the
value of this option is 0.4, that means calibre will remove hard line breaks from the end of lines whose lengths
are less than the length of 40% ofall lines in the document. If your document only has a few line breaks which
need correction, then this value should be reduced to somewhere between 0.1 and 0.2.
Detect and markup unformatted chapter headings andsub headings Ifyour document does not have chapterhead-
ings and titles formatted differently from the rest of the text, calibre can use this option to attempt detection
them and surround themwith heading tags. <h2>tags are used forchapter headings; <h3> tags are usedfor any
titles that are detected.
This function will not create a TOC, but in many cases it will cause calibre’s default chapter detection settings
to correctly detect chapters and build a TOC. Adjust the XPath under Structure Detection if a TOC is not
automatically created. If there are no otherheadings used in the document then setting “//h:h2” underStructure
Detection would be the easiest way to create a TOC forthe document.
The inserted headings are not formatted, to apply formatting use the Extra CSS option under the Look and Feel
conversion settings. For example, to center heading tags, use the following:
h2, h3 { text-align: center }
Renumber sequences of <h1>or <h2> tags Some publishers format chapter headings using multiple <h1> or <h2>
tags sequentially. calibre’s default conversion settings will cause such titles to be split into two pieces. This
optionwill re-number the heading tags to prevent splitting.
Delete blank lines between paragraphs This option will cause calibre to analyze blank lines included within the doc-
ument. If every paragraph is interleaved with a blank line, then calibre will remove all those blank paragraphs.
Sequences of multiple blank lines will be considered scene breaks and retained as a single paragraph. This op-
tion differs from the ‘Remove Paragraph Spacing’ option under ‘Look and Feel’ in that it actually modifies the
HTML content, while the other option modifies the document styles. This option can also remove paragraphs
which were inserted using calibre’s ‘Insert blank line’option.
Ensure scene breaks are consistently formatted With this option calibre will attempt to detect common scene-break
markers and ensure that they are center aligned. ‘Soft’ scene break markers, i.e. scene breaks only defined by
extra white space, are styled to ensure that they will not be displayed in conjunction with page breaks.
1.4. Ebook Conversion
59
45
calibre User Manual, Release 2.57.1
Replace scene breaks If this option is configured then calibre will replace scene break markers it finds with the re-
placement text specified by the user. Please note that some ornamental characters may not be supported across
all reading devices.
In general you should avoid using html tags, calibre will discard any tags and use pre-defined markup. <hr
/> tags, i.e. horizontal rules, and <img> tags are exceptions. Horizontal rules can optionally be specified
with styles, if you choose to add your own style be sure to include the ‘width’ setting, otherwise the style
information will be discarded. Image tags can used, but calibre does not provide the ability to add the image
during conversion,this must be done after the fact using the ‘Edit Book’feature.
Example image tag (place the image withinan ‘Images’folder inside the epubafter conversion):
<img style=”width:10%” src=”../Images/scenebreak.png” />
Example horizontal rule with styles: <hr style=”width:20%;padding-top: 1px;border-top: 2px
ridge black;border-bottom: 2px groove black;”/>
Remove unnecessary hyphens calibre will analyze all hyphenated content in the document when this option is en-
abled. The document itselfis usedas a dictionary foranalysis. This allows calibre toaccurately remove hyphens
for any words in the document in any language, along with made-up and obscure scientific words. The primary
drawback is words appearing only a single time in the document will not be changed. Analysis happens in
two passes, the first pass analyzes line endings. Lines are only unwrapped if the word exists with or without a
hyphenin the document. The second pass analyzes all hyphenated words throughout the document, hyphens are
removed if the word exists elsewhere in the document without a match.
Italicize commonwords and patterns When enabled, calibre will look for common words and patterns that denote
italics and italicize them. Examples are common text conventions such as ~word~ orphrases that should gener-
ally be italicized, e.g. latin phrases like ‘etc.’ or‘et cetera’.
Replace entity indents with CSS indents Some documents use a convention of defining text indents using non-
breaking space entities. When this option is enabled calibre will attempt to detect this sort of formatting and
convert them to a 3% text indent using css.
1.4.5 Search & Replace
These options are useful primarily for conversion of PDF documents or OCR conversions, though they can also be
used to fix many document specific problems. As an example, some conversions can leaves behind page headers and
footers in the text. These options use regular expressions to try and detect headers, footers, or other arbitrary text
and remove or replace them. Remember that they operate on the intermediate XHTML produced by the conversion
pipeline. There is a wizard to help you customize the regular expressions for your document. Click the magic wand
beside the expression box, and click the ‘Test’ button after composing your search expression. Successful matches
will be highlighted in Yellow.
The search works by using a python regular expression. All matched text is simply removed from the document or
replaced using the replacement pattern. The replacement pattern is optional,ifleft blank thentextmatching the search
pattern will be deleted fromthe document. You can learn more about regularexpressions and theirsyntax atAllabout
using regular expressions in calibre(page161).
1.4.6 Structure Detection
Structure detection involves calibre trying its best to detect structural elements in the input document, when they are
not properly specified. For example, chapters, page breaks, headers, footers, etc. As you can imagine, this process
varies widely from book to book. Fortunately, calibre has very powerful options to control this. With power comes
complexity,but if once youtake the time to learn the complexity, you will find it well worth the effort.
60
Chapter 1. Sections
44
calibre User Manual, Release 2.57.1
Chapters and page breaks
calibre has two sets of options for chapter detection and inserting page breaks. This can sometimes be slightly
confusing, as by default, calibre will insert page breaks before detected chapters as well as the locations detected by
the page breaks option. The reason forthis is that there are oftenlocation where page breaks should be insertedthat are
not chapter boundaries. Also,detected chapters can be optionally inserted into the auto generated Table of Contents.
calibre uses XPath, a powerful language to allow the user to specify chapter boundaries/page breaks. XPath can seem
alittle daunting to use at first, fortunately, there is aXPathtutorial(page 129) in the User Manual. Remember that
Structure Detection operates on the intermediate XHTML produced by the conversion pipeline. Use the debug option
described in theIntroduction (page 54) to figure out the appropriate settings for your book. There is also a button for
aXPath wizard to help with the generation of simple XPath expressions.
By default,calibre uses the following expression for chapter detection:
//
*
[((name()='h1' or name()='h2') ) and re:test(., , 'chapter|book|section|part\s+', 'i')) or @class = 'chapter']
This expression is rathercomplex,because ittries tohandlea numberofcommon cases simultaneously. What itmeans
is that calibre willassume chapters start at either <h1> or <h2> tags that haveanyofthewords (chapter,book,section
or part) in them or that have the class=”chapter” attribute.
Arelated option is Chapter mark, which allows you tocontrol what calibre does when itdetects a chapter. By default,
it will insert a page break before the chapter. You can have it insert a ruled line instead of, or in addition to the page
break. You can also have it do nothing.
The default setting for detecting page breaks is:
//
*
[name()='h1' or name()='h2']
which means that calibre will insert page breaks before every <h1> and <h2> tag by default.
Note: The default expressions may change depending on the input format you are converting.
Miscellaneous
There are a few more options in this section.
Insert metadata as page at start ofbook One of the great things about calibre is that it allows you to maintain very
complete metadata about all of your books, for example,a rating, tags, comments,etc. This option will create a
single page with all this metadata and insert it into the converted ebook, typically just after the cover. Think of
it as a way tocreate your own customised book jacket.
Remove first image Sometimes,the sourcedocumentyou areconvertingincludes the coveras partofthe book,instead
of as a separate cover. If you also specify a cover in calibre,thenthe converted book will have two covers. This
option will simply remove the first image from the source document, thereby ensuring that the converted book
has only one cover, the one specifiedin calibre.
1.4.7 Table of Contents
When the input document has a Table of Contents in its metadata, calibre will just use that. However, a number of
older formats either do not support a metadata based Table of Contents, or individual documents do not have one. In
these cases, the options inthis sectioncan helpyouautomatically generate a Table of Contents inthe convertedebook,
based on the actual content in the input document.
1.4. Ebook Conversion
61
49
calibre User Manual, Release 2.57.1
Note: Using these options can be a little challenging to get exactly right. If you prefer creating/editing the Table
of Contents by hand, convert to the EPUB or AZW3 formats and select the checkbox at the bottom of the Table of
Contents section of the conversion dialog that says Manually fine-tune the Table of Contents after conversion. This
will launch the ToC Editor tool afterthe conversion. It allows you to create entries in the Table of Contents by simply
clicking the place in the book where you want the entry to point. You can also use the ToC Editor by itself, without
doing a conversion. Go to Preferences->Toolbars and add the ToC Editor to the main toolbar. Then just select the
book you want to edit and click the ToC Editor button.
Thefirst optionis Forceuse of auto-generatedTable of Contents. Bycheckingthis optionyoucanhavecalibreoverride
any Table of Contents found in the metadata of the input document with the auto generatedone.
The default way that the creation of the auto generated Table ofContents works is that, calibre will first try to add any
detected chapters to the generated table of contents. You can learn how to customize the detection of chapters in the
Structure Detection(page60)sectionabove.Ifyoudonotwanttoincludedetectedchaptersinthegeneratedtableof
contents, check the Do not add detected chapters option.
If less than the Chapter threshold number ofchapters were detected, calibre willthenaddanyhyperlinks it finds in the
inputdocument to the Table of Contents. This oftenworks well many input documents include a hyperlinked Table of
Contents right at the start. The Number of links option can be used to control this behavior. Ifset to zero, no links are
added. Ifset to a number greaterthan zero, at most that numberof links is added.
calibre will automatically filterduplicates from the generated Table of Contents. However,ifthere are some additional
undesirable entries, you can filter them using the TOC Filter option. This is a regular expression that will match the
title of entries in the generated table of contents. Whenever a match is found, it will be removed. For example, to
remove all entries titles “Next” or“Previous” use:
Next|Previous
The Level 1,2,3 TOC options allow you to create a sophisticated multi-level Table of Contents. They are XPath
expressions that match tags in the intermediate XHTML produced by the conversion pipeline. See theIntroduction
(page 54) for how to get access to this XHTML. Also read theXPathTutorial(page 129), to learn how to construct
XPath expressions. Next to each option is a button that launches a wizard to help with the creation of basic XPath
expressions. The following simple example illustrates how to use these options.
Suppose you have an input document that results in XHTML that look like this:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sample document</title>
</head>
<body>
<h1>Chapter 1</h1>
...
<h2>Section 1.1</h2>
...
<h2>Section 1.2</h2>
...
<h1>Chapter 2</h1>
...
<h2>Section 2.1</h2>
...
</body>
</html>
Then, we set the options as:
62
Chapter 1. Sections
44
calibre User Manual, Release 2.57.1
Level 1 TOC : //h:h1
Level 2 TOC : //h:h2
This will result in an automatically generated two level Table ofContents that looks like:
Chapter 1
Section 1.1
Section 1.2
Chapter 2
Section 2.1
Warning: Not all outputformats support a multi level Table of Contents. You should first try with EPUB Output.
Ifthat works, then try your format of choice.
1.4.8 Using images as chapter titles when converting HTML input documents
Suppose you want to use an image as your chapter title, but still want calibre to be able to automatically generate a
Table of Contents foryou from the chapter titles. Use the following HTML markup to achieve this
<html>
<body>
<h2>Chapter 1</h2>
<p>chapter 1 text...</p>
<h2 title="Chapter 2"><img src="chapter2.jpg" /></h2>
<p>chapter 2 text...</p>
</body>
</html>
Set the Level 1 TOC setting to//h:h2. Then,forchaptertwo, calibre will take the title fromthe value of the title
attribute on the <h2> tag, since the tag has no text.
1.4.9 Using tag attributes to supply the text for entries in the Table of Contents
If you have particularly long chapter titles and want shortened versions in the Table of Contents, you can use the title
attribute to achieve this,for example:
<html>
<body>
<h2 title="Chapter 1">Chapter 1: Some very long title</h2>
<p>chapter 1 text...</p>
<h2 title="Chapter 2">Chapter 2: Some other very long title</h2>
<p>chapter 2 text...</p>
</body>
</html>
Set theLevel1 TOC settingto//h:h2/@title. Then calibrewilltakethe titlefromthevalueofthe title attribute
on the <h2> tags, instead of using the text inside the tag. Note the trailing /@title on the XPath expression, you
can use this formto tell calibre to get the text from any attribute you like.
1.4.10 How options are set/saved for Conversion
There are two places where conversion options can be set in calibre. The first is in Preferences->Conversion. These
settings are the defaults for the conversion options. Whenever you try to convert a new book, the settings set here will
be used by default.
1.4. Ebook Conversion
63
42
calibre User Manual, Release 2.57.1
You can also change settings in the conversion dialog for each book conversion. When you convert a book, calibre
remembers the settings you used for that book, so that if you convert it again, the saved settings for the individual
book will take precedence over the defaults set in Preferences. You can restore the individual settings to defaults by
using the Restore to defaults button in the individual book conversion dialog. You can remove the saved settings for a
group ofbooks by selecting all the books and thenclickingthe edit metadata button tobring up the bulk metadata edit
dialog, near the bottom of the dialog is an option to remove stored conversion settings.
When you Bulk Convert a set of books, settings are taken in the following order (last one wins):
• Fromthe defaults set in Preferences->Conversion
• Fromthe saved conversion settings for each book being converted (if any). This can be turned off bythe option
in the top left corner ofthe Bulk Conversion dialog.
• Fromthe settings set in the Bulk conversion dialog
Note that the finalsettings foreachbook ina Bulk Conversionwill be saved and re-used ifthe book is converted again.
Since the highest priority inBulkConversion is given to the settings in the Bulk Conversion dialog,thesewill override
any book specific settings. So you should only bulk convert books together that need similar settings. The exceptions
are metadata and input format specific settings. Since the Bulk Conversion dialog does not have settings for these two
categories,they will be taken frombook specific settings (if any) or the defaults.
Note: You can see the actual settings used during any conversion by clicking the rotating icon in the lower right
cornerandthendouble clickingthe individualconversion job. This willbring up a conversion log that will contain the
actual settings used, near the top.
1.4.11 Format specific tips
Here you will find tips specific to the conversion of particular formats. Options specific to particular format, whether
inputoroutputare available in the conversion dialog undertheirown section, forexample TXT Input orEPUB Output.
Convert Microsoft Word documents
calibre can automatically convert .docx files created by Microsoft Word 2007 and newer. Just add the file to calibre
and click convert (make sure you are running the latest versionof calibre as support for .docx files is very new).
Note: There is ademo.docxfile
25
that demonstrates the capabilities of the calibre conversion engine. Just download
it and convert it to EPUB or AZW3 to see what calibre can do.
calibre will automatically generate a Table of Contents based on headings if you mark your headings with the
Heading 1, Heading 2, etc. styles in Word. Open the output ebook in the calibre viewer and click the Table
ofContents button to viewthe generated Table of Contents.
Older .doc files
For older.doc files, you can save the document as HTML with Microsoft Word and then convert the resulting HTML
file with calibre. When saving as HTML, be sure to use the “Save as Web Page, Filtered” option as this will produce
clean HTML that will convert well. Note that Word produces really messy HTML,converting it can take a long time,
so be patient. If you have a newer version of Word available, you can directly save it as docx as well.
25
http://calibre-ebook.com/downloads/demos/demo.docx
64
Chapter 1. Sections
46
calibre User Manual, Release 2.57.1
Anotheralternative is to usethefree OpenOffice. Open your .doc file inOpenOffice and save it inOpenOffice’s format
.odt. calibre can directly convert .odt files.
Convert TXT documents
TXT documents have no well defined way to specify formatting like bold, italics, etc, or document structure like
paragraphs, headings, sections and so on, but there are a variety of conventions commonly used. By default calibre
attempts automatic detection ofthe correct formatting and markup based on those conventions.
TXT input supports a number of options to differentiate howparagraphs are detected.
Paragraph Style: Auto Analyzes the text file and attempts to automatically determine how paragraphs
are defined. This option will generally work fine, if you achieve undesirable results try one of the
manual options.
Paragraph Style: Block Assumes one or more blank lines are a paragraph boundary:
This is the first.
This is the
second paragraph.
Paragraph Style: Single Assumes that every line is a paragraph:
This is the first.
This is the second.
This is the third.
Paragraph Style: Print Assumes that every paragraph starts with an indent (either a tab or 2+ spaces).
Paragraphs end when the next line that starts with an indent is reached:
This is the
first.
This is the second.
This is the
third.
Paragraph Style: Unformatted Assumes that the document has no formatting, but does use hard line
breaks. Punctuation and median line length are used to attempt to re-create paragraphs.
Formatting Style: Auto Attempts to detect the type of formatting markup being used. If no markup is
used then heuristic formatting will be applied.
Formatting Style: Heuristic Analyzes the document for common chapter headings, scene breaks, and
italicized words and applies the appropriate html markup during conversion.
Formatting Style: Markdown calibre also supports running TXT input though a transformation prepro-
cessor known as markdown. Markdown allows forbasic formatting to be addedto TXT documents,
such as bold, italics, section headings, tables, lists, a Table of Contents, etc. Marking chapter head-
ings with a leading # and setting the chapter XPath detection expression to “//h:h1” is the easiest
way to have a proper table of contents generated from a TXT document. You can learn more about
the markdown syntax atdaringfireball
26
.
Formatting Style: None Applies no special formattingto the text, the document is converted tohtmlwith
no other changes.
26
http://daringfireball.net/projects/markdown/syntax
1.4. Ebook Conversion
65
42
calibre User Manual, Release 2.57.1
Convert PDF documents
PDF documents are one of the worst formats to convert from. They are a fixed page size and text placement format.
Meaning, it is very difficult to determine where one paragraph ends and another begins. calibre will try to unwrap
paragraphs using a configurable, Line Un-Wrapping Factor. This is a scale used to determine the length at which a
line should be unwrapped. Validvalues are a decimal between 0 and 1. The default is 0.45,just underthe median line
length. Lowerthis value to include more text in the unwrapping. Increase to include less. You can adjust this value in
the conversion settings under PDF Input.
Also, they often have headers and footers as part of the document that will become included with the text. Use the
Search and Replace panel to remove headers and footers to mitigate this issue. If the headers and footers are not
removed from the text it can throw off the paragraph unwrapping. To learn how to use the header and footer removal
options, readAllaboutusingregularexpressionsincalibre(page 161).
Some limitations of PDF input are:
• Complex,multi-column,and image based documents are not supported.
• Extraction ofvector images and tables fromwithin the document is also not supported.
• SomePDFs use special glyphs torepresentll orff orfi,etc. Conversionofthese may ormaynot work depending
on just how they are represented internally in the PDF.
• Links and Tables ofContents are not supported
• PDFs that use embedded non-unicode fonts to represent non-English characters will result in garbled output for
those characters
• Some PDFs are made up of photographs of the page with OCRed text behind them. In such cases calibre uses
the OCRed text,which can be very different fromwhat you see when you view the PDFfile
• PDFs that are used to display complex text, like right to left languages and math typesetting will not convert
correctly
To re-iterate PDF is a really,really bad format to use as input. Ifyou absolutely must use PDF,then be prepared for
an output ranging anywhere from decent to unusable,depending on the input PDF.
Comic Book Collections
Acomic book collection is a .cbc file. A .cbc file is a zip file that contains other CBZ/CBR files. In addition the .cbc
file must contain a simple text file called comics.txt, encoded in UTF-8. The comics.txt file must contain a list of the
comics files inside the .cbc file, in the form filename:title, as shown below:
one.cbz:Chapter One
two.cbz:Chapter Two
three.cbz:Chapter Three
The .cbc file will then contain:
comics.txt
one.cbz
two.cbz
three.cbz
calibre will automatically convert this .cbc file into a ebook with a Table of Contents pointing to each entry in
comics.txt.
66
Chapter 1. Sections
Documents you may be interested
Documents you may be interested