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

Support for ordered lists #14

Closed
PhenX opened this issue Dec 6, 2012 · 10 comments
Closed

Support for ordered lists #14

PhenX opened this issue Dec 6, 2012 · 10 comments

Comments

@PhenX
Copy link
Member

PhenX commented Dec 6, 2012

Original author: ryan.mas...@gmail.com (April 29, 2009 18:09:51)

What would you like dompdf to do:

ordered lists are currently not supported

Original issue: http://code.google.com/p/dompdf/issues/detail?id=7

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From sven.rym...@gmail.com on June 24, 2009 06:28:54
I added support for ordered lists.

Modify dompdf.cls.php as documented below:

      // FIXME: handle generated content
      if ( $frame->get_style()->display == "list-item" ) {

        // Insert a list-bullet frame
        $node = $this->_xml->createElement("bullet"); // arbitrary choice
        $b_f = new Frame($node);

//---NEW CODE---
        $index = 0;
        if(!$frame->get_parent()->get_node()->hasAttribute("-dompdf-counter"))
        {
          $index = 1;
          $frame->get_parent()->get_node()->setAttribute("-dompdf-counter", 1);
        }
        else
        {
          $index = $frame->get_parent()->get_node()->getAttribute("-dompdf-counter");
          $index++;
          $frame->get_parent()->get_node()->setAttribute("-dompdf-counter", $index);
        }
        $node->setAttribute("-dompdf-counter", $index);
//---END NEW CODE---

        $style = $this->_css->create_style();
        $style->display = "-dompdf-list-bullet";
        $style->inherit($frame->get_style());
        $b_f->set_style($style);

        $deco->prepend_child( Frame_Factory::decorate_frame($b_f, $this) );
      }

Next modify the file list_bullet_renderer.cls.php (switch statement):

      case "none": // Already documented in another thread.
        break;

      case "decimal": // Here you go, the ordered list stuff!
        list($x, $y) = $frame->get_position();
        $index = $frame->get_node()->getAttribute("-dompdf-counter");
        $text = sprintf('%d.', $index);
        $font = $style->font_family;
        $size = $style->font_size;
        $height = $style->height;    
        $spacing = 0; //$frame->get_text_spacing() + $style->word_spacing;

        if ( preg_replace("/[\s]+/", "", $text) == "" )
          return;

        $this->_canvas->text($x, $y, $text,
                             $font, $size,
                             $style->color, $spacing);

        $x += Font_Metrics::get_text_width($text, $style->font_family,
$style->font_size, $spacing);

        break;

The outline of the list can be better, so you should modify the
list_bullet_renderer.cls.php file as well, but this is a first step.

Hope this helps in making dompdf even better.

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From tobias.t...@gmail.com on October 20, 2009 14:42:09
Hi,

I needed this for more ordered list types (roman, alpha, etc.)
Thanks for providing the patch for ordered lists Sven!

TT

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From charlie....@gmail.com on February 17, 2010 23:17:17
Thanks a million, works very well. The margin styling is a little rough but I can fix
that next!

For anyone needing them, attached are the 2 files with the updated code.

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From ryan.mas...@gmail.com on March 11, 2010 23:11:28
When submitting code fixes, please submit them as a .patch file.

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From blorri...@gmail.com on March 21, 2010 18:47:29
Thanks for this - but when I replaced the files (dompdf.cls.php and
list_bullet_renderer.cls.php) I get a blank screen. I went back to the original
files and it worked again . . . but of course I'm trying to show ordered lists in the
pdf, so I'd really like to get this to work.

Any suggestions?

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From fabien.menager on March 25, 2010 12:37:59
I commited the patch with a few changes in r236. Please report any problem here.

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From eclecticgeek on June 24, 2010 19:08:59
There was an issue where lists specifying lower alpha would render in upper. Addressed in r276.

Sander Bol reported this problem and supplied a fix.

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From fabien.menager on July 27, 2010 19:55:01
I think I can close this issue as ordered lists are now fully supported.
The only point that may remain is that the List_Bullet_Renderer chich renders the ordered lists could be renamed now to List_Renderer, but this is not the same problem.

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From zlatea.a...@redkiwi.ro on October 04, 2012 11:29:15
Hello,

Have solved someone the issue with margin styling? thank you

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From eclecticgeek on October 04, 2012 18:14:28
@zlatea the issue you're asking about does not appear to be related to this enhancement request. Can you open a new issue to report the bug.

@PhenX PhenX closed this as completed Dec 6, 2012
Javdu10 added a commit to Javdu10/dompdf that referenced this issue Oct 20, 2021
…owed path(s)

Hello!

So I had a weird error in my Laravel project using the libs `dompdf/dompdf`, `barryvdh/laravel-dompdf` and `laraveldaily/laravel-invoices` 

The function `Dompdf\\Cpdf->openFont()` were called with an empty $font, it was on shared hosting with open_basedir restrictions.

Here is the full stacktrace: 

