PDF-WebKit
view release on metacpan or search on metacpan
lib/PDF/WebKit.pm view on Meta::CPAN
949596979899100101102103104105106107108109110111112113114
$self
->_append_stylesheets;
my
@args
=
$self
->command(
$path
);
my
$input
=
$self
->source->is_html ?
$self
->source->content :
undef
;
my
$output
;
my
%opt
=
map
+(
"binmode_std$_"
=>
":raw"
),
"in"
,
"out"
,
"err"
;
run3 \
@args
, \
$input
, \
$output
, \
my
$err
, \
%opt
;
if
(
$path
) {
$output
=
do
{
local
(
@ARGV
,$/) = (
$path
); <> };
}
if
(not (
defined
(
$output
) &&
length
(
$output
))) {
Carp::croak
"command failed: $args[0]"
;
}
return
$output
;
}
sub
to_file {
my
$self
=
shift
;
lib/PDF/WebKit.pm view on Meta::CPAN
154155156157158159160161162163164165166167168169170171172173
my
$name
=
$node
->getAttribute(
'name'
);
next
unless
(
$name
&& (
$name
=~ s{^\Q
$prefix
}{}s));
$meta
{
$name
} =
$node
->getAttribute(
'content'
);
}
return
%meta
;
}
sub
_style_tag_for {
my
(
$self
,
$stylesheet
) =
@_
;
my
$styles
=
do
{
local
(
@ARGV
,$/) = (
$stylesheet
); <> };
return
"<style>$styles</style>"
;
}
sub
_append_stylesheets {
my
$self
=
shift
;
if
(@{
$self
->stylesheets } && !
$self
->source->is_html) {
Carp::croak
"stylesheets may only be added to an HTML source"
;
}
return
unless
$self
->source->is_html;
t/pdf-webkit-integration.t view on Meta::CPAN
262728293031323334353637383940414243444546474849505152535455
my
$pdfkit
= PDF::WebKit->new(\
'html'
,
header_spacing
=> 1);
my
=
$pdfkit
->to_pdf;
is(
substr
(
,0,4),
'%PDF'
);
# PDF Signature at beginning of file
};
it
"should have the stylesheet added to the head if it has one"
=>
sub
{
my
$pdfkit
= PDF::WebKit->new(\
"<html><head></head><body>Hai!</body></html>"
);
my
$stylesheet
= File::Spec->catfile(
$SPEC_ROOT
,
'fixtures'
,
'example.css'
);
push
@{
$pdfkit
->stylesheets },
$stylesheet
;
$pdfkit
->to_pdf;
my
$css
=
do
{
local
(
@ARGV
,$/) = (
$stylesheet
); <> };
like(
$pdfkit
->source->content,
qr{<style>\Q$css\E</style>}
);
};
it
"should prepend style tags if the HTML doesn't have a head tag"
=>
sub
{
my
$pdfkit
= PDF::WebKit->new(\
"<html><body>Hai!</body></html>"
);
my
$stylesheet
= File::Spec->catfile(
$SPEC_ROOT
,
'fixtures'
,
'example.css'
);
push
@{
$pdfkit
->stylesheets },
$stylesheet
;
$pdfkit
->to_pdf;
my
$css
=
do
{
local
(
@ARGV
,$/) = (
$stylesheet
); <> };
like(
$pdfkit
->source->content,
qr{<style>\Q$css\E</style><html>}
);
};
it
"should throw an error if the source is not html and stylesheets have been added"
=>
sub
{
my
$stylesheet
= File::Spec->catfile(
$SPEC_ROOT
,
'fixtures'
,
'example.css'
);
push
@{
$pdfkit
->stylesheets },
$stylesheet
;
eval
{
$pdfkit
->to_pdf };
like($@,
qr/stylesheet.*html/
i);
};
( run in 0.722 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )