another dream that comes up by useing this excellent module. As TCPDF is supporting CSS (or, as they describe, at least some of it) would it be possible to leave it up to the user, if he/she wants to use print.css or another display css for the output of the Element and as default use print.css anyway. As the created PDF will be used for print out, that would make sense to me a lot. May be even with support for CMYK colors according to W3C Working draft for CSS 3. I know that's a big one...just a dream

Comments

hunziker’s picture

Can you explain more precisely describe what you like to have? You reference to TCPDF documentation. Can you post the link to the documentation?

m-si’s picture

Sorry for the delay, another project needed my attention. According to www.tcpdf.org/index.php in Main features TCPDF seems to be capabel to process CSS "methods to publish some XHTML + CSS code, Javascript and Forms". For me using CSS would be the chance to have less granularity in my nodes.

E.g. right now I do have a Textfield area in my node and im allowing user to put some predefined css clases during node genration for styling purpose (e.g. Textsize, color etc.) im using print.css to restyle the same classes for print output. Now assuming that I use the testfield in my PDF output through your module, it would be fantastic if the styles I uesd in print.css will be used to style the output in the PDF (for instance set the Textsize, the color to cmyk (that one would be only possible if I do print.css according to the working draft for css 3)).

so for instance if I use a style like

h3 {
  color: #7AB800;
  color: cmyk(0.59, 0.0, 1.0, 0.0);
}

in my css, it would be fantastic if the CMYK value will be used for printing out the PDF with exact that color value.
if I use the application as is and Views PDF would support a external stylesheet like print.css I would be forced to use a style definition like this:

h3 {
  color: #7AB800;
  color: cmyk(59, 0, 100, 0);
}

I think that might work as well as the second one would simply not beeing interpreted, but that might be according to the today given CSS 3 specifications not valid.

Another critical point to use CSS 3 might be the font-face:
As I can't see how for example an @font-face make compatible to the fonts TCPDF is useing (right now I'am personally a fan of using @font-face in combination with .eot fonts but I could declare as a fallback as well .ttf or even svg fonts)

Personaly I don't need all the possible attributes of CSS supported (as TCPDF might not allow them anyway). I would be realy happy if this CSS attributes

	font-size:
	line-height:
	font-weight:
	text-decoration:
	text-align:
	text-indent:
	letter-spacing:
	word-spacing:
	width:
	height:
	margin:
	padding:
	border-style:
	border-top-style:
	list-style-type:
	list-style-position:

would be supported by views PDF.

Up to now I see my self to give my nodes more fields as I'am now only able to set the Text style per field through views PDF. I hope this explanation brightens things up a little.

May be that dream is just to strange, but I can imagine a 1000 possible usecases for styling a pdf through a .css declaration und give i to the user by allowing inside views PDF to choose an external style sheet for just that purpose. Again thank you very much for your kind reaction.

hunziker’s picture

Ok, I understand know what you need.

The problem is that not all users want this functionality and the print CSS file does not always calls "print.css". Additionally it can be located in a sub folder of the theme folder.

A multi selectbox for adding a CSS file is hard to implemented, because .css files can be located nearly everywhere in the Drupal folder. Potentially it can be also on a different server. So the input must be direct a file path or better a fully qualified URL. I'm not sure how many users need this really. So a special user input field, like for color or font make no sense to me.

I propose this way:
You can prepend a

tag to your content (body field). This can be done by adding in the "PHP CODE BEFORE OUTPUT:" something like:
$content = '<link type="text/css" rel="stylesheet" media="print" href="http://your-url.com/to/your/print.css" />' . $content;
I have test it, at the moment it will not work. I need more time to debug it. But this way seems for me more convenient, because
  • you can specify for each field different CSS files.
  • You do not set some additional requirements (special path to css)
  • We don't break the current implementation
The problem is that the TCPDF does not support the inclusion of external CSS files. The result of my debugging will be posted here in this issue.
m-si’s picture

Wow I can see your point and the declaration of the .css as you showed, seems not to difficult at all. Is TCPDF showing what portion of CCS they support? I'am realy exited about your reaction...

UPDATE: I found a example myself, it seems the allow a lot of attributes. So only color(cmyk) and the font-face seems to be difficult at last...

wow, wow, wow this realy might change my whole drupal setup...

UPDATE: I checked it with putting some php in the field 'PHP CODE BEFORE OUTPUT:' unfortunatly I'am doing something wrong as I even can not manage to make a print 'hello world'; work. I tried these two insert

Insert 1.

<?php
print 'hello world';
?>

Insert 2.

print 'hello world';

it says:

Parse error: syntax error, unexpected '<' in /mnt/web7/63/27/52444027/htdocs/my_website/modules/views_pdf/views_pdf_template.php(395) : eval()'d code on line 1

Do I have to write it differently?

By the way, just in case you might wonder about why I do have this strange 'dream'. I'am a graphic Designer with minimal codeing knowledge but major design requirements.

hunziker’s picture

You do not need to use the PHP tags (<\?php ... ?\>). It seems that this is your problem. The printed output make potentially problems, so I propose for debugging using a "die();" command. To ensure, that after the invocation of the code inside the field, the script stops. So you can see the output.

candelas’s picture

subscribe! :)
@m-si: did you succeeded on the try?

and congratulations for this excellent module.
i will be trying it this weekend.
i will report anything i see it can serve to you.

hunziker’s picture

I have add an option to specify an URL to add a CSS file in the GUI (available in beta5). This CSS file is then added to each HTML field.

With this option you could change the rendering of HTML fields. But the support of CSS options is very limited. See the TCPDF library for details what is supported and what is not supported.

For example the "padding" and "margin" options are not supported.

candelas’s picture

@hunziker thanks a lot.
i try it this weekend and if i find anything, i report.

candelas’s picture

Version: 6.x-1.0-beta1 » 6.x-1.0-beta5

i have tried to assign color in a class style and it doesnt work.
i assign in "PDF settings" the css (i check in the browser to verify the url and it is ok)
then in the "row style: PDF Fields" i write this in the "PHP Code Before Output"

$content = "<span class='prueba'>". $content. "</span>";

in my css file:

.prueba {
color: #DD2EC8;
}

are class styles supported?

hunziker’s picture

I dont know if class styles are supported. For debugging try something like span { color: #667788; }. If this does not work, then you are doing something wrong.

Personally I have use it for styling some

tags. This works well except of the margin / padding thing as mentioned somewhere else.

candelas’s picture

it doesnt work... :)
and i dont know what else to try.
in the PHP Code Before Output:

$content="<span style='color: #667788;'>djdj</span>". $content;
hunziker’s picture

The following works for me:

Set in the eval before:

$content = "<p>My Test paragraph. And some blind text... . Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,</p>";

Define in the CSS file:

p {
text-align: justify;
}

If this does not work, then you do something wrong. Because I use exactly this in a live environment. In sure that you are using the latest TCPDF library. If some other options such as margins, colors and other things not work as expected, then please post these things directly by the TCPDF developers and not here.

candelas’s picture

thanks for giving to me your time.
that i know, but i need many changes in color and i was trying to do it with span or style.
but maybe i have to change and make variations with that.
thanks a lot :)

hunziker’s picture

Status: Active » Closed (fixed)

I will close this issue because, the feature is implemented and the discussion is moved to "how to use TCPDF with CSS". So I propose if there are more questions about this open a new issue.