```
[2021-10-20 20:23:47] production.INFO: FONT LOADED: /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/lib/fonts/Helvetica  
[2021-10-20 20:23:47] production.INFO: FONT LOADED: /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/lib/fonts/DejaVuSans  
[2021-10-20 20:23:47] production.INFO: FONT LOADED: /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/lib/fonts/Times-Bold  
[2021-10-20 20:23:47] production.INFO: FONT LOADED: /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/lib/fonts/DejaVuSans-Bold  
[2021-10-20 20:23:47] production.INFO: FONT LOADED:   
[2021-10-20 20:23:47] production.ERROR: file_exists(): open_basedir restriction in effect. File(/.ufm) is not within the allowed path(s): (/:/tmp/) {"userId":1,"exception":"[object] (ErrorException(code: 0): file_exists(): open_basedir restriction in effect. File(/.ufm) is not within the allowed path(s): (/:/tmp/) at /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/lib/Cpdf.php:3341)
[stacktrace]
#0 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
dompdf#1 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/lib/Cpdf.php(3341): file_exists()
dompdf#2 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/lib/Cpdf.php(3549): Dompdf\\Cpdf->openFont()
dompdf#3 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/Adapter/CPDF.php(1030): Dompdf\\Cpdf->selectFont()
dompdf#4 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/FontMetrics.php(327): Dompdf\\Adapter\\CPDF->get_text_width()
dompdf#5 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/FontMetrics.php(294): Dompdf\\FontMetrics->getTextWidth()
dompdf#6 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/PhpEvaluator.php(53) : eval()'d code(6): Dompdf\\FontMetrics->get_text_width()
dompdf#7 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/PhpEvaluator.php(53): eval()
dompdf#8 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/PhpEvaluator.php(61): Dompdf\\PhpEvaluator->evaluate()
dompdf#9 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/Renderer.php(293): Dompdf\\PhpEvaluator->render()
dompdf#10 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/Renderer.php(138): Dompdf\\Renderer->_render_frame()
dompdf#11 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/Renderer.php(194): Dompdf\\Renderer->render()
dompdf#12 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/FrameReflower/Page.php(148): Dompdf\\Renderer->render()
dompdf#13 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/FrameDecorator/AbstractFrameDecorator.php(895): Dompdf\\FrameReflower\\Page->reflow()
dompdf#14 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/Dompdf.php(838): Dompdf\\FrameDecorator\\AbstractFrameDecorator->reflow()
dompdf#15 /httpdocs/plugins/invoicepro/vendor/barryvdh/laravel-dompdf/src/PDF.php(208): Dompdf\\Dompdf->render()
dompdf#16 /httpdocs/plugins/invoicepro/vendor/barryvdh/laravel-dompdf/src/PDF.php(155): Barryvdh\\DomPDF\\PDF->render()
```

The `FONT LOADED` part was to log the current font and was placed just above where the error was at `Cpdf.php(3341)`
Javdu10 added a commit to Javdu10/dompdf that referenced this issue Oct 31, 2021
…owed path(s)

Hello!

So I had a weird error in my Laravel project using the libs `dompdf/dompdf`, `barryvdh/laravel-dompdf` and `laraveldaily/laravel-invoices` 

The function `Dompdf\\Cpdf->openFont()` were called with an empty $font, it was on shared hosting with open_basedir restrictions.

Here is the full stacktrace: 

```
[2021-10-20 20:23:47] production.INFO: FONT LOADED: /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/lib/fonts/Helvetica  
[2021-10-20 20:23:47] production.INFO: FONT LOADED: /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/lib/fonts/DejaVuSans  
[2021-10-20 20:23:47] production.INFO: FONT LOADED: /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/lib/fonts/Times-Bold  
[2021-10-20 20:23:47] production.INFO: FONT LOADED: /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/lib/fonts/DejaVuSans-Bold  
[2021-10-20 20:23:47] production.INFO: FONT LOADED:   
[2021-10-20 20:23:47] production.ERROR: file_exists(): open_basedir restriction in effect. File(/.ufm) is not within the allowed path(s): (/:/tmp/) {"userId":1,"exception":"[object] (ErrorException(code: 0): file_exists(): open_basedir restriction in effect. File(/.ufm) is not within the allowed path(s): (/:/tmp/) at /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/lib/Cpdf.php:3341)
[stacktrace]
#0 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
dompdf#1 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/lib/Cpdf.php(3341): file_exists()
dompdf#2 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/lib/Cpdf.php(3549): Dompdf\\Cpdf->openFont()
dompdf#3 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/Adapter/CPDF.php(1030): Dompdf\\Cpdf->selectFont()
dompdf#4 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/FontMetrics.php(327): Dompdf\\Adapter\\CPDF->get_text_width()
dompdf#5 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/FontMetrics.php(294): Dompdf\\FontMetrics->getTextWidth()
dompdf#6 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/PhpEvaluator.php(53) : eval()'d code(6): Dompdf\\FontMetrics->get_text_width()
dompdf#7 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/PhpEvaluator.php(53): eval()
dompdf#8 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/PhpEvaluator.php(61): Dompdf\\PhpEvaluator->evaluate()
dompdf#9 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/Renderer.php(293): Dompdf\\PhpEvaluator->render()
dompdf#10 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/Renderer.php(138): Dompdf\\Renderer->_render_frame()
dompdf#11 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/Renderer.php(194): Dompdf\\Renderer->render()
dompdf#12 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/FrameReflower/Page.php(148): Dompdf\\Renderer->render()
dompdf#13 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/FrameDecorator/AbstractFrameDecorator.php(895): Dompdf\\FrameReflower\\Page->reflow()
dompdf#14 /httpdocs/plugins/invoicepro/vendor/dompdf/dompdf/src/Dompdf.php(838): Dompdf\\FrameDecorator\\AbstractFrameDecorator->reflow()
dompdf#15 /httpdocs/plugins/invoicepro/vendor/barryvdh/laravel-dompdf/src/PDF.php(208): Dompdf\\Dompdf->render()
dompdf#16 /httpdocs/plugins/invoicepro/vendor/barryvdh/laravel-dompdf/src/PDF.php(155): Barryvdh\\DomPDF\\PDF->render()
```

The `FONT LOADED` part was to log the current font and was placed just above where the error was at `Cpdf.php(3341)`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant