Please read. Significant change on the site that will affect compatibility [ Dismiss ]
Home » Forum » Author Hangout

Forum: Author Hangout

Coding: Resetting the first page of an eBook

Vincent Berg 🚫

Kindle and ePubs released by the mainstream publishers all have the usual front matter where it belongs—at the front of the book—but when you open the book, it immediately jumps to the first page of the story.

Does anyone here know how the hell they do that? Is there some internal coding, or some flag that I've never noticed before? Is there an html or ePub command I can add to my ePubs to ensure the document opens at the correct space?

Thanks, this might seem like a minor technical issue, but I'm sure that readers will appreciate the simple convenience. While the front matter is necessary, I'd rather not shift the "Front" matter to the ass-end of the book just to do what should be handled automatically.

Switch Blayde 🚫

@Vincent Berg

I have no idea, but maybe the default is to open it at Chapter 1 in the ToC.

Replies:   Vincent Berg
Vincent Berg 🚫

@Switch Blayde

I have no idea, but maybe the default is to open it at Chapter 1 in the ToC.

That makes sense, and it seems a logical place for the command, as I've played around with a LOT of TOC settings before, but I've never noticed anything that looks like it would handle it. I'll have to check again, though.

Dominions Son 🚫
Updated:

@Vincent Berg

Kindle and ePubs released by the mainstream publishers all have the usual front matter where it belongs—at the front of the book—but when you open the book, it immediately jumps to the first page of the story.

Actually, I have a lot of kindle books. While this is true of most, I have a couple (from traditional publishers) that open to either the TOC or the cover page. Don't know why the difference.

On the other hand, the Kindle reader app for PC and a Kindle device will remember where you were in the story if it's re-opened later. Perhaps that's the secret. The open the e-book and go to the start of chapter 1 before distributing it.

If you explictly go to begining, again most will go to the start of chapter 1, but a few will go to the cover page or the TOC. I've seen this oddity pop up even within a given publisher/author. A series of books from the same publisher/author, most on go to beginning go to the start of chapter 1, but one goes to the TOC and one to the cover page.

Replies:   Keet
Keet 🚫

@Dominions Son

On the other hand, the Kindle reader app for PC and a Kindle device will remember where you were in the story if it's re-opened later. Perhaps that's the secret. The open the e-book and go to the start of chapter 1 before distributing it.

Your reader remembers the position, it's not saved in the epub itself. So opening at chapter 1 before distribution won't make a difference.

The start point is different for epub 2 and 3:

epub 2 has a [guide[ section in the OPF file where the initial start page is set like [reference type="start" title="Chapter 1" href="..." /]

The epub 3 standard still supports the guide section but it is deprecated. With epub 3 you would use landmarks in the new nav page.

Replies:   Vincent Berg
Vincent Berg 🚫
Updated:

@Keet

Thanks, Keet, I'd managed to find a reference to the "reference type="start" tag, but there were no coding examples and I couldn't figure out WTF they were referring to. Since I'm unfamiliar with guides in ePub 2 or 3, could you either enlighten us, or suggest a reference describing how they operate? Also, where does the [quide] command go, in the header section, at the start of the text session, or in the actual chapter you wish to start at?

Geez! This is a slow process: guessing how to implement the code, converting it to the ePub via Calibre and then uploading it to the select device to test it, only to discover your code isn't even slightly valid!

I've determined that the [guide] command goes into the opf file within Calibre (or Sigil), but I've never seen one in any of my current Calibre documents? Do I have to manually create it, or am I using the wrong tool (i.e. Calibre instead of Sigil)?

Sigh! OK, the .opf file is officially a backup of a book's metadata, but every guide I've looked at warns that it should NEVER be modified, as it's a recipe for disaster (i.e. a non-recoverable book). Since I'm creating each book anew via Calibre, that's not really a concern, but I've yet to locate the .opf metafile backup in Calibre. I'm guessing it doesn't exist until after the book is created, meaning it then belongs in Sigil's sphere of influence?

By the way, to answer why some books open to the cover page instead of the first page of the story, apparently Nooks do NOT contain the required .opf metadata backup file, and thus are incapable of opening anywhere besides the opening page of the book (i.e. the cover page).

Replies:   Keet
Keet 🚫

@Vincent Berg

Since I'm unfamiliar with guides in ePub 2 or 3, could you either enlighten us, or suggest a reference describing how they operate? Also, where does the [quide] command go, in the header section, at the start of the text session, or in the actual chapter you wish to start at?

This link should help you. The guide section is part of the OPF document.

Sigh! OK, the .opf file is officially a backup of a book's metadata, but every guide I've looked at warns that it should NEVER be modified, as it's a recipe for disaster (i.e. a non-recoverable book).

Why should you be afraid to edit the OPF file? Keep a backup of the original and you can experiment all you want ;)

By the way, to answer why some books open to the cover page instead of the first page of the story, apparently Nooks do NOT contain the required .opf metadata backup file, and thus are incapable of opening anywhere besides the opening page of the book (i.e. the cover page).

Also some systems don't respect the 'start' reference, I think Adobe Digital Editions was one of them.

Replies:   Vincent Berg
Vincent Berg 🚫

@Keet

Why should you be afraid to edit the OPF file? Keep a backup of the original and you can experiment all you want ;)

I'm not, as I said, I regenerate new eBooks every time I make a change, rather than editing the existing books in either Calibre (unrelible) or Sigil (which is designed as an eBook editor). However, the key is figuring out HOW to access the .opf, as it's not visible anywhere, and the only documentation I can find on it starts spirling down a rabbit hole of .odt files and other things I can't comprehend.

Update: Apparently, it's impossible to edit the .opf file unless you physically decompile the book (break open the .zip file containing all the various chapter and image files, edit it and then recompile them all into a NEW .zip file and then reconstruct the book.

Sorry but that's all WAY over my head, and I'm fairly sophisticated, both in terms of html, eBooks and coding in general (although my coding experience is heavily dated).

I was looking for a workable solution, rather than lessons in how to decompile and recode an existing ebook file's structure. But, I'm guessing that there is NO simple way to achieve what I'm trying to do, which would explain why no Independent Publisher I'ver ever met does it.

Replies:   Keet
Keet 🚫
Updated:

@Vincent Berg

Update: Apparently, it's impossible to edit the .opf file unless you physically decompile the book (break open the .zip file containing all the various chapter and image files, edit it and then recompile them all into a NEW .zip file and then reconstruct the book.

Unzip is easy when you rename the .epub to .zip.
What I can do on Linux is open the zip in an archive manager, double click the file I want to edit in the presented content list, edit the file, save the file, and close the zip. All edits will be in the zipped file.

So you don't have to 'recompile' a complete epub. I can just right click an epub and select unzip from the popup menu. Everything will be unzipped into a folder. Then edit the opf file in the unzipped folder and save it. Select all files in the folder, right click, and select zip/compress/archive or whatever it's called on your system and you again have an epub. It's really quite easy.

What also works for me on Linux is rename the epub to .zip, unzip, and just edit the .opf file. Then drag the 'new' .opf file over the .zip and it will replace the existing .opf file in the zip with the new one. Rename back to .epub and you're done. Make sure you keep a backup of the original epub.

ETA: depending on what archive manager ('unzipper') you use you might even be able to just extract the opf file. This might be better if you can use the last method I mentioned (with the drag). This works because the .opf file is in the root of the epub/zip.

Lazeez Jiddan (Webmaster)

@Keet

Select all files in the folder, right click, and select zip/compress/archive or whatever it's called on your system and you again have an epub. It's really quite easy.

Not quite. These steps will result in an invalid EPUB file as the mime type string wouldn't be correct.

Some ebook readers might simply look at the extension and the files inside, and those will work.

But this will trip a lot of strict ebook readers, especially Books on iOS and Mac which will look for the mime type string at the beginning of the EPUB file.

Replies:   Keet  Vincent Berg
Keet 🚫

@Lazeez Jiddan (Webmaster)

Not quite. These steps will result in an invalid EPUB file as the mime type string wouldn't be correct.

After some more investigation I ran my test file through the IDPF validator and I got an error "Mimetype file entry is missing or is not the first file in the archive.". Since the file is there it must be because it's not the first file. So I tried again by first adding the MIME type file and then the rest of the files. The error remained the same but the epub still works perfectly on my Linux system with different ebook readers. Since I don't have any Windows or Apple systems I can't test on those.

Apparently there is a solution for this:
You can use the terminal command "zip -X0 file.epub mimetype" and then add the other files with the command "zip -9 -r file.epub META-INF OPS" (i.e. the rest of the files/folders). This tested as a correct epub file. The same zip utility is also available on Windows and Mac OSX (and a load of other systems).

How do you compress files to an epub?

Lazeez Jiddan (Webmaster)

@Keet

How do you compress files to an epub?

The system that I created has a function to write the mime type to the newly created zip archive before it adds zipped entries to it. The mime type is written as the first few characters of the file in clear/non-zipped text right after the zip archive identifier string. Like so: 'mimetypeapplication/epub+zip'; that's why you adding a mime type file doesn't work.

Replies:   Keet
Keet 🚫

@Lazeez Jiddan (Webmaster)

that's why you adding a mime type file doesn't work.

It does work, this is how:
I created a new mimetype file with an editor. I could have used an existing mimetype file but I wanted it to be original because it's a key file for an epub. I did use the rest of the 'normal' files from an existing epub because I wanted to be able to compare them with a hex editor.
I created a little bash script with just 4 lines:

tr -d 'nr' < mimetype > mimetype.2
mv mimetype.2 mimetype
zip -X0 file.epub mimetype
zip -9 -r file.epub META-INF OPS

The first 2 lines are just to remove possible ending chars from the file. By reusing an existing mimetype file this would not be necessary since they are always the same. The file should be exactly 20 bytes in size after the trimming.
The last 2 lines zip the files into a "file.epub". This new epub validates perfectly and comparing the first few dozens of bytes with a hex editor shows no differences. The file is 1.3 kB larger but that probably has to do with the compression part of the other files. All in all it works perfectly and with a script file its no work at all.

Lazeez Jiddan (Webmaster)

@Keet

It does work, this is how:

What I meant is that simply putting a mime type file in the directory and zipping the whole thing in one shot does not work.

The -X0 is for no compression, and it has to be the first file in the archive.

Replies:   Keet
Keet 🚫

@Lazeez Jiddan (Webmaster)

Ah, I misunderstood you. Agreed, just simply compressing all doesn't work.

Vincent Berg 🚫

@Lazeez Jiddan (Webmaster)

But this will trip a lot of strict ebook readers, especially Books on iOS and Mac which will look for the mime type string at the beginning of the EPUB file.

Actually, once I finally got it to work on the Mac, the book opened fine on the Mac, though of course the 'reference type="start"' command did nothing, and some of my links seem to no longer work, so maybe it's screwing with the internals.

Replies:   Keet
Keet 🚫

@Vincent Berg

though of course the 'reference type="start"' command did nothing

Did you try the landmark method? The reference=start in the guide section is deprecated so in the long run you will have to do that anyway. I did warn that the reference=start is not respected by every ereader. You could check if it works with a different ereader.

Replies:   Vincent Berg
Vincent Berg 🚫

@Keet

I did warn that the reference=start is not respected by every ereader. You could check if it works with a different ereader.

Alas, I have many files ePub/azw files that do start on the first page of the story, so it's clearly not a device limitation, and the code seems to be in the wrong place, so it code is apparently being ignore (possibly by the previously-defined document structure listing each chapter and image file in the order they'll appear.

Ernest Bywater 🚫

to edit opf in Calibre is very easy.

Open Calibre - highlight the story file - click on the menu item Edit Book. This opens a window with the list of story splits on the left, a code section then a live preview. The top of the list is each split or chapter in the book, then there's a section with the stylesheets called Styles, followed by Images, then Fonts, and last is Miscellaneous. This will have container.xml, content.opf, and toc.ncx. Depending on the size of the list you may have to scroll down to the bottom. Double click on content.opf and the code opens in the middle section, then you can amend the code directly, make sure to use File and Save when you finish.

Note: If you later use the Convert Book option to make a new epub file Calibre will reset the content.opf to the default information which is likely to remove what you manually edited, so you'll have to recode it.

Replies:   Vincent Berg
Vincent Berg 🚫

@Ernest Bywater

Finally! Why couldn't anyone (online references, help sites or here) mention the the .opf file is named "content.opf". If I'd know that much, I could easily have found it, but no, they send me down a damn rabbit hole of .opf=.doc=deconstruct your ebook/you can't reconstruct a broken ePub file load of nonsense.

Plus, while I can now see how to muck with the .opf file, I originally started on an Amazon Author's forum discussion of opening Kindle files. So other than converting all of you Kindle documents into Calibre, deconstructing and reconstructing them and then re-converting it back into Kindle format. Somehow, I can't imagine that's how the mainstream publishers are doing it, now how Amazon itself is doing it.

Later Update: It turns out, you can access the content.opf file directly on the Mac, by going to the Calibre data files for the particular book, where it's stored as a separate file. However, the "reference type="start" still had no effect, and when I tried to unzip the files, it produced an unable nonsense file (I certainly didn't recognize it), so after downloading a NEW UnArchiver app, I was unable to decompress it, access the file, only to learn that it was the same as I'd edited from within Calibre itself.

I'd thought that Calibre was erasing it each time I generated a new file (testing out each), but actually, the "reference type="start"" command was simply being ignored each time.

So, unless anyone has any new ideas (like moving the "guide" commands to the top of the file (Calibre itself puts them at the end, which is where I added to it), I'm out of ideas. There doesn't seem to be any to adjusting the start position of eBooks, at least on Macs.

Lazeez Jiddan (Webmaster)

@Vincent Berg

There doesn't seem to be any to adjusting the start position of eBooks, at least on Macs.

while examining various EPUBs for the bookapy sampler, I found many that had only one item in the guide section. The book had many chapters in the TOC, but the guide section had one item and it pointed to the start of the book's text or chapter 1.

Might work.

Switch Blayde 🚫

@Vincent Berg

I begin my cover page with the book's title and then under it "a novel" and then the copyright information, etc below that.

I format the title as H1 so the book title is the first thing in the ToC before Chapter 1. If my guess is true (that the e-reader opens it to the first chapter) it will open it at my cover page since it's the first "chapter" in the ToC.

Replies:   Vincent Berg
Vincent Berg 🚫

@Switch Blayde

I format the title as H1 so the book title is the first thing in the ToC before Chapter 1. If my guess is true (that the e-reader opens it to the first chapter) it will open it at my cover page since it's the first "chapter" in the ToC.

It would also be an easy matter to simply delete the internal cover image, meaning it would definitely start at the first FULL text page.

Back to Top

Close
 

WARNING! ADULT CONTENT...

Storiesonline is for adult entertainment only. By accessing this site you declare that you are of legal age and that you agree with our Terms of Service and Privacy Policy.


Log In