|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* Jasper report integration for PHP |
|
7
|
|
|
* |
|
8
|
|
|
* @link https://github.com/belgattitude/soluble-jasper |
|
9
|
|
|
* @author Vanvelthem Sébastien |
|
10
|
|
|
* @copyright Copyright (c) 2017-2019 Vanvelthem Sébastien |
|
11
|
|
|
* @license MIT |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Soluble\Jasper\Proxy\Engine\Export; |
|
15
|
|
|
|
|
16
|
|
|
use Soluble\Japha\Bridge\Adapter as BridgeAdapter; |
|
17
|
|
|
use Soluble\Japha\Interfaces\JavaObject; |
|
18
|
|
|
use Soluble\Jasper\Proxy\Export\SimplePdfExporterConfiguration; |
|
19
|
|
|
use Soluble\Jasper\Proxy\RemoteJavaObjectProxyInterface; |
|
20
|
|
|
use SplFileInfo; |
|
21
|
|
|
|
|
22
|
|
|
class JRPdfExporter implements RemoteJavaObjectProxyInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var BridgeAdapter |
|
26
|
|
|
*/ |
|
27
|
|
|
private $ba; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var JavaObject Java('net.sf.jasperreports.engine.export.JRPdfExporter') |
|
31
|
|
|
*/ |
|
32
|
|
|
private $exporter; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Create a local context, if no parentContext is given, assume the DefaultJasperReportsContext. |
|
36
|
|
|
* |
|
37
|
|
|
* @param BridgeAdapter $bridgeAdapter |
|
38
|
|
|
*/ |
|
39
|
5 |
|
public function __construct(BridgeAdapter $bridgeAdapter) |
|
40
|
|
|
{ |
|
41
|
5 |
|
$this->ba = $bridgeAdapter; |
|
42
|
5 |
|
$this->exporter = $this->ba->java( |
|
43
|
5 |
|
'net.sf.jasperreports.engine.export.JRPdfExporter' |
|
44
|
|
|
); |
|
45
|
5 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param JavaObject $jasperPrint Java('net.sf.jasperreports.engine.JasperPrint') |
|
49
|
|
|
*/ |
|
50
|
4 |
|
public function setExporterInput(JavaObject $jasperPrint): void |
|
51
|
|
|
{ |
|
52
|
4 |
|
$exporterInput = $this->ba->java( |
|
53
|
4 |
|
'net.sf.jasperreports.export.SimpleExporterInput', |
|
54
|
|
|
$jasperPrint |
|
55
|
|
|
); |
|
56
|
4 |
|
$this->exporter->setExporterInput($exporterInput); |
|
57
|
4 |
|
} |
|
58
|
|
|
|
|
59
|
4 |
|
public function setExporterOutput(SplFileInfo $file): void |
|
60
|
|
|
{ |
|
61
|
4 |
|
$exporterOutput = $this->ba->java( |
|
62
|
4 |
|
'net.sf.jasperreports.export.SimpleOutputStreamExporterOutput', |
|
63
|
4 |
|
$file->getPathname() |
|
64
|
|
|
); |
|
65
|
4 |
|
$this->exporter->setExporterOutput($exporterOutput); |
|
66
|
4 |
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Set custom pdf configuration (metadata,...). |
|
70
|
|
|
*/ |
|
71
|
4 |
|
public function setConfiguration(SimplePdfExporterConfiguration $exportConfig): void |
|
72
|
|
|
{ |
|
73
|
4 |
|
$this->exporter->setConfiguration($exportConfig->getJavaProxiedObject()); |
|
74
|
4 |
|
} |
|
75
|
|
|
|
|
76
|
4 |
|
public function exportReport(): void |
|
77
|
|
|
{ |
|
78
|
4 |
|
$this->exporter->exportReport(); |
|
79
|
4 |
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return JavaObject Java('net.sf.jasperreports.engine.export.JRPdfExporter') |
|
83
|
|
|
*/ |
|
84
|
1 |
|
public function getJavaProxiedObject(): JavaObject |
|
85
|
|
|
{ |
|
86
|
1 |
|
return $this->exporter; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|