Images
This topic contains information about how you can reference images from your HTML or XML documents.
<img>
tag is recognized as an image
without any other styling in your CSS
files:...
<p> And this is the picture of a happy face: <img src="happy.png" />. </p>
...
...
<para> And this is the picture of a happy face: <imagedata fileref="happy.png"/>.</para>
...
imagedata
:before
pseudo-element:imagedata[fileref]:before {
content: attr(fileref, url);
}
url
keyword when retrieving the attribute value. It signals that the value is a pointer to an
external image.Supported Image Types
Oxygen PDF Chemistry supports the following types of raster images:
- BMP (Microsoft Windows Bitmap)
- GIF (Graphics Interchange Format)
- JPEG (Joint Photographic Experts Group)
- PNG (Portable Network Graphic)
- TIFF (Tag Image Format File)
And the following types of vector images:
- SVG (Scalable Vector Graphics)
- PDF (PDF Documents)
PDF Images
You can reference PDF images the same way other image files are referenced:
<img src="my_doc.pdf"/>
To point to a single page from your PDF document, use the following syntax (this example points to page 5):
<img src="my_doc.pdf#page=5"/>
Setting Image Width and Height
The image size can be determined from the number of pixels of the image, taking the image resolution into account (if available). There are cases where this computed size is not what you need, and you want to specify the size explicitly.
For HTML, it is enough to use the image attributes directly in your document.
<img src="my_image.png" width="300" height="250" />
For an arbitrary XML, you can indicate the image width and height through a rule that matches
the element (or its :before
or :after
pseudo-elements) and
sets the width
and height
CSS properties.
imagedata {
display: inline;
content: attr(src, url);
width: attr(width, length);
height: attr(height, length);
}
Or, if you use an image as a decorator, you can specify fixed dimensions in the CSS:
chapter title:before {
content: url("my_artwork.png");
width: 300px;
}
content
property disables the width and height
specification.If you want to limit the width of the images to a maximum size, you can use the
max-width
property. The image will be scaled down to fit the maximum size
(if it is larger).
imagedata {
...
content: attr(src, url);
max-width: attr(width, length);
...
}
Image Resolution
Some raster images (pixels, not vector) may have a default resolution, set by the designer, using an image-editing software. Usually, the image size and resolution are set to look best on the screen. The advantage of a resolution set in the image itself is that it will have the same effective size on the screen and on paper. For example, if the image has 144 dots in width, and an embedded resolution of 72dpi, it will be two inches on screen and on paper.
The problems start to arise when the resolution is not set on the image, and the PDF processor has to decide what resolution to use to determine the size of the graphic. To solve this, the processor extracts the DPI from:
- The
image-resolution
CSS property associated to the element that contains the image. - The
-image-resolution
command-line parameter. - The built-in fallback resolution of 96 DPI.
The recommended way to change this is by using the CSS Level 4
image-resolution
property:
img {
image-resolution: 300dpi;
}
image-resolution
is inheritable, so you can associate it to the root
element. It does not apply on the page generated content (margin
boxes).:root {
image-resolution: 300dpi;
}
To reset the image resolution to the one set in the image itself, you can use the
constant from-image
instead of a DPI value:
title:before {
content: url("chapter-decorator.png");
image-resolution: from-image;
}
@page front-page {
image-resolution: 600dpi;
}
@page {
@top-center {
image-resolution: 600dpi;
content: url("company-logo.png");
}
}