Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyperlinks in PDF #12

Closed
seubi42 opened this issue Jul 8, 2022 · 9 comments
Closed

Hyperlinks in PDF #12

seubi42 opened this issue Jul 8, 2022 · 9 comments

Comments

@seubi42
Copy link

seubi42 commented Jul 8, 2022

Hi,
I'am using this library which is really nice by the way.
I found an issue when the source pdf contains hyperlinks.
factur-x library seems to broke the hyperlinks in the PDF document.

The blue color and the underline style are still on the links but hitbox is removed to, so it is not possible to click on it anyome.

For information i use the following code :

`
// 1. generate the pdf with dompdf
$html = "my pdf with a <a href="https://github.com/atgp/factur-x/issues/new\">here link";

$options = new \Dompdf\Options();
$options->set('enable_php', true);
$options->set('enable_html5_parser', true);
$options->set('isRemoteEnabled', true);
$options->set('dpi', 192);
$dompdf = new \Dompdf\Dompdf($options);
$dompdf->setHttpContext(stream_context_create([
'ssl' => [
'verify_peer' => FALSE,
'verify_peer_name' => FALSE,
'allow_self_signed'=> TRUE
],
]));
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
pdfoutput = $dompdf->output(); // links in this pdf works

//2. factur x

$facturex_xml = "...custom code here to generate the right xml as string, using \horstoeko\zugferd\ZugferdDocumentBuilder library...";
$facturx = new \Atgp\FacturX\Facturx();
$facturxPdf = $facturx->generateFacturxFromFiles($pdfoutput, $facturex_xml); // links are now broken
`

Is it a but to fix, or maybe i need to add some options in my code ?
Thanks a lot for your help.

@lucas-gp
Copy link
Collaborator

Did you find a solution for this problem ? To know if I need to check it
If not, could you give me an PDF example please ?

@wq9578
Copy link

wq9578 commented Jan 11, 2023

A closing </a> tag seems to be missing.
(Also, PDF/A doesn't allow transparent objects, which might be relevant here.)

@wq9578
Copy link

wq9578 commented Jan 11, 2023

I now encountered the same problem.
Links are not clickable anymore in the combined PDF.
The text is still printed in blue color (marked as link), but is not clickable.

The PDF/A standard itself permits links:

Can PDF/A files include links?

There's no problem with including links in a PDF/A file. It should be considered, however, that external links will likely become invalid over time.

https://www.pdfa.org/pdfa-faq/

@wq9578
Copy link

wq9578 commented Jan 11, 2023

Example PDFs:

Created with atgp / factur-x (link not clickable)
ZUGFeRD.pdf

Source PDF (link clickable)
ZUGFeRD_part.pdf

Created with Mustang (link clickable)
ZUGFeRD.pdf

@lucas-gp
Copy link
Collaborator

Hi @wq9578,
It's seem it's linked to FPDI library that doesn't preserve external links
I found several link about it :

So maybe need to make a custom class (or enhance FpdfiFacturx class) to be able to preverse external links
Don't hesitate to contribute and make a merge request about it :)

@wq9578
Copy link

wq9578 commented Jan 12, 2023

I have no experience with PDF editing in PHP for making a pull request.
But a quick internet search might suggest the following:
The FPDI library is used by FPDF, which is in turn used by mPDF. Since external links in PDF/A documents work well with mPDF (I tested it), you might either have a look at how mPDF uses (indirectly) the FPDI library, or use mPDF directly.

@JanSlabon
Copy link

In FPDI 2.4.0 you can import PDF pages with external links now: https://github.com/Setasign/FPDI/releases/tag/v2.4.0
For backwards compatibility you need to activate this. See here for more details: https://www.setasign.com/news-archive/fpdi-2.4.0-released/

@FactorSpeed
Copy link

The problem seems to be in Facturx class :

$tplIdx = $pdfWriter->importPage($i, '/MediaBox');

if It's replaced by this below, It works well !

$tplIdx = $pdfWriter->importPage($i, '/MediaBox', true, true);
public function importPage(
        $pageNumber,
        $box = PageBoundaries::CROP_BOX,
        $groupXObject = true,
        $importExternalLinks = false // <= here
)

benito103e pushed a commit that referenced this issue Nov 6, 2023
benito103e pushed a commit that referenced this issue Nov 6, 2023
benito103e pushed a commit that referenced this issue Nov 6, 2023
@benito103e
Copy link
Member

Fixed into #28 : you can upgrade to v2 of this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants