borisdaeppen / ebook--mobi Goto Github PK
View Code? Open in Web Editor NEWEbook in MOBI format with Perl
Home Page: https://metacpan.org/module/EBook::MOBI
Ebook in MOBI format with Perl
Home Page: https://metacpan.org/module/EBook::MOBI
This message should be removed:
Version: 2 - 2 - DOC_COMPRESSED
Current code is as follow
sub title {
my $self = shift;
my $txt = shift;
my $lvl = shift || 1;
my $toc = shift || 1;
If the final argument is not present, or set to zero, then shift returns nothing and the OR operator sets $toc to 1. But documentation suggest that a false value will mean title is not included in the TOC.
The following code solved this for me.
sub title {
my $self = shift;
my $txt = shift;
my $lvl = shift;
my $toc = shift;
unless (defined($toc)) {
$toc = 1;
}
Iโm using the following code to make a MOBI book. All the contents goes in, but the table of contents is just an empty list. I followed your simple_mobi.pl example which uses the driver to add content in POD format and it worked fine. But adding content without using a driver seems to cause the TOC to not generate correctly
Regards,
Kim
use EBook::MOBI;
my $mobi = EBook::MOBI->new();
sub debug {
my ($package, $filename, $line) = caller;
print "$package\t$_[0]\n";
}
$mobi->debug_on(&debug);
my $c = EBook::MOBI::Converter->new();
$mobi->add_mhtml_content($c->title('Head1 not in TOC', 2,0) );
$mobi->add_mhtml_content("hello world");
$mobi->add_mhtml_content( $c->newline);
$mobi->add_mhtml_content("more text");
$mobi->add_pagebreak();
$mobi->add_toc_once();
$mobi->add_pagebreak();
$mobi->add_mhtml_content($c->title('Head 2 page 2 in TOC', 2,0) );
$mobi->add_mhtml_content( $c->paragraph('some paragraph text') );
$mobi->add_pagebreak();
$mobi->add_mhtml_content($c->title('Head 4 page 3 in TOC', 4,1) );
$mobi->add_mhtml_content( $c->paragraph('some paragraph text') );
$mobi->add_mhtml_content("plain content");
$mobi->add_pagebreak();
$mobi->set_filename('mobi_test.mobi');
$mobi->make();
$mobi->save();
$mobi->print_mhtml();
HTML output
hello world
more text<mbp:pagebreak />
<mbp:pagebreak />
some paragraph text
<mbp:pagebreak />
some paragraph text
plain content<mbp:pagebreak />
You can see the latgest log here http://ppm4.activestate.com/MSWin32-x86/5.16/1600/B/BO/BORISD/EBook-MOBI-0.67.d/log-20131028T200829.txt and previous logs here http://code.activestate.com/ppm/EBook-MOBI/
Activestate wont load versions that don't pass, so 0.58 is the latrst one they have. www.cpantesters.org currently down so can't check whats happening there.
Also, not sure if this is related to the above, but this link doesn't work http://search.cpan.org/~borisd/EBook-MOBI-0.68-TRIAL/ so can't easily browse content, test results etc, as we can for Ebook-MOBI-Image.
can not change to some font on kindle paperwhite2.
how to set font of the mobi ?
thanks a lot.
@steffenw thx for the ideas
Instead of using
=image
use something from the POD standard.
For example
=for
or
=begin
=end
Examples:
http://www.perlmonks.org/?node_id=938715
http://www.arcetri.astro.it/CC/Manuals/PerlMan/pod/perlpod.html
To insert images, the Image::Imlib2 module is a dependency. This in turn requires the imlib2 program to be installed.
This package is only available for Linux, no Windows version, which means I can't create any images if I want to use this module. Also Imlib2 doesn't seem to have many recent updates, and some people have had trouble configuring it: http://cpanratings.perl.org/dist/Image-Imlib2
There are several pure perl modules that will rescale images, including Image::Imager and Image::Scale . They will work on all operating systems and seem to be more actively maintained
If it is not practical for you to switch to one of these alternatives, I suggest you add a LIMITATION section to your documentation, outlining no MS Windows support.
A note about needing to install imlib2 binaries or compile the package locally would also help, but may this should probably go into the MOBI::Image module doco.
There is still some unused code containing GD in lib/EBook/MOBI/MobiPerl/Util.pm
It seems like this was used to add title images... would be a cool feature to have that ported.
The most minimalistic Example ever should be added too
Like:
use EBook::MOBI;
my $book = EBook::MOBI->new();
$book->add_mhtml_content("hello world");
$book->make();
$book->save();
Test of a finished Book could be made over a Checksum:
Create "Hello-World"-Book in a temporary directory, make checksum, compare that with a handmade hardcoded checksum, if not equal, fail.
v0.55 is 170.28K and this actually can't be...
A short check shows:
$ find EBook-MOBI-0.55 | grep \.mobi\$
EBook-MOBI-0.55/BigSimple.mobi
EBook-MOBI-0.55/Simple.mobi
Dist::Zilla keeps on fooling me!
use 5.010;
use strict;
use warnings;
use EBook::MOBI;
my $book = EBook::MOBI->new();
$book->add_mhtml_content(q{
<p><ol> and <li> oddly number the rows with 65535.</p>
<ol>
<li>First entry</li>
<li>Second entry</li>
</ol>
}
);
$book->add_pagebreak();
$book->set_title( 'A new MOBI book generated by EBook::MOBI' );
$book->set_author('Gabor Szabo');
$book->set_encoding(':encoding(UTF-8)');
$book->print_mhtml;
$book->make();
$book->save();
The resulting file will show two list items having the order number 65535 when viewed on the desktop Kindle reader on OSX.
When reading on real Kindle, they show no numbering at all.
I wonder if this is a bug in the module, the viewer or Kindle itself?
I wonder if this
I'm having some problems getting UTF-8 encoded text to work with EBook::MOBI. Please see the following gist
https://gist.github.com/rupertl/5975866
When I view the created file book.mobi in an eReader such as Calibre or fbReader, the first two lines (English and German) display OK but the next two (Chinese and Japanese) do not.
The MOBI format should support full UTF-8 so I suspect there is an issue in encoding non ISO-8859 characters
Tested using EBook::MOBI 0.64 and perl 5.16.3 on Linux.
Issue #22 mentioned the problem and offered a fix.
However the tests fail after merging, so I have made a reset to the last working commit.
I'll have to take a closer look at the issue.
Add year 2013 to "COPYRIGHT & LICENSE" section.
metacpan.org tells me that there is a POD-error.
And also this section should be removed:
https://metacpan.org/module/EBook::MOBI::Mhtml2Mobi#TODO
it is not needed in dist.ini
this also works
$plugin->debug_on( sub {
my ($package, $filename, $line) = caller;
print "$package\t$_[0]\n";
}
);
and is more elegant.
Can be shown in the examples!
An idea of https://github.com/garu
"When I got to EBook::MOBI, I was
looking for a module that would let me write text in MOBI format.
Reading would also be nice, but not necessary my particular need at
that moment. I was a bit frustrated when I realized I had to convert
my stuff to pod and only then have the MOBI file ready. I saw there
was some kind of way to write raw content with the add_mhtml_content()
method, but it can get really frustrating - specially when there is no
easily reachable documentation pointing to what exactly the MHTML
format is."
https://github.com/garu wishes:
"[...] another thing I missed is a way to get the data as a
variable instead of as a file. This would let me serve the generated
"book" via Web or send it directly to a Kindle device without having
to save a temporary file on disk."
Use Image::Imlib2 instead of Image::Resize.
Here is how to use: http://stackoverflow.com/questions/486874/stretch-resize-or-thumbnail-an-image-using-perl
How pictures get converted has to be found out... I don't know yet.
Also it would be a good idea to make the thumbnail-part as a plugin system so that only those need to install it which actually use pictures.
0.42 has Problems with Umlaut - 0.41 did not.
Urgent issue
http://cpants.charsbar.org/dist/errors/EBook-MOBI says:
no_large_files Simple.mobi:255402; example/img/camel_big.jpg:211473
This file could be removed, to reduce size of dist
https://github.com/garu brought up this idea:
"how about just extending your API so it lets other people create MOBI
files without having to learn mhtml? Then turn the POD-specific code
into a pluggable system (e.g. EBook::MOBI::Driver::POD, already
bundled into your dist) that talks to this API, so people can create
other converters as well, such as from MarkDown, Word (.doc), PDF,
etc."
With release 0.53 the POD-Plugin can handle "=begin html" blocks, but I forgot to add it to the docs for the plugin... need to do that later once
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.