sivasekar / dompdf

Automatically exported from code.google.com/p/dompdf
0 stars 0 forks source link

TCPDF Integration #3

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 reported on code.google.com by ryan.mas...@gmail.com on 29 Apr 2009 at 6:07

GoogleCodeExporter commented 9 years ago
I can try to see how difficult would be to implement this if there isn't anybody
already doing it

Original comment by luca.pri...@gmail.com on 20 May 2009 at 6:42

GoogleCodeExporter commented 9 years ago
No one is that I know of. Give everyone else a chance to comment before you do
though. (a day or two)

Original comment by ryan.mas...@gmail.com on 20 May 2009 at 6:46

GoogleCodeExporter commented 9 years ago
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_adapte
r.cls.php>
for a head start.

Original comment by eclecticgeek on 20 May 2009 at 6:51

GoogleCodeExporter commented 9 years ago
OK

Original comment by luca.pri...@gmail.com on 20 May 2009 at 10:16

GoogleCodeExporter commented 9 years ago
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

Original comment by luca.pri...@gmail.com on 22 May 2009 at 10:56

GoogleCodeExporter commented 9 years ago
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?

Original comment by luca.pri...@gmail.com on 25 May 2009 at 8:51

GoogleCodeExporter commented 9 years ago
it would be nice to see your patch at least here until it reach repository

Original comment by gaplev...@gmail.com on 27 Jul 2009 at 8:06

GoogleCodeExporter commented 9 years ago
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.

Original comment by carlshol...@gmail.com on 9 Apr 2010 at 3:49

GoogleCodeExporter commented 9 years ago
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

Original comment by luca.pri...@gmail.com on 19 Apr 2010 at 6:49

Attachments:

GoogleCodeExporter commented 9 years ago
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

Original comment by luca.pri...@gmail.com on 24 Apr 2010 at 8:40

Attachments:

GoogleCodeExporter commented 9 years ago
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

Original comment by fabien.menager on 24 Apr 2010 at 10:28

GoogleCodeExporter commented 9 years ago
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?

Original comment by d.sandi...@gmail.com on 21 Apr 2011 at 4:31

GoogleCodeExporter commented 9 years ago
Issue 269 has been merged into this issue.

Original comment by fabien.menager on 21 Apr 2011 at 6:15

GoogleCodeExporter commented 9 years ago
Hello, no TCPDF is currently not supported by DOMPDF, what is the reason why 
you need it to be supported?

Original comment by fabien.menager on 21 Apr 2011 at 6:16

GoogleCodeExporter commented 9 years ago
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

Original comment by d.sandi...@gmail.com on 21 Apr 2011 at 6:35

GoogleCodeExporter commented 9 years ago
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 © 2011 MiningIQ. All rights reserved.", 
ENT_QUOTES, 'UTF-8');

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

Original comment by eclecticgeek on 21 Apr 2011 at 6:44

GoogleCodeExporter commented 9 years ago
$text2 = html_entity_decode("Copyright © 2011 MiningIQ. All rights reserved.", 
ENT_QUOTES, 'iso-8859-1');

and it wors for me!.
Thanks

Original comment by d.sandi...@gmail.com on 22 Apr 2011 at 9:33

GoogleCodeExporter commented 9 years ago
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.

Original comment by d.sandi...@gmail.com on 22 Apr 2011 at 9:35

GoogleCodeExporter commented 9 years ago
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();

Original comment by eclecticgeek on 22 Apr 2011 at 2:12

GoogleCodeExporter commented 9 years ago
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?

Original comment by d.sandi...@gmail.com on 25 Apr 2011 at 5:08

GoogleCodeExporter commented 9 years ago
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. 

Original comment by sandipgh...@indusnet.co.in on 2 May 2011 at 12:44

GoogleCodeExporter commented 9 years ago
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.

Original comment by rakesh.g...@gmail.com on 10 Nov 2011 at 1:44

GoogleCodeExporter commented 9 years ago

Original comment by eclecticgeek on 24 May 2013 at 3:00