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

Can't use @page or something similar - Goal is to use a class for only the first page #3390

Open
8bamo opened this issue Feb 9, 2024 · 7 comments
Labels

Comments

@8bamo
Copy link

8bamo commented Feb 9, 2024

@bsweeney

In general all css rules are working but I can't define css, that should work only for the first page.

Is there any workaround?

Thanks and regards

@bsweeney
Copy link
Member

bsweeney commented Feb 9, 2024

You are correct that @page supports limited styling options. What type of styling are you attempting to apply only to the first page?

@8bamo
Copy link
Author

8bamo commented Feb 9, 2024

@bsweeney
Super simple, I want to give a div container "display: none;" and this only at the first page.

@bsweeney
Copy link
Member

bsweeney commented Feb 9, 2024

That is challenging with current feature support, but not impossible. It has to be done outside the document through callbacks. I think something like the following might work (untested, unoptimized):

$dompdf->setCallbacks([
    [
        'event' => 'begin_frame',
        'f' => function ($frame, $canvas, $fontMetrics) {
            $node = $frame->get_node();
            if ($node->hasAttributes() && ($id = $node->attributes->getNamedItem("id")) !== null && $id->nodeValue === "myid") {
                $style = $frame->get_style();
                if ($canvas->get_page_number() === 1) {
                    $style->set_used("display", "none");
                } else {
                    $style->set_used("display", "block");
                }
            }
        }
    ]
]);

There is a request to make @page usable as a selector (#1486), though there is no movement on that request at this time.

@8bamo
Copy link
Author

8bamo commented Feb 15, 2024

@bsweeney Where to place the class name?

@bsweeney
Copy link
Member

Sorry I left something out, sample updated. If you're identifying by the class attribute instead use getNamedItem("class")

@8bamo
Copy link
Author

8bamo commented Feb 27, 2024

Sadly it didn't worked out.

@bsweeney
Copy link
Member

If you share a sample of the HTML and PHP you tried I can try to figure out why not.

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

No branches or pull requests

2 participants