pdfChip specific CSS aspects

In pdfChip, (almost) all valid CSS3 properties can be used. On top of that, pdfChip implements a range of additional CSS properties, mainly in order to address certain requirements of the graphic arts industry. This chapter describes these custom CSS properties as well as other properties that are useful in the context of pdfChip.

Page geometry boxes

PDF page geometry boxes can be specified inside the CSS @page{} rule. The following custom CSS properties are available:

-cchip-trimbox
-cchip-bleedbox
-cchip-cropbox
-cchip-artbox

Page geometry boxes are defined in PDF coordinates: 0/0 is left bottom of the page and Y goes up (rather than in screen coordinates where center is left top and Y goes down). Each of the page geometry box properties takes four values: The fist two define the coordinates of the lower left corner, the third the width and the forth the height of the box. The MediaBox is defined via the CSS @page size property.

Example for a typical A4 page:

@page {
    size: 230mm 317mm;
    -cchip-trimbox: 10mm 10mm 210mm 297mm;
    -cchip-bleedbox: 7mm 7mm 216mm 303mm;
    -cchip-cropbox: 0mm 0mm 230mm 317mm;
	} 

If a pdfChip-page geometry box property is set, then:

  • the appropriate page geometry box is present in the output PDF
  • the appropriate value is available is JavaScript 'page' object

In order to use page geometry boxes in JavaScript the syntax is

  • cchip.pages[i].artbox
  • cchip.pages[i].bleedbox
  • cchip.pages[i].trimbox
  • cchip.pages[i].cropbox

E.g. in order to check if the BleedBox is set on the first page:

if (cchip.pages[1].bleedbox) {
	...do something with bleedbox...
	}

Force Mediabox and CropBox to be equal and sit at the origin (0,0)

New in pdfChip v.2.2.064

Due to various constraints and limitations, it is often necessary to make the pagesize larger than actually needed and at the same time use a CropBox to crop it to the actually intended displayed/rendered size. This leads to PDFs where the page as displayed/rendered does not sit at the origin but rather away from it (i.e. where the lower left of the CropBox sits).

Some PDF processing/output tools fail to acknowldge the position of the CropBox and instead just look at the MediaBox. It is not feasible to make all those tools behave per the PDF specification, instead the new CSS property below will help by creating PDFs where the CropBox sits at the origin 0/0. The MediaBox would have the same value as that of the CropBox while the other boxes that are present (BleedBox, TrimBox, ArtBox) would also be adjusted accordingly (by the same delta as the CropBox).

-cchip-media-and-crop-box-at-origin: on | off  (on is default value)
Click to copy

Needless to say that when the switch is turned OFF, the MediaBox and the CropBox might not sit at the origin 0/0 on creating a PDF file.

Before making adjustments (intended page size: 500x1000):
  /CropBox [50 100 550 1100]
  /MediaBox [0 0 550 1100]
  /BleedBoox [ ... original ... ]
  /TrimBox [ ... original ... ]
  /ArtBox [ ... original ... ]
 
After making adjustments (intended page size: 500x1000):
  /CropBox [0 0 500 1000]
  /MediaBox [0 0 500 1000]
  /BleedBoox [ ... adjusted ... ]
  /TrimBox [ ... adjusted ... ]
  /ArtBox [ ... adjusted ... ]
Click to copy

Please keep in mind that this works even if the page size or CropBox are different from page to page.

Rotating page content

In pdfChip, you can use all CSS positioning properties. This includes properties for rotating page content which are not supported by all web browsers and are therefore not commonly used. For this reason they are listed here.

  • -webkit-transform: Sets the rotation factor
  • -webkit-transform-origin: Defines the origin for rotation

It is useful to combine these properties with other positioning properties in order to set the origin accordingly.

Example for rotating content 45 degrees counterclockwise with an origin at 20mm / 100 mm (from top of the page).

.rotated-45 {
    position: absolute;
    left: 20mm; bottom: 100mm;
    -webkit-transform: rotate(-45deg);
    -webkit-transform-origin: left bottom;
	}

Since HTML thinks in 96 dpi, some transformations in HTML cause displacement of content for which users can:

  • The Origin in HTML is always at the top left, the Origin for CropBox etc. is at the bottom left (in terms of page size)
  • Always make the pagesize/MediaBox a little bit bigger than the page should be at the end, especially in the vertical direction (at least a few mm, rather more), but also in the horizontal direction (here a few points would be enough, but in case of doubt just add 10mm)
  • Set the actual page size via the CropBox
  • The CropBox should be in the upper left corner and TrimBox equal to the CropBox
  • Example for a desired page format of DIN A4 (210x297mm): 
    • @page {

      /* Size of the page, equivalent to MediaBox, origin always at 0/0 */

      /* 10mm wider and 100m higher than actually needed */

      size: 220mm 397mm;

      /* push the cropbox up 100mm from below, so that it closes at the top */

      -chip-cropbox: 0mm 100mm 210mm 297mm;

      /* trimbox equal to the cropbox, or at least within the cropbox */

      -chip-trim box: 0mm 100mm 210mm 297mm;

      }

Page breaks

Another type of CSS property that is especially useful in pdfChip is related to setting or avoiding page breaks, because page breaks naturally play a much more important role in PDF creation than in the design of web pages.

  • page-break-after
  • page-break-before
  • page-break-inside

Below, the most important values for each of these properties are listed

Value name
Result
Applicable in
auto
Default. Automatic page breaks
page-break-after,
page-break-before,
page-break-inside
always
Always insert a page break
page-break-after,
page-break-before
avoid
Avoid page break (if possible)
page-break-after,
page-break-before,
page-break-inside
left
Insert page breaks so that the next page is formatted as a left page
page-break-after,
page-break-before
right
Insert page breaks so that the next page is formatted as a right page
page-break-after,
page-break-before

The example below inserts a page break before the next element.

<p style="page-break-after: always" />

Theoretically, a 'page break' should work as suggested above and simply create another PDF page when deployed. However, this CSS does not always work reliably in the web engines we tested and also not in the webkit we use. In the HTML world (unlike with PDF), page breaks are not the core of the requirements.

To avoid this, the template can be adjusted or the vertical distance between the source pages can be increased, so that the content is mounted on the next page.

Defining colors for print - CMYK, spot or ICC based color

Device color spaces

CSS Property Value Range Resulting Color Space
-cchip-gray(g) g: 0.0 … 1.0 DeviceGray
-cchip-rgb(r,g,b) rgb: 0.0 … 1.0 DeviceRGB
-cchip-cmyk(c,m,y,k) cmyk: 0.0 … 1.0 DeviceCMYK

Device independent color spaces (ICC based and Lab)

CSS Property
Value Range
Resulting Color Space
-cchip-icc-gray('ICCPATH', g)
g: 0.0 … 1.0
ICC based Gray
-cchip-icc-rgb('ICCPATH', r,g,b)
rgb: 0.0 ... 1.0
ICC based RGB
-cchip-icc-cmyk('ICCPATH', c,m,y,k)
cmyk: 0.0 … 1.0
ICC based CMYK
-cchip-lab(l,a,b)
l: 0.0 … 100.0
ab: -128.0 … +127.0
Lab
-cchip-icc-lab('ICCPATH', l,a,b)
"l: 0.0 … 100.0
ab: -128.0 … +127.0"
ICC based Lab

With 'ICCPATH' path to a local ICC profile.

Spot color (with Alternate color defintions using device dependent or device independent color spaces)

CSS Property Value Range Resulting Color Space
-cchip-gray('NAME',g [, tint]) g: 0.0 … 1.0, tint 0 … 1.0 Spot color NAME, Alternate DeviceGray
-cchip-icc-gray('ICCPATH', 'NAME',g [, tint]) g: 0.0 … 1.0, tint 0 … 1.0 Spot color NAME, Alternate ICC based Gray
-cchip-rgb('NAME',r,g,b [, tint]) rgb: 0.0 … 1.0, tint 0 … 1.0 Spot color NAME, Alternate DeviceRGB
-cchip-icc-rgb('ICCPATH', 'NAME',r,g,b [, tint]) rgb: 0.0 … 1.0, tint 0 … 1.0 Spot color NAME, Alternate ICC based RGB
-cchip-cmyk('NAME',c,m,y,k [, tint]) cmyk: 0.0 … 1.0, tint 0 … 1.0 Spot color NAME, Alternate DeviceCMYK
-cchip-icc-cmyk('ICCPATH', 'NAME',c,m,y,k [, tint]) cmyk: 0.0 … 1.0, tint 0 … 1.0 Spot color NAME, Alternate ICC based CMYK
-cchip-lab('NAME',l,a,b [, tint]) l: 0.0 … 100.0
ab: -128.0 … +127.0, tint 0 … 1.0
Spot color NAME, Alternate Lab
-cchip-icc-lab('ICCPATH', 'NAME',l,a,b [, tint]) l: 0.0 … 100.0
ab: -128.0 … +127.0, tint 0 … 1.0
Spot color NAME, Alternate ICC based Lab

With 'ICCPATH' path to a local ICC profile. Profiles have to be accessible in the file system, it is e.g. not possible to derive them via http.

In order to define colors in a way that a regular Browser will be able to display a color the definitions can be combined with regular HTML/CSS color definitions as shown below.

Example that defines a background color as spot color with the name "Spot" using an alternate color in ICC based CMYK C=0% M=80% Y=80% K=0% and ISO Coated v2 as source color space. The spot color is used with a tint value of 75%.

.background-spot_orange-ICCbasedcmyk {
		background-color: orange;
		background-color: -cchip-icc-cmyk('./ISO Coated v2 (ECI).icc',
		'Orange',0.0,0.8,0.8,0.0, 0.75)
		}

DeviceN color spaces

Defining DeviceN color spaces is a bit more complex than using other color spaces, which comes from the fact that DeviceN in principle is a (multi-component) color space conceptually defined in two steps:

  • First, one or several separation color space have to be established: often spot color colorants, but also process color colorants (one or even several None components could be possible).
  • Second, these separation color space are defined in a certain order and form within the DeviceN color space
  • In addition, the DeviceN color space itself also needs an alternate colorspace definition
@-cchip-devicen{
-cchip-devicen-name: "test-colorspace-name";
-cchip-components: -cchip-cmyk('Cyan'   ,1   ,0   ,0   ,0  )
                           -cchip-cmyk('Magenta',0   ,1   ,0   ,0  )
                           -cchip-cmyk('Yellow' ,0   ,0   ,1   ,0  )
                           -cchip-cmyk('Black'  ,0   ,0   ,0   ,1  )
                           -cchip-cmyk('Fifth colorant'  ,0.5 ,0.5 ,0.5 ,0  )
                           -cchip-cmyk('Sixth colorant'  ,0   ,0.5 ,0.5 ,0.2)
}

The alternates of the components can become defined in all supported spot color definitions (see chapter above).

A mixture of different alternate color spaces may become converted to CMYK-only alternate values.

Using and mixing different channels is similar to the usage of common color spaces, for example:

.devicen.c1  { background-color: -cchip-devicen('test-colorspace-name',1,0,0,0,0,0);  }
 .devicen.c2  { background-color: -cchip-devicen('test-colorspace-name',0,1,0,0,0,0);  }
    .devicen.c3  { background-color: -cchip-devicen('test-colorspace-name',0,0,0,0.25,1,0);  }

Limitations

  • pdfChip colors are implemented only for CSS/HTML but not for JavaScript. The following JavaScript is not possible for pdfChip colors:
  • note.style.color = "rgb(155, 102, 102)"
  • In some situations colors are converted to Device RGB:
      Rasterization.
      Colors are acсessed via JavaScript. E.g. if “mydiv.style.backgroundColor” in JavaScript it would be output as RGB even if it has accurately been defined as CMYK via '-cchip-cmyk' in CSS.
      DeviceN is not supported inside rasterized content.

Extended Graphics State parameters

Special pdfChip parameters

CSS Property Value Range Default value
-cchip-flatness-tolerance >= 0.0 1.0
-cchip-smoothness-tolerance 0.0 … 1.0 -1.0 *)
-cchip-text-knockout 0, 1 0
-cchip-overprint 0, 1 0
-cchip-overprint-mode 0, 1 0
-cchip-stroke-adjustment 0, 1 0
-cchip-rendering-intent absolute-colorimetric, relative-colorimetric, perceptual, saturation relative-colorimetric

-cchip-black-point-compensation On, Off, Default Default

*) Special value -1.0 for pdfChip-smoothness-tolerance means “nothing was set in CSS and pdfChip should use it's own default"

Example that switches overprint and overprint mode ON and sets the rendering intent to "saturation" for a color.

.background-spot_orange-ICCbasedcmyk {
    -cchip-overprint: 1;
    -cchip-overprint-mode: 1;
    -cchip-rendering-intent: absolute-colorimetric;
    background-color: orange;
    background-color: -cchip-icc-cmyk('./ISO Coated v2 (ECI).icc',
    'Orange',0.0,0.8,0.8,0.0, 0.75);
}

Transparency

The CSS3 property "opacity" can be used in order to define transparent PDF objects.

CSS Property Value Range Default value
opacity 0.0 ... 1.0 1.0

E.g. style="opacity: 0.5" sets opacity to 50%, the ca value in the result PDF's Extended Graphic State is thereby set to 0.5.

PDF as image in background

A PDF might be used as the background "image" inside of the background property in the same way as in HTML in the img tag. The PDF objects of the background "image" will show up in the destination PDF as page objects (not rasterized).

Please go to the chapter "pdfChip specific HTML aspects" for further information about selecting a PDF page or clipping a PDF page.

Setting the text rendering mode

The PDF specification allows several "Rendering mode" for text objects. Depending on the defined mode, some text might be invisible (but can be searched and copied, e.g. in scanned and OCR-ed documents),  be painted with a stroke, used as a clipping path and much more.

This feature is available since callas pdfChip 2.1.061

-cchip-text-rendering-mode: 0;

0
Fill text (Default)
1
Stroke text
2
Fill, then stroke text
3
Neither fill nor stroke text
4
 Fill text and add to path for clipping
5
Stroke text and add to path for clipping
6
Fill, then stroke text and add to path for clipping
7
Add text to path for clipping