Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
typo3
qfq
Commits
45b2e9a7
Commit
45b2e9a7
authored
Apr 30, 2017
by
Carsten Rose
Browse files
Html2Pdf.php: implemented session forwarding to wkhtmltopdf.
parent
790fa271
Changes
1
Hide whitespace changes
Inline
Side-by-side
extension/qfq/qfq/report/Html2Pdf.php
View file @
45b2e9a7
...
...
@@ -12,6 +12,7 @@
namespace
qfq
;
require_once
(
__DIR__
.
'/../store/Config.php'
);
require_once
(
__DIR__
.
'/../store/Session.php'
);
require_once
(
__DIR__
.
'/../Constants.php'
);
require_once
(
__DIR__
.
'/../helper/KeyValueStringParser.php'
);
...
...
@@ -23,6 +24,11 @@ class Html2Pdf {
*/
private
$config
=
array
();
/**
* @var \qfq\Session
*/
private
$session
=
null
;
/**
* Read QFQ config. Only SYSTEM_BASE_URL_PRINT and SYSTEM_WKHTMLTOPDF will be used.
* Check and get all clean _GET Parameter. Build a URL based on SYSTEM_BASE_URL_PRINT and the delivered URL params.
...
...
@@ -52,6 +58,11 @@ class Html2Pdf {
if
(
!
is_executable
(
$config
[
SYSTEM_WKHTMLTOPDF
]))
{
throw
new
\
exception
(
CONFIG_INI
.
' - '
.
SYSTEM_WKHTMLTOPDF
.
'='
.
$config
[
SYSTEM_WKHTMLTOPDF
]
.
' - not found or not executable.'
);
}
$urlParts
=
parse_url
(
$config
[
SYSTEM_BASE_URL_PRINT
]);
$this
->
session
=
Session
::
getInstance
();
}
/**
...
...
@@ -85,6 +96,23 @@ class Html2Pdf {
header
(
"Content-Transfer-Encoding: binary"
);
}
/**
* @return string
*/
private
function
wkhtmlSessionCookies
()
{
$result
=
''
;
$cookieNames
=
array_keys
(
$_COOKIE
);
foreach
(
$cookieNames
as
$name
)
{
if
(
isset
(
$_COOKIE
[
$name
]))
{
$result
.
=
" --cookie '"
.
$name
.
"' '"
.
urlencode
(
$_COOKIE
[
$name
])
.
"'"
;
}
}
return
trim
(
$result
);
}
/**
* Converts a Webpage (URL) to a PDF file.
* The URL might be a local Typo3 page (without hostname, starting with the parameter) or a full URL.
...
...
@@ -144,7 +172,10 @@ class Html2Pdf {
$filename
=
tempnam
(
sys_get_temp_dir
(),
DOWNLOAD_FILE_PREFIX
);
$filenameEscape
=
escapeshellarg
(
$filename
);
$cmd
=
"
$wkhtmlToPdf
$options
$urlPrint
$filenameEscape
"
;
$cookieOptions
=
$this
->
wkhtmlSessionCookies
();
$this
->
session
->
close
();
$cmd
=
"
$wkhtmlToPdf
$cookieOptions
$options
$urlPrint
$filenameEscape
> /tmp/wk.out 2>&1"
;
$rc
=
0
;
$line
=
system
(
$cmd
,
$rc
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment