App-Pod2Epub

 view release on metacpan or  search on metacpan

bin/pod2epub  view on Meta::CPAN


    my $css_filename = shift;
    my $css_fh;

    # If the user supplied the css filename check if it exists.
    if ( $css_filename ) {
        if ( -e $css_filename ) {
            $user_css = 1;
            return $css_filename;
        }
        else {
            warn "CSS file $css_filename not found.\n";
        }
    }

    # If the css file doesn't exist or wasted supplied create a default.
    ( $css_fh, $css_filename ) = tempfile();

    print $css_fh "h1         { font-size: 110%; }\n";
    print $css_fh "h2, h3, h4 { font-size: 100%; }\n";

    close $css_fh;

    return $css_filename;
}


###############################################################################
#
# add_cover()
#
# Add a cover image to the eBook. Add cover metadata for iBooks and add an
# additional cover page for other eBook readers.
#
sub add_cover {

    my $epub           = shift;
    my $cover_filename = shift;


    # Check if the cover image exists.
    if ( !-e $cover_filename ) {
        warn "Cover image $cover_filename not found.\n";
        return undef;
    }

    # Add cover metadata for iBooks.
    my $cover_id = $epub->copy_image( $cover_filename, 'images/cover.jpg' );
    $epub->add_meta_item( 'cover', $cover_id );

    # Add an additional cover page for other eBook readers.
    my $cover_xhtml =
        qq[<?xml version="1.0" encoding="UTF-8"?>\n]
      . qq[<!DOCTYPE html\n]
      . qq[     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n]
      . qq[    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n\n]
      . qq[<html xmlns="http://www.w3.org/1999/xhtml">\n]
      . qq[<head>\n]
      . qq[<title></title>\n]
      . qq[<meta http-equiv="Content-Type" ]
      . qq[content="text/html; charset=iso-8859-1"/>\n]
      . qq[<style type="text/css"> img { max-width: 100%; }</style>\n]
      . qq[</head>\n]
      . qq[<body>\n]
      . qq[    <img alt="" src="../images/cover.jpg" />\n]
      . qq[</body>\n]
      . qq[</html>\n\n];

    # Crete a temp file for the cover xhtml.
    my ( $tmp_fh, $tmp_filename ) = tempfile();

    print $tmp_fh $cover_xhtml;
    close $tmp_fh;

    # Add the cover page to the ePub doc.
    $epub->copy_xhtml( $tmp_filename, 'text/cover.xhtml', linear => 'no' );

    # Add the cover to the OPF guide.
    my $guide_options = {
        type  => 'cover',
        href  => 'text/cover.xhtml',
        title => 'Cover',
    };

    $epub->guide->add_reference( $guide_options );

    # Cleanup the temp file.
    unlink $cover_xhtml;

    return $cover_id;
}


###############################################################################
#
# get_commandline_options()
#
# Parse options from the commandline using GetOptions.
#
sub get_commandline_options {

    # Use GetOptions for the commandline parsing.
    GetOptions(
        'a|author=s'     => \$author,
        't|title=s'      => \$title,
        'l|language=s'   => \$language,
        'o|outfile=s'    => \$out_filename,
        's|stylesheet=s' => \$css_filename,
        'c|cover=s'      => \$cover_filename,
        'v|version'      => \$version,
        'x|xhtml-only'   => \$xhtml_only,
        'h|help'         => \$help,
        'man'            => \$man,
        'whine!'         => \$whine,
        'errata!'        => \$errata,
        'complain!'      => \$complain,
    ) or pod2usage( 2 );

    # Print the application version and exit.
    die "pod2epub, version $App::Pod2Epub::VERSION\n" if $version;



( run in 4.963 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )