Skip to content

Commit

Permalink
Import external links on pdf writing
Browse files Browse the repository at this point in the history
See #12
  • Loading branch information
Benjamin Dieleman committed Nov 6, 2023
1 parent 176884a commit 16b3739
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ class Writer
];
public const XML_FILENAME = 'Factur-X_extension_schema.xmp';

private ?string $profile = null;
protected ?string $profile = null;

protected bool $importExternalLinks = true;

public function __construct(bool $importExternalLinks = true)
{
$this->importExternalLinks = $importExternalLinks;
}

/**
* Generates Factur-X PDF from PDF invoice and Factur-X XML.
Expand Down Expand Up @@ -78,7 +85,7 @@ public function generate(string $pdfInvoice, string $xml, string $profile = null
$pdfWriter = new FdpiFacturx();
$pageCount = $pdfWriter->setSourceFile($pdfInvoiceRef);
for ($i = 1; $i <= $pageCount; ++$i) {
$tplIdx = $pdfWriter->importPage($i, '/MediaBox');
$tplIdx = $pdfWriter->importPage($i, '/MediaBox', $groupXObject = true, $this->importExternalLinks);
$pdfWriter->AddPage();
$pdfWriter->useTemplate($tplIdx, 0, 0, null, null, true);

Expand Down Expand Up @@ -109,6 +116,26 @@ public function generate(string $pdfInvoice, string $xml, string $profile = null
return $pdfWriter->Output('S');
}

/**
* Returns used profile for export.
*/
public function getProfile(): ?string
{
return $this->profile;
}

public function doesImportExternalLinks(): bool
{
return $this->importExternalLinks;
}

public function setImportExternalLinks(bool $importExternalLinks): self
{
$this->importExternalLinks = $importExternalLinks;

return $this;
}

/**
* Updates PDF metadata to according to Factur-X XML data.
*
Expand Down

0 comments on commit 16b3739

Please sign in to comment.