Cookbook/PDF files
From HaskellWiki
(Difference between revisions)
(→Drawing text) |
(→Drawing text) |
||
| Line 56: | Line 56: | ||
** a [http://hackage.haskell.org/packages/archive/HPDF/latest/doc/html/Graphics-PDF-Text.html#t%3AFontName FontName] | ** a [http://hackage.haskell.org/packages/archive/HPDF/latest/doc/html/Graphics-PDF-Text.html#t%3AFontName FontName] | ||
** a font size | ** a font size | ||
| - | * create a [http://hackage.haskell.org/packages/archive/HPDF/latest/doc/html/Graphics-PDF-Text.html#t%3APDFText] using [http://hackage.haskell.org/packages/archive/HPDF/latest/doc/html/Graphics-PDF-Text.html#v%3Atext text] and the data anove | + | * create a [http://hackage.haskell.org/packages/archive/HPDF/latest/doc/html/Graphics-PDF-Text.html#t%3APDFText PDFText] using [http://hackage.haskell.org/packages/archive/HPDF/latest/doc/html/Graphics-PDF-Text.html#v%3Atext text] and the data anove |
* draw the PDFText with [http://hackage.haskell.org/packages/archive/HPDF/latest/doc/html/Graphics-PDF-Text.html#v%3AdrawText drawText] | * draw the PDFText with [http://hackage.haskell.org/packages/archive/HPDF/latest/doc/html/Graphics-PDF-Text.html#v%3AdrawText drawText] | ||
TODO | TODO | ||
Revision as of 08:14, 24 April 2009
For the following recipes you need to install HPDF.
1 Creating an empty PDF file
runPdf generates a PDF file in the file system. You need to pass it four things:
- a file name for the PDF file
- document information, an instance of PDFDocumentInfo. You can use the data generated by standardDocInfo.
- the default page size, an instance of PDFRect.
- a PDF Action
Let's create an empty PDF file with the name "test1.pdf". We use addPage to add an empty page.
import Graphics.PDF main :: IO () main = do let outputFileName= "test1.pdf" let documentInfo = standardDocInfo let defaultPageSize = PDFRect 0 0 200 300 runPdf outputFileName documentInfo defaultPageSize $ do addPage Nothing
2 Pages with different sizes
If you pass "Nothing" to addPage, the default page size will be used for the size of the new page. We can pass it a different size (an instance of PDFRect).
Let’s create three pages, the last two pages with different dimensions:
import Graphics.PDF main :: IO () main = do let outputFileName= "test2.pdf" let documentInfo = standardDocInfo let defaultPageSize = PDFRect 0 0 200 300 runPdf outputFileName documentInfo defaultPageSize $ do addPage Nothing addPage $ Just $ PDFRect 0 0 100 100 addPage $ Just $ PDFRect 0 0 150 150
3 Drawing text
To draw a text you need to take the following steps:
- convert the text to a PDFString using toPDFString
- create a PDFFont, passing it
- a FontName
- a font size
- create a PDFText using text and the data anove
- draw the PDFText with drawText
TODO
