Personal tools

Cookbook/PDF files

From HaskellWiki

< Cookbook(Difference between revisions)
Jump to: navigation, search
(Creating an empty PDF file)
(Creating an empty PDF file)
Line 6: Line 6:
   
 
* a file name for the PDF file
 
* a file name for the PDF file
* [http://hackage.haskell.org/packages/archive/HPDF/latest/doc/html/Graphics-PDF-Document.html#t%3APDFDocumentInfo document information] (you can use the data generated by [http://hackage.haskell.org/packages/archive/HPDF/latest/doc/html/Graphics-PDF-Document.html#v%3AstandardDocInfo standardDocInfo])
+
* document information ([http://hackage.haskell.org/packages/archive/HPDF/latest/doc/html/Graphics-PDF-Document.html#t%3APDFDocumentInfo PDFDocumentInfo]). You can use the data generated by [http://hackage.haskell.org/packages/archive/HPDF/latest/doc/html/Graphics-PDF-Document.html#v%3AstandardDocInfo standardDocInfo].
* a default [http://hackage.haskell.org/packages/archive/HPDF/latest/doc/html/Graphics-PDF.html#t%3APDFRect page size]
+
* a default page size ([http://hackage.haskell.org/packages/archive/HPDF/latest/doc/html/Graphics-PDF.html#t%3APDFRect PDFRect])
 
* a [http://hackage.haskell.org/packages/archive/HPDF/latest/doc/html/Graphics-PDF.html#t%3APDF PDF Action]
 
* a [http://hackage.haskell.org/packages/archive/HPDF/latest/doc/html/Graphics-PDF.html#t%3APDF PDF Action]
   

Revision as of 07:34, 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:

Let's create an empty PDF file with the name "test1.pdf":

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 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 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