public class PdfSurface extends Surface
You specify the size of a PdfSurface in points, and all subsequent
operations on a Context based on this Surface will likewise be in points.
If you are used to using Cairo to draw to screen where a device unit equals
a pixel, be aware that here your a distance of 1.0
is in
points, not pixels.
Cairo's PDF support is still nascent but is improving steadily! Wherever possible graphics drawn in your Context will be rendered in vector form in the PDF; when that is not available the PDF backend will fallback to rendering bitmaps of the desired content.
Constructor and Description |
---|
PdfSurface(String filename,
double width,
double height)
Create a new PdfSurface, supplying the file you want to write to and
the size of the page you are creating.
|
Modifier and Type | Method and Description |
---|---|
void |
copyPage()
Emit the current page, but keep the content of the Surface as the
starting point for the next page.
|
void |
showPage()
Emit the current page and clear the Surface, allowing you to continue
drawing with your Context but to a new blank page.
|
createSimilar, finish, flush, setMimeData, setMimeData, writeToPNG
public PdfSurface(String filename, double width, double height) throws IOException
width
and
height
parameters are specified in points, where 1
point equals 1/72nd of an inch.
A4 paper is 210mm x 297mm, which works out as about:
surface = new PdfSurface("output.pdf", 595.275, 841.889);more generally, you can use get paper size information via GTK's printing support using [
org.gnome.gtk
] PaperSize's
getWidth()
and getHeight()
methods, for example:
paper = PaperSize.getDefault(); width = paper.getWidth(Unit.POINTS); height = paper.getHeight(Unit.POINTS); surface = new PdfSurface("output.pdf", width, height);saving you having to worry about just how big such paper really is.
IOException
- If you do not have write permissions on the given file.public void copyPage()
Surface
public void showPage()
Surface
If you want to render the current page, but keep the page content in
your Context, then call copyPage()
instead.
This method only applies to Surfaces which are paginated, which in practise means the PDF backend.