Skip to content

Instantly share code, notes, and snippets.

@KojoBailey
Last active February 17, 2024 14:19
Show Gist options
  • Save KojoBailey/722d0f599a2279a6bee24ba07eaf2728 to your computer and use it in GitHub Desktop.
Save KojoBailey/722d0f599a2279a6bee24ba07eaf2728 to your computer and use it in GitHub Desktop.
My process for creating EPUB 3 digital manga

Quick copy-paste access (if you know, you know):

<spine page-progression-direction="rtl">
.calibre1 {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  margin: 0;
}

Table of Contents

My process for creating EPUB 3 digital manga

Here is my process for creating EPUB 3 digital manga with Calibre. It's not complicated, but there are little things to remember and copy-paste, hence why I've created this document - for myself and anyone else who's interested to refer to.

With this method, you will be able to...

  • easily download PNG images from MangaDex and (probably) similar sites.
  • quickly sort folders of chapters into a single stream of helpfully-named images.
  • convert these images into an EPUB 3 document with useful metadata.
  • easily customise an EPUB table of contents.
  • have the EPUB read right-to-left (like manga are supposed to be).
  • fix vertical alignment issues with the EPUB images.
  • import your EPUBs into apps (I'll be focusing on Apple Books).
  • view the EPUBs offline, with no online dependencies whatsoever.

Note that I'm very new to using Calibre, and the following process is only what I've found to be best so far. If there are things here that you know there are better or existing solutions too, please do tell!

Downloading Source Files

There are many ways to get your hands on manga pages as raw images. Of course, there are torrent sites like nyaa.si, but you're probably looking to use stuff from sites like MangaDex, as they have massive catalogs of fan-translated manga in many different languages.

To grab images from MangaDex, you'll want to install HakuNeko, available for Windows, macOS, and Linux. The Nightly release is fine, but this method will also work for the Stable version.

Once installed, go to the manga "title" page you want to download from (NOT the chapter page). This is the page containing the lists of chapters and volumes. Then, copy the URL of this page, go to HakuNeko, and click on the paste button next to the Manga List heading.

MS Paint _ Microsoft Paint Online

After that, click on the manga's title in the Manga List and wait for the Chapter List to generate (may take a while depending on the number of chapters). You can then click on the cloud icon next to each chapter you want to download, and it'll appear wherever you've designated the images to download to. Open the HakuNeko settings from the top-left if you want to check or change this path.

image

For more help with HakuNeko, refer to their official docs.

Reorganising Files

To quickly reorganise the download files for easy importing into Calibre, I've created a tool for Windows, Book Volume Organiser.

Since MangaDex downloads chapters into separate folders, this tool simply merges those folders into one, with a naming scheme that will be helpful later in the process. For example, a file created by the tool named Ch3-19 (82).png means "Chapter 3, page 19 (page 82 overall)". More specific instructions can be found in the tool's repository.

Then, you can create a ZIP file from all the images in the folder. The name of this ZIP file doesn't matter, and you can also use RAR or 7Z (.7z) if you want.

image

However, it isn't actually necessary to use the organiser. You can simply create a ZIP from the chapter folders if you want, but using the organiser will be helpful later on when defining the EPUB's table of contents.

Importing into Calibre

Calibre (or "calibre" - idk it's really inconsistent) is available on Windows, macOS, and Linux, and is the best app I know of for creating EPUB 3 files. It's also useful to have in case you want to later convert your EPUB files into other formats like MOBI for Kindle, or simpler formats like PDF.

Once you have it installed, open the app and click on "Add books" from the top-left.

MS Paint _ Microsoft Paint Online (1)

Assuming you created the ZIP file already, find it and open it. Calibre will then automatically convert it into a CBZ (comic book archive) file.

Then, find the file from the Calibre list and click on "Edit metadata", either from the button next to "Add books" or from right-clicking on the file's list item. This will open the following window:

image

In this window, you can specify many of the volume's properties. Include as much information as you'd like, and you can refer to the image above for an example from me.

Some things to keep note of:

  • In the top right, you should only have the CBZ file showing. I have an EPUB since I already converted it (see the next step!).
  • If you're unhappy with the default cover image, you can choose a custom one by clicking "Browse" under "Change cover".
  • Use the green arrows next to "Title" and "Author(s)" to automatically set the "Title sort" and "Author sort".
  • It's not super obvious, but the "Number" property refers to the volume number (e.g. 2.00 corresponds to "Volume 2"). I personally don't use the decimals, but maybe you can find a use for them somehow.
  • The "Date" and "Published" properties are a bit goofy and not-so-simple to edit via typing. I suggest you play around with it a bit to find out which way of editing it works for you.

After you're done, just click "OK" from the bottom-right.

Converting to EPUB 3

Changing Default Settings

Before converting, there are some default settings I suggest you use first.

Open Preferences > Change calibre behavior or press Ctrl + P, and first open "Output options" under "Conversion". Find "EPUB output" and change the following:

  • Enable "No default cover".
  • Enable "Preserve cover aspect ratio".
  • Enable "No SVG cover".
  • Change "EPUB version" to 3.

image

Then, go back to Preferences and open the "Input options", also under "Conversion". For this, you can just outright enable "Disable comic processing". Otherwise, the Calibre will do stuff like automatically split the pages in two, which usually wouldn't be an issue if it didn't also rotate pages and reduce the quality significantly. Issues like these can likely be fixed with more customisation, but I personally don't care for it.

image

Then, go back to Preferences and open "Common options", also under "Conversion". Go to "Page setup" and select your desired "Output profile". I just use Default profile for the most flexibility, but you can choose other options if you'd like to optimise the resolution and filesize or whatever.

image

Then, for the last time, go back to Preferences again and open "Behavior" under "Interface", in which you should set the "Preferred output format" to EPUB.

image

Conversion

Now for the actual conversion! Close all the preference windows and click on "Convert books" (next to "Edit metadata"). This will open up another window. At this point, the default settings you just set will take care of everything, so all you really need to do is...

  1. In the top-left, ensure that "Input format" is set to CBZ.
  2. In the top-right, ensure taht "Output format" is set to EPUB.
  3. Go through the different tabs and just make sure the options are what you want. If you can't understand some of the settings, you can just ignore them. I personally don't use any others than the ones I've already gone over above.
  4. Press "OK"!

Calibre will take a moment to convert the file, and once done, you'll be able to view the EPUB by right-clicking on the book and selecting Open book folder > Open book folder (or by just pressing O). You can also view the EPUB with Calibre's shaky EPUB viewer by pressing "View", but we're not done yet...

Final Touches

There are still a few issues with the EPUB to sort out before reading from it:

  • It (likely) doesn't read from right to left as a manga should.
  • Any wider pages are vertically aligned to the top when the middle would be preferred.
  • The Table of Contents has probably labeled every page as its own chapter.

Firstly, select the book in Calibre and click "Edit book" from the top-right (or press T). This will once again open a new window, this time for editing the EPUB's details.

If you find that the title page (titlepage.xhtml) and the first page (page_1.xhtml) are the same, you may just want to remove the first page altogether by deleting it, although it's up to you.

Page Direction

To fix the page direction issue, go to Miscellaneous > content.opf, open it, and find the <spine> tag. Then, add page-progression-direction="rtl" inside the tag. rtl means "right-to-left", and the EPUB likely uses ltr by default ("left-to-right") hence why we have to manually change it. Afterwards, your <spine> code should be looking something like this:

<spine page-progression-direction="rtl">
  <itemref idref="titlepage"/>
  <itemref idref="id1"/>
  <!-- etc. etc. -->
</spine>

It may even look like this if the Table of Contents decides to show up:

<spine toc="toc" page-progression-direction="rtl">
  <itemref idref="titlepage"/>
  <itemref idref="id1"/>
  <!-- etc. etc. -->
</spine>

Then, save with File > Save or by pressing Ctrl + S. You can test if the change worked by then viewing the EPUB with Calibre and seeing if pressing the left arrow takes you "forwards" in the book.

Vertical Alignment

To fix the vertical alignment issue with wider pages, go to Styles > stylesheet.css next, and replace the CSS for .calibre1 with the following:

.calibre1 {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  margin: 0;
}

It's harder to test the success of this due to how weirdly Calibre displays pages, but you should see that it works once you get to sending the EPUB to your reading device.

Configuring Table of Contents

Even if your manga download doesn't have multiple chapters, you'll still want to remove the table of contents entries since, usually, Calibre automatically detects every single page to be its own chapter - not very useful.

In the Calibre editor, click on the Edit Table of Contents button from the toolbar:

MS Paint _ Microsoft Paint Online (2)

Press Ctrl + A to select all the existing chapters and then recycle button to the right to remove them all. Then, you can just keep on creating new entries as you see fit (not gonna go into too much detail here, but it's fairly easy to figure out).

This is where Book Volume Organiser tool becomes truly useful, as you'll be able to easily see which page number corresponds to the start of which chapter! Once you're satisfied with the Table oc Contents, press "OK".

image

Sending to Apple Devices

As mentioned at the start, I use Apple Books) since I just find it to be the easiest to use personally on an Apple device (I have an iPad and an iPhone). I use a Windows laptop, but since iTunes is available for free on Windows as well, the process is no different than if I were to use a Macbook.

At this point, if you're already dedicated to another app or aren't using an Apple device to read from, you can search elsewhere for how to get your EPUB into your app's library. Otherwise...

Importing your EPUB into Apple Books is extremely simple. You will need iTunes (and I want to take a moment to say how thankful I am for the existence of this app. It's so easy to sync music, videos, books, podcasts, and more to my phone).

Plug your device into your computer via its USB charging cable, "open" the device with iTunes, go down to "Books" under "On My Device", and then simply drag your EPUB files into it. If all goes well, you'll be able to eject your device and view your manga in your Apple Books library! If not, you'll need to search for iTunes troubleshooting, although there should be minimal issues with such a simple transfer.

Conclusion

First of all, disclaimer: I'm not an Apple employee, nor am I sponsored by Apple. iTunes just ended up being the light in the dark when I was struggling to find apps that simply... worked. I do find that Apple Books is perfectly suitable for my needs, and it being completely free with no ads is obviously appreciated!

You could also modify this whole process for, say, your Kindle devices. To do so, you'd likely need to convert to a MOBI file instead of EPUB which shouldn't be too difficult. Although (as of writing this) I've only known about Calibre for 2 days, I really do find it to be amazingly flexible, even if the UI is a bit daunting.

Also, although this process is really long, note that most of it is just set-up. In reality, I can have a book downloaded and onto Apple Books in less than 10 minutes, which I find to definitely be worth the time. That being said, I'm not saying my process is perfect, and I ask that you comment with improvements/suggestions if you have any!

Otherwise, good luck, and I hope this works for you.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment