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 create a page with 4 equals squares #2468

Closed
Defacta opened this issue Jun 2, 2021 · 7 comments · Fixed by #2506
Closed

Can't create a page with 4 equals squares #2468

Defacta opened this issue Jun 2, 2021 · 7 comments · Fixed by #2506

Comments

@Defacta
Copy link

Defacta commented Jun 2, 2021

Hello,

I try to create a A4 page with 4 equals parts.

I tried with inline div and with table but with no success.

With tables:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Header and Footer example</title>
<style type="text/css">
* {
    margin:0;
    padding:0;
}
@page {
  margin: 0;
}
.bg-red {
  background:red;
}
.bg-green {
  background:green;
}
.bg-grey {
  background:#ddd;
}
</style>
</head>
<body>
<table class="bg-red" style="width:100%;line-height:0;" cellspacing="0" cellpadding="0">
<tr>
  <td class="bg-grey" style="width:50%;height:50%;line-height:0;">Square 1</td>
  <td class="bg-green" style="width:50%;height:50%;line-height:0;">Square 2</td>
</tr>
<tr>
  <td class="bg-green" style="width:50%;height:50%;line-height:0;">Square 3</td>
  <td class="bg-grey" style="width:50%;height:50%;line-height:0;">Square 4</td>
</tr>
</table>
</body>
</html>

Result:
image

Is there any chance to do it?

If I try with height at 49%, there is a big white line at the bottom of the page.

Thanks,
Vincent.

@bsweeney
Copy link
Member

bsweeney commented Jun 2, 2021

This rendered as expected when I ran it through my test bed. Which version of Dompdf are you using?

@Defacta
Copy link
Author

Defacta commented Jun 2, 2021

This rendered as expected when I ran it through my test bed. Which version of Dompdf are you using?

1.0.2 and I also tried on 0.8.5.

To construct the package I did:

git clone https://github.com/dompdf/dompdf/
cd dompdf/
composer install --no-dev --optimize-autoloader

To create the PDF I do:

require_once (__DIR__.'/'._PATHROOT.'include/php/0_libraries/pdf/dompdf/1.0.2/vendor/autoload.php');

$options = new \Dompdf\Options();
$options->set('isRemoteEnabled', true);
$options->set('isPhpEnabled', true);
$dompdf = new \Dompdf\Dompdf($options);
$dompdf->set_option('dpi', 300);
$dompdf->set_paper('A4', 'portrait');

$html = '...';

$dompdf->load_html($html);
$dompdf->render();
$output = $dompdf->output();
file_put_contents('test.pdf', $output);

@Defacta
Copy link
Author

Defacta commented Jun 2, 2021

What is strange is I do that:

<table>
  <tr>
    <td class="bg-red" height="200px" width="200px">
      <table>
        <tr>
          <td class="bg-green" height="50%" width="200px">
          </td>
      </table>
    </td>
  </tr>
</table>

The second cell bg-green of the second table should have a height of 50% of 200px, so 100px, but the height is 50% of the entire page instead of the td in which the table is.
It's like it does not inherit of the parent height and takes 50% of all the page. Is it normal?
image

@bsweeney
Copy link
Member

bsweeney commented Jun 3, 2021

The second issue you noted is probably related to #2255. It could be implicated in the issue you have rendering the document. If possible, an absolute unit may give you more consistent results.

@Nexample-G
Copy link

Your Solution here
https://youtu.be/wcAoC8P5gaM

@Mellthas
Copy link
Member

This is fixed by the changes to handling empty text nodes in #1356. The issue can be worked around by removing the whitespace between the body and table tags (and fixing the spelling of </boyd> :-)).

Mellthas added a commit to Mellthas/dompdf that referenced this issue Aug 1, 2021
Before, page breaks before empty text nodes were not allowed, but they
were still checked; and as they report their line height as the space
needed, they could force a page break, which then would continue to
search backwards in the tree for an element that allowed a page break
(even though it would fit on the current page).

Based on work in dompdf#1356
Fixes dompdf#2468
@bsweeney bsweeney linked a pull request Aug 26, 2021 that will close this issue
Mellthas added a commit to Mellthas/dompdf that referenced this issue Aug 27, 2021
Before, page breaks before empty text nodes were not allowed, but they
were still checked; and as they report their line height as the space
needed, they could force a page break, which then would continue to
search backwards in the tree for an element that allowed a page break
(even though it would fit on the current page).

Based on work in dompdf#1356
Fixes dompdf#2468

Co-authored-by: David Sickmiller <david@sickmiller.com>
bsweeney pushed a commit that referenced this issue Sep 6, 2021
Before, page breaks before empty text nodes were not allowed, but they
were still checked; and as they report their line height as the space
needed, they could force a page break, which then would continue to
search backwards in the tree for an element that allowed a page break
(even though it would fit on the current page).

Based on work in #1356
Fixes #2468
@bsweeney
Copy link
Member

bsweeney commented Sep 6, 2021

Regarding that last sample, the inner height should be on the table element instead of the cell. This is because the block formatting context for the cell is the table, which has no height. Dompdf is still wrong, but the rendering should be no height instead of that indicated in your comment.

Also, Dompdf does not current support the height attribute on table elements, so you should use a style attribute instead.

The following is rendered correctly:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Header and Footer example</title>
<style type="text/css">
* {
    margin:0;
    padding:0;
}
@page {
  margin: 0;
}
.bg-red {
  background:red;
}
.bg-green {
  background:green;
}
.bg-grey {
  background:#ddd;
}
</style>
</head>
<body>
    <table>
        <tr>
          <td class="bg-red" height="200px" width="200px">
            <table style="height:50; width:200px">
              <tr>
                <td class="bg-green">
                </td>
            </table>
          </td>
        </tr>
      </table>
      </body>
</html>

@bsweeney bsweeney closed this as completed Sep 6, 2021
liam-milbel added a commit to Milestone-Belanova/dompdf that referenced this issue Sep 16, 2021
* Moving the PDF version to a `const`

* Remove unused import

* Coding standards: Enable more PSR-2 rules

Enable rules which should be uncontroversial and easy to fix.

* Apply coding-standards changes to files

* Travis: Also check tests dir for coding standards

* Update IMagick version check logic

fixes dompdf#1296

* Fix scoping issue for IMagick version check

* fix Trying to access array offset on value of type null (dompdf#2227)

* fix Trying to access array offset on value of type null

* space

* fix css selector issue

* Fall back to decimals for roman numerals, if out of range

Consistent with how web browsers do it.

See https://en.wikipedia.org/wiki/Roman_numerals#Standard_form

* Stylesheet: Rename and document `_image` method for clarity

* Stylesheet: Make `resolve_url` public to reduce code duplication

* FontMetrics: Fix text-width calculations when using different backends

Fixes issue dompdf#2403.

* FontMetrics: Use direct access for protected properties

* Extend tests for resolving URLs in stylesheets

Without `$sheet->set_base_path(__DIR__)`, the stylesheet location would
be the location of phpunit.

* Fix instantiating CPDF Adapter without Dompdf

* Avoid offset error in CPDF line trasparency logic

related to dompdf#2227

* Use strict comparison in CPDF transparency logic

* Stylesheet: Improve return-value check

* Remove temporary file created when caching an image. (dompdf#2411)

* Remove temporary file created when caching an image.
dompdf#2377

* move unlink() to exception catch block

* Fix text-width calulation with letter spacing (dompdf#2414)

* Consistent doc for `get_text_width` arguments

To clear up the confusion about whether word and char spacing can be
float.

* CPDF: Fix text-width calulation with letter spacing

The letter spacing was counted twice for every space character.

* PDFLib: Fix text-width calculation with letter spacing

See discussion in dompdf#2414.

* Use OS-indepenent file path for unit test

* BlockFrameReflower: Always resolve `auto` widths

* Fix undefined variable (dompdf#2466)

* Bump version to 0.8.6

* Reset version string to commit hash

* Bump version to 1.0.1

* Reset version string to commit hash

* Bump version to 1.0.2

* Reset version string to commit hash

* Fix undefined variable

* Fix indentation

* Fix undefined variable

* Update src/FontMetrics.php

* Update src/FontMetrics.php

Co-authored-by: Brian Sweeney <brian@eclecticgeek.com>

* Add support for `page-break-before/-after` on table rows

pr dompdf#2512:

* Fix some typos

* Update documentation text for `_page_break_allowed`

Mainly to clear up a few unclear points that have changed. The comment
about table headers does not apply anymore.

* Add support for `page-break-before/-after` on table rows

Caveat: `page-break-after: always` does not work if the row is the last
of its table row group. I want to keep things simple now; this might be
better fixed in a proper rework of the page-break-properties handling,
e.g. by properly propagating the property values as per
https://www.w3.org/TR/css-break-3/#break-propagation.

Fixes dompdf#329

* BlockFrameReflower: Fixes to height calculations (dompdf#2511)

Brings the code closer to the spec:
* Always resolve `auto` heights
* Apply `min-/max-height` independently of the `overflow` property
value
* `min-height` overrules `max-height` (swapping removed)

* Prevent case exception in text renderer (dompdf#2423)

In case of " auto " width is throws an error as following and breaks the PDF render.
ErrorException: A non-numeric value encountered in /Path_To_Project/vendor/dompdf/dompdf/src/Renderer/Text.php:158

type casting the $width to float will prevent the ErrorException

* Resolve auto margins in more cases (dompdf#2531)

Fixes dompdf#1482

* Properly skip checking for page breaks on empty text nodes (dompdf#2506)

Before, page breaks before empty text nodes were not allowed, but they
were still checked; and as they report their line height as the space
needed, they could force a page break, which then would continue to
search backwards in the tree for an element that allowed a page break
(even though it would fit on the current page).

Based on work in dompdf#1356
Fixes dompdf#2468

* Fix table column widths after page break (dompdf#2502)

Node attributes are always string, so when a table was laid out, and
then a page break occurred before the table at a later point, `$colspan`
and `$rowspan` would always be string values and fail the checks below,
most notably the check where the minimum column width is set, so that
all columns received `0` minimum width.

Fixes dompdf#2395

* Add support for any inline-positioned frames in text alignment

This notably adds support for inline-block.

Fixes dompdf#1761

* Fix `justify` text alignment with letter spacing

The old logic seemed to correct for wrong text-width calculation
involving letter spacing when using the CPDF backend. With the fix in
dompdf#2414 this is no longer needed.

* Improve support for relative positioning

* Move handling of relative positioning to after the reflow process, so
that it does not affect layout.
* Handle `right` and `bottom` properties plus `auto` values (except for
RTL language support, which is an easy FIXME).
* As a side-effet, this adds support for relative positioning on inline
and inline-block elements.

Fixes dompdf#516

* Fix logic error in `add_frame_to_line` function

The block must check its own content-box width, not the content-box
width of its containing block when placing child frames.

Fixes dompdf#2476.

* Apply line shift to justified lines with break

* Tweak Style border/outline method color handling

fixes dompdf#2367

* BlockFrameReflower: Fix handling of `100%` width

The condition is wrong, as an `auto` width can resolve to more than
100% if the minimum width of the content is larger.

* BlockFrameReflower: Remove swapping of `min-/max-width`

Per spec, `min-width` overrules `max-width`.

https://www.w3.org/TR/CSS21/visudet.html#min-max-widths

* Remove erroneous ‘degenerate’ case handling in `get_min_max_width`

If the frame has no children, it might still have a fixed width set.

Fixes dompdf#2366

* Small code cleanups (dompdf#2547)

* Clean up `get_margin_height/width` functions

For simplicity, return a `float` value consistently.
The `get_break_margins` method was unused.

* TextReflower: Small cleanup for `get_min_max_width`

Also, add type declarations to `_collapse_white_space`.

* Clean up `split` method signatures

Consistent argument names and more type declarations.

Co-authored-by: Thomas Landauer <thomas@landauer.at>
Co-authored-by: Till Berger <till@mellthas.de>
Co-authored-by: Brian Sweeney <brian@eclecticgeek.com>
Co-authored-by: Edwin Manuel Cerrón Angeles <xerron.angels@gmail.com>
Co-authored-by: Ion Bazan <ion.bazan@gmail.com>
Co-authored-by: bradbulger <1234634+bradbulger@users.noreply.github.com>
Co-authored-by: Jáchym Toušek <enumag@gmail.com>
Co-authored-by: Madi <mudasser.ismail@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants