"Fossies" - the Fresh Open Source Software Archive

Member "PDFlib-Lite-7.0.5p3/bind/pdflib/python/starter_pdfx.py" (6 Jun 2012, 2591 Bytes) of package /linux/misc/old/PDFlib-Lite-7.0.5p3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "starter_pdfx.py" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/python
    2 # $Id: starter_pdfx.py,v 1.9.2.4 2009/03/02 14:14:07 rjs Exp $
    3 #
    4 # PDF/X starter:
    5 # Create PDF/X-compliant output
    6 #
    7 # required software: PDFlib/PDFlib+PDI/PPS 7
    8 # required data: font file, image file, icc profile
    9 #                (see www.pdflib.com for ICC profiles)
   10 
   11 import sys
   12 from pdflib_py import *
   13 
   14 def printf(format, *args):
   15     sys.stdout.write(format % args)
   16 
   17 # This is where the data files are. Adjust as necessary.*/
   18 searchpath = "../data"
   19 imagefile = "nesrin.jpg"
   20 outfilename = "starter_pdfx.pdf"
   21 
   22 p = PDF_new()
   23 
   24 try:
   25   try:
   26     # This means we must check return values of load_font() etc.
   27     PDF_set_parameter(p, "errorpolicy", "return")
   28 
   29     PDF_set_parameter(p, "SearchPath", searchpath)
   30 
   31     if (PDF_begin_document(p, outfilename, "pdfx=PDF/X-3:2002") == 0):
   32         raise PDFlibException("Error: " + PDF_get_errmsg(p))
   33 
   34     PDF_set_info(p, "Creator", "PDFlib starter sample")
   35     PDF_set_info(p, "Title", "starter_pdfx")
   36 
   37     # You can use one of the Standard output intents (e.g. for SWOP
   38     # printing) which do not require an ICC profile:
   39     #
   40     # PDF_load_iccprofile(p, "CGATS TR 001", "usage=outputintent")
   41     #
   42     # However, if you use ICC or Lab color you must load an ICC
   43     # profile as output intent:
   44     if (PDF_load_iccprofile(p, "ISOcoated.icc", "usage=outputintent") == -1):
   45         printf("Error: %s\n", PDF_get_errmsg(p))
   46         printf("Please install the ICC profile package from " +
   47             "www.pdflib.com to run the PDF/X starter sample.\n")
   48         exit(2);
   49 
   50 
   51     PDF_begin_page_ext(p, 595, 842, "")
   52 
   53     # font embedding is required for PDF/X
   54     font = PDF_load_font(p, "LuciduxSans-Oblique", "unicode", "embedding")
   55     if font == -1:
   56         raise PDFlibException("Error: " + PDF_get_errmsg(p))
   57 
   58     PDF_setfont(p, font, 24)
   59 
   60     spot = PDF_makespotcolor(p, "PANTONE 123 C")
   61     PDF_setcolor(p, "fill", "spot", spot, 1.0, 0.0, 0.0)
   62     PDF_fit_textline(p, "PDF/X-3:2002 starter", 50, 700, "")
   63 
   64     # The RGB image below needs an icc profile; we use sRGB.
   65     icc = PDF_load_iccprofile(p, "sRGB", "")
   66     image = PDF_load_image(p, "auto", imagefile, "iccprofile=" + repr(icc))
   67 
   68     if (image == -1):
   69         raise PDFlibException("Error: " + PDF_get_errmsg(p))
   70 
   71     PDF_fit_image(p, image, 0.0, 0.0, "scale=0.5")
   72 
   73     PDF_end_page_ext(p, "")
   74 
   75     PDF_end_document(p, "")
   76 
   77   except PDFlibException:
   78     print("PDFlib exception occurred:\n[%d] %s: %s" %
   79     ((PDF_get_errnum(p)), PDF_get_apiname(p),  PDF_get_errmsg(p)))
   80 
   81   except Exception:
   82     print("Exception occurred: %s" % (exc_info()[0]))
   83 
   84 finally:
   85     PDF_delete(p)