Cookbook/PDF files

From HaskellWiki
< Cookbook
Revision as of 10:40, 23 April 2009 by Lenny222 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

For the following recipes you need to install HPDF.

Creating an empty PDF file

The following code creates an empty PDF file with the name "test1.pdf":

import Graphics.PDF

main :: IO ()
main = do
  let outputFileName= "test1.pdf"
  let defaultPageSize = PDFRect 0 0 200 300
  
  runPdf outputFileName standardDocInfo defaultPageSize $ do
    addPage Nothing

Pages with different sizes

If you pass "Nothing" to the function addPage, the default page size will be used for the size of the new page.

Let’s create three pages, the last two pages with different dimensions:

import Graphics.PDF

main :: IO ()
main = do
  let outputFileName= "test2.pdf"
  let defaultPageSize = PDFRect 0 0 200 300
  
  runPdf outputFileName standardDocInfo defaultPageSize $ do
    addPage Nothing
    addPage $ Just $ PDFRect 0 0 100 100
    addPage $ Just $ PDFRect 0 0 150 150