Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
importPage example
private
function
mergeDocuments
(
array
$paths
)
: void
{
$pdf
=
new
Fpdi
(
)
;
foreach
(
$paths
as
$path
)
{
$numPages
=
$pdf
->
setSourceFile
(
$path
)
;
for
(
$i
= 1;
$i
<=
$numPages
; ++
$i
)
{
$template
=
$pdf
->
importPage
(
$i
)
;
$size
=
$pdf
->
getTemplateSize
(
$template
)
;
if
(
!\
is_array
(
$size
)
)
{
continue
;
}
$pdf
->
AddPage
(
'P',
[
$size
[
'width'
]
,
$size
[
'height'
]
]
)
;
$pdf
->
useTemplate
(
$template
)
;
}
}
$hash
= Random::
getAlphanumericString
(
32
)
;
continue
;
}
$config
= DocumentConfigurationFactory::
createConfiguration
(
$document
->
getConfig
(
)
)
;
$media
=
$context
->
scope
(
Context::SYSTEM_SCOPE,
fn
(
Context
$context
)
: string =>
$this
->mediaService->
loadFileStream
(
$documentMediaId
,
$context
)
->
getContents
(
)
)
;
$numPages
=
$this
->fpdi->
setSourceFile
(
StreamReader::
createByString
(
$media
)
)
;
$totalPage
+=
$numPages
;
for
(
$i
= 1;
$i
<=
$numPages
; ++
$i
)
{
$template
=
$this
->fpdi->
importPage
(
$i
)
;
$size
=
$this
->fpdi->
getTemplateSize
(
$template
)
;
if
(
!\
is_array
(
$size
)
)
{
continue
;
}
$this
->fpdi->
AddPage
(
$config
->
getPageOrientation
(
)
?? 'portrait',
$config
->
getPageSize
(
)
)
;
$this
->fpdi->
useTemplate
(
$template
)
;
}
}
if
(
$totalPage
=== 0
)
{
return
null;
}