Shiny New E-Book Gizmo: The Amazon Kindle


View Full Version : bd2mobi - Application to convert Book Designer html0 to .mobi


maggotb0y
01-19-2008, 03:20 PM
I've written a perl script to convert .html0 files output by Book Designer to .mobi format for viewing on the Kindle or other .mobi devices. This should be useful to those of us who would like to (legally, of course) share our content with Kindle owners.

This will automatically generate the table of contents from the "Titles" in the original BD file.

I've attached a zip file with a compiled .exe file, and the Perl source for this file for anyone who'd like to contribute. You'll need to extract the .exe and download mobigen from Mobipocket (available at http://www.mobipocket.com/dev/)

The easiest way to use this is to create a shortcut to the .exe in your "Send To" folder. Then you can simply right click on any .html0 file and choose Send To>bd2mobi, and it will convert the file for you.

Let me know how it works for you!

p.s.- Thanks to HarryT for the excellent tutorial that I followed in creating this script.

version 2 now attached
This version now properly converts books with PNGs and GIFs in the source.
version 3 now attached
This version works properly with newer versions of mobigen and allows you to specify author, title and cover image.

astra
01-20-2008, 07:47 AM
Uhm. BD creates books for Kindle or CyBook Gen3 or Iliad without any additional tools. Why would you write another tool for the purpose?

maggotb0y
01-20-2008, 11:10 AM
Uhm. BD creates books for Kindle or CyBook Gen3 or Iliad without any additional tools. Why would you write another tool for the purpose?

I'm not aware of a way to generate .mobi files from BD. There is a PRC (or perhaps PDB, don't have it in front of me at the moment) option, but that has never worked properly for me. Is that what you are referring to?

Doing research on the topic, I found HarryT's thread http://www.mobileread.com/forums/showthread.php?t=17914 and automated the process.

astra
01-20-2008, 12:31 PM
I was under the impression that BD can create mobi pocket books. Because Harry_T creates his books in BD. I was aware about TOC problems. I see why you wanted to automate the process.

Thanks.

tompe
01-20-2008, 02:53 PM
I was under the impression that BD can create mobi pocket books. Because Harry_T creates his books in BD. I was aware about TOC problems. I see why you wanted to automate the process.


It cannot create true MobiPocket books. It can pack HTML in a PalmDOC book that can be read by MobiPocket readers. But you need a true MobiPocket book if you want to have long titles and meta information like author. Also BD does not work on all platforms.

My MobiPerl contains opf2mobi which generated true MobiPocket books.

maggotb0y
01-20-2008, 07:06 PM
My MobiPerl contains opf2mobi which generated true MobiPocket books.

You're welcome to grab this code for inclusion in mobiperl - it basically automatically creates a table of contents and an OPF directly from the HTML0 file, then calls mobigen to build the .mobi file, finally deleting the files it creates for the conversion.

tompe
01-20-2008, 07:30 PM
You're welcome to grab this code for inclusion in mobiperl - it basically automatically creates a table of contents and an OPF directly from the HTML0 file.

I put it on the list of possible things to do. I thought about it a couple of days ago but then decided that since HTML0 is a Windows specific format in the sence that the only tool that generates it runs only in Windows it was less interesting to do it.

kovidgoyal
01-20-2008, 08:41 PM
As motivation, html2lrf has a BD preprocessor :)

HarryT
01-21-2008, 04:00 AM
I was under the impression that BD can create mobi pocket books. Because Harry_T creates his books in BD. I was aware about TOC problems. I see why you wanted to automate the process.

Thanks.

The "MobiPocket" books that BD creates are very poor. They don't have any metadata, all text which should be centred comes out left-aligned, all pictures come out very small, the navigation links to the table of contents don't work - there are numerous problems.

It's a lot better to use BD as a book editor, but then to use the "Mobigen" or "MobiPocket Creator" tools to create a "proper" Mobipocket book. That's what I do now, and what this thread is all about.

astra
01-21-2008, 04:15 AM
The "MobiPocket" books that BD creates are very poor. They don't have any metadata, all text which should be centred comes out left-aligned, all pictures come out very small, the navigation links to the table of contents don't work - there are numerous problems.

It's a lot better to use BD as a book editor, but then to use the "Mobigen" or "MobiPocket Creator" tools to create a "proper" Mobipocket book. That's what I do now, and what this thread is all about.

I see.

WOW :eek: I am a little bit surprised and disappointed :blink:

When I was doing a research on iRex iLiad, I have asked a couple of times whether creating books for iRex iLiad would be more difficult or different than creating lrf files for Sony in BD and whether they would be of the same quality and as nice looking as lrf files. Besides pointing out to me that I will have to "manually" (use a certain command in BD) add TOC in the beginning of a book and that pics will be smaller, noone has mentioned all the problems that I hear now.

JSWolf
01-21-2008, 08:04 AM
Does BD2Mobi create a proper table of contents and proper metadata?

Also, how does an eBook created using bd2mobi compare to doing it using Harry's tutorial?

maggotb0y
01-21-2008, 08:20 AM
BD2Mobi reads the "titles" from the BD html0 file to generate the table of contents, and extracts the Author and Title of the book as well.

bd2mobi does exactly what HarryT's tutorial walks you through- it just automates it all. The only thing it does not automate is converting any non-jpeg images to jpeg. If it sees any gifs or pngs in the source, it will let you know that you need to fix that.

JSWolf
01-21-2008, 08:25 AM
Sounds good. What version of Perl would I need for Windows in order to use your program?

RWood
01-21-2008, 09:03 AM
vvv has stated that the BD output for mobi is several versions behind the current mobi level. It is one of the items on his enhancement list which itself has no publicly released milestone dates -- it may be released this week, it may be released in a year or more.

When we first released mobi books (with the PRC extension) there were only a few takers as the iLiad had just acquired the ability to read them. With the release of the Gen3 and now the Kindle the number of downloads for mobi books has grown. For most books the number of downloads for mobi is still below that of Sony but the gap is closing and for a few the mobi is format is more popular than the Sony.

maggotb0y
01-21-2008, 09:40 AM
Sounds good. What version of Perl would I need for Windows in order to use your program?

For the compiled version, you won't need Perl at all, just run the .exe.

If you want to modify the Perl script, you should be able to do this in just about any version of Perl- it isn't doing anything particularly fancy.

tompe
01-21-2008, 09:41 AM
bd2mobi does exactly what HarryT's tutorial walks you through- it just automates it all. The only thing it does not automate is converting any non-jpeg images to jpeg. If it sees any gifs or pngs in the source, it will let you know that you need to fix that.

You can use GD to convert to jpeg. That is what I use in MobiPerl. The only issue was that if you use ActivePerl in Windows you have to use an alternative repository for the GD package.

If you give -jpeg to mobigen I thought it converted to jpeg but maybe it only accept jpeg and does not convert them to gif.

tompe
01-21-2008, 09:44 AM
For the compiled version, you won't need Perl at all, just run the .exe.


Which version of Perl did you use and how did you compile it? I had a lot of trouble finding a combination of ActivePerl and PAR that worked. I finally found one but now I do not dare to update anything...

maggotb0y
01-21-2008, 10:41 AM
The machine I wrote it on has a relatively recent 5.8 build from activestate- it was compiled with the activestate compiler.

HarryT
01-21-2008, 11:46 AM
If you give -jpeg to mobigen I thought it converted to jpeg but maybe it only accept jpeg and does not convert them to gif.

It does indeed convert other image formats to JPEG if you use that flag, but if you have any <IMG> links in your HTML which reference the GIF (or whatever they are) files, they don't get changed, so it's not really of that much practical use :).

tompe
01-21-2008, 12:03 PM
It does indeed convert other image formats to JPEG if you use that flag, but if you have any <IMG> links in your HTML which reference the GIF (or whatever they are) files, they don't get changed, so it's not really of that much practical use :).

The image links are always changed to a record index pointer so it will work. So mobigen -jpeg will work for files that references GIF images. The links in the documents are not used at all in the MobiPocket file. A link to a position is replaced by a "filepos" tag for example.

maggotb0y
01-21-2008, 12:27 PM
It does indeed convert other image formats to JPEG if you use that flag, but if you have any <IMG> links in your HTML which reference the GIF (or whatever they are) files, they don't get changed, so it's not really of that much practical use :).

I'm sure I can correct the source html to deal with new file names. Over the next day or so I'll do some playing around with documents that have jpgs and gifs and update the script to handle them automatically.

HarryT
01-22-2008, 01:33 AM
The image links are always changed to a record index pointer so it will work. So mobigen -jpeg will work for files that references GIF images. The links in the documents are not used at all in the MobiPocket file. A link to a position is replaced by a "filepos" tag for example.

OK, thanks, Tommy. I remember trying something using that flag which didn't work as I expected it too. I can't recall exactly what it was, though.

maggotb0y
01-23-2008, 05:42 AM
Okay, I've updated the attachment to remove the checking for .jpgs and .gifs, so this should now properly convert any file with those graphics types. If you could try it out and let me know what you think, I'd appreciate it.

Thanks for the info, Tommy!

lovebeta
01-30-2008, 12:30 AM
Great tool maggotb0y. This is faster than doing it by hand following HarryT's instruction.

There's one issue about the author field though. When defining in BD, I would like to keep the "First name last name" sequence. However, as we know, to make "sort by author" work properly in Kindle, we need the output Mobi in the format of "last name, first name". Is there any work around for this? Thanks.

dcalder
01-31-2008, 12:50 AM
I've downloaded and attempted to use bd2mobi but not having any luck with it.

Using this command line:

bd2mobi.exe "C:\Documents and Settings\dcalder\My eBooks\build\aylno.html0"

I end up with this result:


*****************************************
* Mobipocket mobigen.exe V6.01 build 36 *
* A command line e-book compiler *
* Copyright Mobipocket.com 2003-2007 *
*****************************************

opt compression: standard DOC compression
opt security: no security
Error: unsupported argument -jpegdone processing A Year Like No Other by Aspen

No file appears to have been created. Am I doing something wrong or is there a bug in the script? Where should the mobi file appear - in the directory with bd2mobi or in the directory with the BD source file?

maggotb0y
02-01-2008, 08:25 AM
we need the output Mobi in the format of "last name, first name". Is there any work around for this? Thanks.

I'll look into a switch for reversing the author or allowing you to specify.

maggotb0y
02-01-2008, 08:38 AM
No file appears to have been created. Am I doing something wrong or is there a bug in the script? Where should the mobi file appear - in the directory with bd2mobi or in the directory with the BD source file?

If everything's working properly, the mobi file will be created in the same folder as the html0 file.

Not sure why that would happen, it may be something in the environment on your PC. Does the problem you're describing happen with all files or just one file. If you are experiencing only with this file, can you post it (is it public domain)? If not I'll work to add a switch that doesn't delete the source files so we can troubleshoot the issue.

dcalder
02-07-2008, 10:01 AM
If everything's working properly, the mobi file will be created in the same folder as the html0 file.

Not sure why that would happen, it may be something in the environment on your PC. Does the problem you're describing happen with all files or just one file. If you are experiencing only with this file, can you post it (is it public domain)? If not I'll work to add a switch that doesn't delete the source files so we can troubleshoot the issue.


After a little further investigation, it appears that the problem may be that I'm using the latest mobigen - which no longer supports the -jpeg option, as it behaves that way by default. That's what throws the error. It seems likely that it's also what prevents the mobi file from being created.

maggotb0y
04-07-2008, 08:25 PM
After an extremely long delay, I've finally gotten around to releasing an update that works with newer versions of mobigen, and also allows you to specify author, title, and cover image.

maggotb0y
04-09-2008, 02:21 PM
Sorry, didn't document the usage. Its as follows

mobigen.exe "my example book.html0" --author="Smith, Agent" --title="My Example Book" --cover="My Neato Cover.jpg"

Darqref
04-13-2008, 09:02 PM
Sorry, didn't document the usage. Its as follows

mobigen.exe "my example book.html0" --author="Smith, Agent" --title="My Example Book" --cover="My Neato Cover.jpg"

I've tried to build a book I scanned and ocred three different ways.

1. I used bd2mobi and had problems. first I couldn't get past the file validator, and got sent back to the syntax use declaration. For this attempt I had the hltm0 file, bd2mobi.exe and mobigen.exe all in the same directory. Finally I tried bd2mobi but sent the target file to the original BD LastFile directory instead, and got some action. This generated a crashing error in mobigen (some kind of access violation, I think. I'm not enough of a developer to dig into the debug of mobigen.) twice.
AppName: mobigen.exe AppVer: 4.8.8.7 ModName: mobigen.exe
ModVer: 4.8.8.7 Offset: 000dbe90



2. I went back and tried to follow HarryT's instruction doc as close as possible - reopened BD and saved as htm, opened the file in notepad and changed the justify, set the anchors, and set the mbp:pagebreak . When I got to Mobipocket Creator and tried to build, I again got a crashing bug, nothing is created and what appears to be the same exception, and Creator closes.
AppName: creator.exe AppVer: 4.2.39.0 ModName: msvcr80.dll
ModVer: 8.0.50727.762 Offset: 00014580

3. went back and tried mobigen directly, using the html file generated in step 2. same exception.

AppName: mobigen.exe AppVer: 4.8.8.7 ModName: mobigen.exe
ModVer: 4.8.8.7 Offset: 000dbe90

Since the book is a copyrighted file, I can't post it here. It's pretty basic, no images etc. Any idea what's causing the stupid thing to croak? Note that while the prc isn't pretty, the one I build from Book Designer is readable on my Gen3, but doesn't have the standard toc, etc.

Roger

maggotb0y
04-14-2008, 09:06 PM
I've tried to build a book I scanned and ocred three different ways.

1. I used bd2mobi and had problems. first I couldn't get past the file validator, and got sent back to the syntax use declaration.

Since the book is a copyrighted file, I can't post it here. It's pretty basic, no images etc. Any idea what's causing the stupid thing to croak? Note that while the prc isn't pretty, the one I build from Book Designer is readable on my Gen3, but doesn't have the standard toc, etc.

Roger

Roger-
Without seeing the contents of the file, it's nigh on impossible to troubleshoot the problem. You may be able to edit the file down to the first paragraph of the first chapter and modify the text and still reproduce the problem. If you can do that, we might be able to troubleshoot, but without any view of the contents of the file, it's not likely that anyone can solve your issue.

Darqref
04-15-2008, 11:33 PM
Roger-
Without seeing the contents of the file, it's nigh on impossible to troubleshoot the problem. You may be able to edit the file down to the first paragraph of the first chapter and modify the text and still reproduce the problem. If you can do that, we might be able to troubleshoot, but without any view of the contents of the file, it's not likely that anyone can solve your issue.

It's a freakin Margin style!


I kept chopping the book in half until I located where the error stopped happening. Whenever there is a div statement that looks like

<DIV style="MARGIN-LEFT: 80px; MARGIN-RIGHT: 100px">

Then I get a crashing error in Mobipocket Creator. When I take all those statements out, it works ok. I was working on a Harry Potter book, and I was using this method of setting off the quoted newspaper text.

I'll try to add a zip of the html file.