HTML to PDF converter for Java and .NET

HOME   FEATURES   PRODUCTS   DOWNLOADS   BUY NOW!   SUPPORT
<< back

PD4ML: Proprietary CSS features

As you know, PD4ML supports rendering/conversion of CSS-styled HTML documents. However we never claim that PD4ML is CSS2 or CSS3 compliant. There are some CSS features, whose implementation we decide to skip due to technical complexities or potential performance issues; there are some features we ignored as they are not that popular (from our perspective); some features are not supported by our CSS parser.

FYI: PD4ML utilizes a third-party library ss_css2.jar of open-source CSS Parser project. The library "officially" supports CSS Level 2, that makes an implementation of highly demanded popular CSS3 features complicated, or even impossible. We patched the library to workaround some limitations, however there is still a number of open issues. (The patched source code of the library is available for download from our site).

By the link you can find the list of currently supported CSS properties. As you may see the list ends with some non-standard PD4ML-specific properties. Below we'll try to shed light on them.

But first, we start with supported CSS media types and a proprietary type 'pdf'.

1. Media type 'pdf'

By default PD4ML applies CSS properties, defined for media type 'screen' (if a media type specified). Of course, it also applies styles of media type 'all', but 'print' is ignored. If for some reason print styles must be applied, PD4ML allows to enable them with the API call:

Map m = new HashMap();  
m.put(PD4Constants.PD4ML_MEDIA_TYPE_PRINT, "add");  
pd4ml.setDynamicParams(m); 
The above code enables 'print' media type in addition to 'screen'. If 'screen' styles are undesired, the following disables 'screen' and enables 'print'.
Map m = new HashMap();  
m.put(PD4Constants.PD4ML_MEDIA_TYPE_PRINT, "override");  
pd4ml.setDynamicParams(m); 
In situations, when very special styles are required for pdf conversions only, there is a proprietary media type 'pdf'. As the type is known to PD4ML only, it will be ignored by the regular web browsers.

@media pdf {
	TR, IMG {page-break-inside: avoid;}
}
CSS media queries are not supported.

2. Proprietary CSS properties

  • pd4ml-visibility and pd4ml-display

    With PD4ML-specific CSS properties pd4ml-visibility and pd4ml-display there is a possibility to exclude particular elements from a resulting PDF document. The properties syntax is more-less identical to the standard display and visibility.

     <input style="pd4ml-display: none; pd4ml-visibility: hidden" 
        type=submit value="Get the page as PDF">

    An opposite effect can be achieved with the code below. As you see, the proprietary properties take precedence over the standard visibility and display in PD4ML environment. But by the regular web browser they are not known and just ignored.

    <div style="display: none; visibility: hidden; pd4ml-display: block; pd4ml-visibility: visible">
    The section is visible only in PDF report
    </div>
    
  • pd4toc - CSS property to be applied to <H1>-<H6> heading tags to suppress page numbering in the table of contents (if defined with <pd4ml:toc>). It can be applied to all headings of a particular level:
    H3 {pd4toc: nopagenum}
    
    or to selected tags individually.
     

  • pd4ml-bookmark-visibility - makes possible to exclude some items from PDF bookmarks structure.
    H3 { pd4ml-bookmark-visibility: hidden }
    
    or <h3 style="pd4ml-bookmark-visibility: hidden"> for a single bookmark exclusion.
     
  • pd4ml-page-break-border-top and pd4ml-page-break-border-bottom - the properties define borders for tables, broken by a page break.
    TR { page-break-inside: avoid;
    pd4ml-page-break-border-top: 1 solid red;
    pd4ml-page-break-border-bottom: 1 solid blue; }	
    

     
3. Supported CSS selectors.

PD4ML supports most of CSS2 selectors including some popular CSS3 constructs. Here is the list.

*Universal selector Matches any element
EType selectorsMatches any E element (i.e., an element of type E)
E.fooClass selectorMatches E element of class "foo"
.foo (or *.foo)Class selectorMatches any element of class "foo"
E.foo.bar Multi-class selector Matches E element of both classes "foo" and "bar"
.foo.bar (or *.foo.bar) Multi-class selector Matches any element of both classes "foo" and "bar"
E FDescendant selectors Matches any F element that is a child of an element E
E > FChild selectors Matches any F element that is a child of an element E
E:first-child The :first-child pseudo-class Matches element E when E is the first child of its parent
E:nth-child(even|odd)Structural pseudo-class selector Matches E element, the even or odd child of its parent
E + FAdjacent selectors Matches any F element immediately preceded by a sibling element E
E[foo] Attribute selectors Matches any E element with the "foo" attribute set (whatever the value)
E[foo="warning"] Attribute selectors Matches any E element whose "foo" attribute value is exactly equal to "warning"

The selectors can be combined or chained.

Copyright ©2004-24 zefer|org. All rights reserved. Bookmark and Share