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

TCPDF Integration #10

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

TCPDF Integration #10

PhenX opened this issue Dec 6, 2012 · 25 comments

Comments

@PhenX
Copy link
Member

PhenX commented Dec 6, 2012

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

What would you like dompdf to do:

Use TCPDF (http://sourceforge.net/projects/tcpdf) instead of
R&OS because the former supports UTF-8.

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

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From luca.pri...@gmail.com on May 20, 2009 18:42:17
I can try to see how difficult would be to implement this if there isn't anybody
already doing it

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From ryan.mas...@gmail.com on May 20, 2009 18:46:01
No one is that I know of. Give everyone else a chance to comment before you do
though. (a day or two)

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From eclecticgeek on May 20, 2009 18:51:46
I'm not working on it. If you decide to give it a go take a look at
http://code.google.com/p/dompdf/source/browse/trunk/dompdf/include/tcpdf_adapter.cls.php
for a head start.

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From luca.pri...@gmail.com on May 20, 2009 22:16:35
OK

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From luca.pri...@gmail.com on May 22, 2009 22:56:04
I have something working. Many of the tests that come with DOMPDF work.
So far I have 2 main things left:

  1. getting fonts right
  2. PDF 'objects' support

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From luca.pri...@gmail.com on May 25, 2009 20:51:09
State of the development.

All the DOMPDF samples run, but the output not always looks exactly the same as
with the CPDF lib (sometimes objects are positioned with a 1-2 pixels difference).

TCPDF does not seem to support template objects. I have tried a couple of
workarounds, but I have only tested them with simple objects.

So far, I have tested using only Helvetica and Times-Roman fonts.

TCPDF also does not seem to distinguish between lines and fill transparency, so that
transparency is applied to both at the same time.

I am still testing. At which point should I submit the source code? An attachment
here is fine?

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From gaplev...@gmail.com on July 27, 2009 20:06:27
it would be nice to see your patch at least here until it reach repository

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From carlshol...@gmail.com on April 09, 2010 15:49:45
If we eventually want full unicode support I guess TCPDF is the only way to go unless someone wants to
completely rewrite CPDF for unicode – I have tried a few times but never had the time to finish it. TCPDF is a bit
"heavy" and would probably need to be slimmed for use in dompdf.
If Luca isn't still around perhaps I'll have a go at doing the adaptor.

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From luca.pri...@gmail.com on April 19, 2010 18:49:08
I tested it only with the examples present in the dompdf/www/test directory. They
works although with some differences in respect to using CPDF, mainly in the area of
line/font hight. I have done the tests with Ubuntu 8.04 and 9.10. A couple of the
unicode tests fail under Ubuntu 9.10. It might be a bug with PHP. I have seen the
same error message reported several times in the net.

The TCPDF version I used is 4.9.012. The DOMPDF version was taken from the SVN on
2010-04-13.

I have added the following files and directories to the project tree:

include/tcpdf_adapter.cls.php (the TCPDF adapter)
lib/tcpdf/ (from tcpdf_4_9_012.zip)
tests/ (my test dir)

I have also made some minor changes to the DOMPDF files, essentially to take into
account the presence of this adapter.

In the tests/ dir you will find a python script (tests.py) that runs all the tests
present in www/test/. It puts the resulting PDFs in the tests/TCPDF dir (or in
tests/CPDF if you run it with the option '-l CPDF', in which case it will use the
CPDF library instead).

I have also added a couple of command line options to dompdf.php to help the debugging.

This library must be considered a very very very ... early work. I have worked
considering TCPDF as a black box, trying to find what are the interface differences
with CPDF and PDFLIB, and working out from these. I didn't go into the PDF code
produced, due mainly to lack of time to spend on it.

There are few implementation details to point out:

  1. i didn't find in the TCPDF docs, an equivalent to the CPDF methods openObject(),
    closeObject(), reopenObject(). They might well be there, however... Therefore I have
    subclassed the TCPDF class to add them, and have done a very rough implementation,
    just to make the test examples work. Basically, in the openObject() I save the TCPDF
    output buffer, reinitialize it to an empty string and in the closeObject() I take the
    output collected since the openObject(), save it for later use, and restore the
    content of the TCPDF output buffer to the state it was before the call to the
    openObject().

  2. it seems from the docs that TCPDF handles internal links using page numbers as
    href target, and not arbitrary names. I don't know if I interpreted the docs well, in
    any case I maintain the mapping myself within the adapter and apply it at the end.

  3. i did not implement disk caching. The produced output is kept in memory.

  4. i didn't keep track of the page number and page count in the adapter
    ($_page_number and $_page_count variables) since it looks like TCPDF has similar
    variables publicly accessible.

  5. the DOMPDF library has few calls to the get_cpdf() method even when another
    adapter is used. I have renamed these calls to get_lib_obj() and changed the adapters
    code accordingly

In the end I hope that this can be of some use to someone

Bye

Luca

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From luca.pri...@gmail.com on April 24, 2010 08:40:11
This is the latest version that works with DOMPDF r255.
It has some fixes to better resemble the output obtained with CPDF.
More work on fonts to be done

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From fabien.menager on April 24, 2010 10:28:06
Hello Luca, could you join a patch instead of a full copy of DOMPDF ? This is easier
for us to test it.
I'm maybe going to add an API to render form fields, and TCPDF would be the first
adapter to support it as it is the only one that can render forms. I think this will be
for the 0.7 or 0.6.1 release

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From d.sandi...@gmail.com on April 21, 2011 04:31:28
I am using dompdf 0.6 beat2 version with tcpdf 5.9, so I put tcpdf library in Lib folder.When i render it , it gives me a fatal error.So is dompdf 0.6beat2 is not compatible with tcpdf 5.9?

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From fabien.menager on April 21, 2011 06:16:02
Hello, no TCPDF is currently not supported by DOMPDF, what is the reason why you need it to be supported?

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From d.sandi...@gmail.com on April 21, 2011 06:35:47
Hello,
I am using dom pdf and I need "Copyright © 2011 MiningIQ. All
rights reserved." to be appeared at every page in footer section.So for that
case I am used this code:-

<script type="text/php"> if ( isset($pdf) ) { $font = Font_Metrics::get_font("sans-serif"); $size = 6; $color = array(0,0,0); $text_height = Font_Metrics::get_font_height($font, $size); $copy_right_obj = $pdf->open_object(); $w = $pdf->get_width(); $h = $pdf->get_height(); // Draw a line along the bottom $y = $h - 0.5 * $text_height - 15; $pdf->line(16, $y, $w - 16, $y, array(0,0,0), 1); $y += $text_height; $text2 = "Copyright © 2011 MiningIQ. All rights reserved."; $width = Font_Metrics::get_text_width($text2, $font, $size); $center_area = $w / 2 - $width / 2; $pdf->text($center_area, $y, $text2, $font, $size, $color); $text = "Page {PAGE_NUM} of {PAGE_COUNT}"; $width = Font_Metrics::get_text_width("Page 1 of 2", $font, $size); $left_corner_area = $w - 16 - $width; $pdf->page_text($left_corner_area, $y, $text, $font, $size, $color); $pdf->close_object(); $pdf->add_object($copy_right_obj, "all"); } </script>

But it does not render "©" that means copy right symbol and it prints
"©" at the footer section.So what should I do?
Also I have used tcpdf and see that type of character is rendered properly
in PDF using TCPDF.So i want to use TCPDF in back end of dom pdf

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From eclecticgeek on April 21, 2011 18:44:56
Text added via inline script is not parsed, so you'll have to use the actual character you want to include. If you don't know how to type that character you can do something like the following:

$text2 = html_entity_decode("Copyright &copy; 2011 MiningIQ. All rights reserved.", ENT_QUOTES, 'UTF-8');

(if UTF-8 doesn't work, try 'iso-8859-1')

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From d.sandi...@gmail.com on April 22, 2011 09:33:22

$text2 = html_entity_decode("Copyright &copy; 2011 MiningIQ. All rights reserved.", ENT_QUOTES, 'iso-8859-1');

and it wors for me!.
Thanks

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From d.sandi...@gmail.com on April 22, 2011 09:35:57
But this codes leads me extra coding for adding text at header and footer section.TCPDF has default method($pdf->addHeader() and $pdf->addFooter()) for adding text at header and footer sections.So please correct tcpdf adapter code so that we can use TCPDF as backend pdf generation in DOM PDF.

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From eclecticgeek on April 22, 2011 14:12:24
TCPDF integration is not a high priority at this point. When Luca did some initial investigation he found the changes to TCPDF between revisions would make it difficult to maintain a compatible adapter. I don't know if this still holds true, and won't be able to do so until work on this request begins.

However, a minor change to the adapter written by Luca should help with your particular issue. Add the following code to the class definition contained within tcpdf_adapter.cls.php:

  function get_pdflib() { return $this->_pdf; }

Now, in your inline script you can access the TCPDF class (and all its methods and properties) directly:

  $pdf->get_tcpdf();

Or from the script where you instantiate DOMPDF (after you call $dompdf->render()):

  $dompdf->get_canvas()->get_tcpdf();

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From d.sandi...@gmail.com on April 25, 2011 05:08:27
Hello,
I have configured TCPDF in domodf_config.inc.php as

def("DOMPDF_PDF_BACKEND", "TCPDF");

and in tcpdf_adapter.cls.php , I have used this code:-

  function get_pdflib() { return $this->_pdf; }

but gives me this error:-

" Fatal error: Declaration of TCPDF_Adapter::get_text_width() must be
compatible with that of Canvas::get_text_width() in *
C:\wamp\www\dompdf\include\tcpdf_adapter.cls.php* on line 58"

What should I do now?

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From sandipgh...@indusnet.co.in on May 02, 2011 12:44:45
Please give me a suggestion about it?as I am helpless!.Plase also can u give a one shot function that should be used to put header text and footer text at pdf.Now I have to calculate the header and footer portion of a single pdf page.So I need a handful functions through which I can put header text/image to pdf.

@PhenX
Copy link
Member Author

PhenX commented Dec 6, 2012

From rakesh.g...@gmail.com on November 10, 2011 13:44:52
Hi this work in the core PHP but i try to create the joomla module for this so everybody can use this module but i getting some errors like "Fatal error: Class 'DOMPDF' not found in E:\wamp\www\Joomla162\modules\mod_pdfcreate\mod_pdfcreate.php on line 12" so how i can do the solution for this problem.
i also try to include the class file but not getting the output so please help me i want to complete it as soon as possible.

@PhenX
Copy link
Member Author

PhenX commented Feb 22, 2013

I can't see the point in integrating TCPDF, as I find this library too much heavy and really badly written. CPdf suits largely better for dompdf.

@PhenX PhenX closed this as completed Feb 22, 2013
@bsweeney
Copy link
Member

@PhenX I think it'd be nice to support a wider range of rendering libraries, but I'm inclined to agree. You're not the first to comment on the difficulty of supporting TCPDF. Few people using dompdf will need a library other than CPDF or PDFLib (though obviously there's a contingent out there that would still like to see TCPDF supported).

@PhenX
Copy link
Member Author

PhenX commented Feb 24, 2013

@bsweeney in fact I dont see the point in supporting other libraries. If Cpdf is not enough, why not work on it?

@bsweeney
Copy link
Member

@PhenX don't get me wrong. I don't disagree. There's little point right now in devoting efforts on supporting other libraries when we have so much other work to do. I guess I look at it as more of a nice possibility, especially if a library similar to PDFLib (but perhaps open source) can be integrated. But I look at this as more of an academic value (the modularization of the back end) not something we need to continue working on to the detriment of other needs.

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

2 participants