Skip to content

Instantly share code, notes, and snippets.

@rupertl
Last active December 19, 2015 15:19
Show Gist options
  • Save rupertl/5975866 to your computer and use it in GitHub Desktop.
Save rupertl/5975866 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use utf8;
use strict;
use warnings;
binmode(STDOUT, ":encoding(UTF-8)");
use EBook::MOBI;
my $book = EBook::MOBI->new();
$book->set_encoding(':encoding(UTF-8)');
# These two lines work OK
$book->add_mhtml_content("<p>Here is some English text - Hello there!</p>\n");
$book->add_mhtml_content("<p>Here is some German text - Viele Grüße!</p>\n");
# These do not, showing garbled text when viewing in an eReader
$book->add_mhtml_content("<p>Here is some Chinese text - 你好!</p>\n");
$book->add_mhtml_content("<p>Here is some Japanese text - お元気ですか!</p>\n");
$book->add_mhtml_content("<p>End of text.</p>\n");
$book->make();
# Printing the raw mHTML shows the encoding is correct
$book->print_mhtml();
$book->save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment