author | robin |
Thu, 24 Oct 2019 16:07:15 +0100 | |
changeset 4551 | d357e2acc856 |
parent 4294 | 55c8019c775e |
child 4608 | 25c3638c0330 |
permissions | -rw-r--r-- |
2587 | 1 |
#!/usr/pkg/bin/python |
2 |
||
3 |
import os, sys, time |
|
4 |
||
4551 | 5 |
from reportlab import Version as __RL_Version__ |
2592 | 6 |
from reportlab.graphics.barcode.common import * |
7 |
from reportlab.graphics.barcode.code39 import * |
|
8 |
from reportlab.graphics.barcode.code93 import * |
|
9 |
from reportlab.graphics.barcode.code128 import * |
|
10 |
from reportlab.graphics.barcode.usps import * |
|
2674 | 11 |
from reportlab.graphics.barcode.usps4s import USPS_4State |
4224
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
12 |
from reportlab.graphics.barcode.qr import QrCodeWidget |
2587 | 13 |
|
14 |
||
15 |
from reportlab.platypus import Spacer, SimpleDocTemplate, Table, TableStyle, Preformatted, PageBreak |
|
16 |
from reportlab.lib.units import inch, cm |
|
17 |
from reportlab.lib import colors |
|
18 |
||
19 |
from reportlab.pdfgen.canvas import Canvas |
|
20 |
from reportlab.lib.styles import getSampleStyleSheet |
|
21 |
from reportlab.platypus.paragraph import Paragraph |
|
22 |
from reportlab.platypus.frames import Frame |
|
23 |
from reportlab.platypus.flowables import XBox, KeepTogether |
|
4224
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
24 |
from reportlab.graphics.shapes import Drawing, Rect, Line |
2587 | 25 |
|
3669
40848d552920
fix issue 5, Tsy's createBarcodeInMemory was incomplete
robin
parents:
3502
diff
changeset
|
26 |
from reportlab.graphics.barcode import getCodes, getCodeNames, createBarcodeDrawing, createBarcodeImageInMemory |
2587 | 27 |
def run(): |
28 |
styles = getSampleStyleSheet() |
|
29 |
styleN = styles['Normal'] |
|
30 |
styleH = styles['Heading1'] |
|
31 |
story = [] |
|
4222
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
32 |
storyAdd = story.append |
2587 | 33 |
|
34 |
#for codeNames in code |
|
4222
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
35 |
storyAdd(Paragraph('I2of5', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
36 |
storyAdd(I2of5(1234, barWidth = inch*0.02, checksum=0)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
37 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
38 |
storyAdd(Paragraph('MSI', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
39 |
storyAdd(MSI(1234)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
40 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
41 |
storyAdd(Paragraph('Codabar', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
42 |
storyAdd(Codabar("A012345B", barWidth = inch*0.02)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
43 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
44 |
storyAdd(Paragraph('Code 11', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
45 |
storyAdd(Code11("01234545634563")) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
46 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
47 |
storyAdd(Paragraph('Code 39', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
48 |
storyAdd(Standard39("A012345B%R")) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
49 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
50 |
storyAdd(Paragraph('Extended Code 39', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
51 |
storyAdd(Extended39("A012345B}")) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
52 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
53 |
storyAdd(Paragraph('Code93', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
54 |
storyAdd(Standard93("CODE 93")) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
55 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
56 |
storyAdd(Paragraph('Extended Code93', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
57 |
storyAdd(Extended93("L@@K! Code 93 :-)")) #, barWidth=0.005 * inch)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
58 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
59 |
storyAdd(Paragraph('Code 128', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
60 |
storyAdd(Code128("AB-12345678")) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
61 |
|
4235
bc4e916892fd
add barcode contributions from Kyle MacFarlane @ bitbucket; version -->3.2.10
robin
parents:
4224
diff
changeset
|
62 |
storyAdd(Paragraph('Code 128 Auto', styleN)) |
bc4e916892fd
add barcode contributions from Kyle MacFarlane @ bitbucket; version -->3.2.10
robin
parents:
4224
diff
changeset
|
63 |
storyAdd(Code128Auto("AB-12345678")) |
bc4e916892fd
add barcode contributions from Kyle MacFarlane @ bitbucket; version -->3.2.10
robin
parents:
4224
diff
changeset
|
64 |
|
4222
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
65 |
storyAdd(Paragraph('USPS FIM', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
66 |
storyAdd(FIM("A")) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
67 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
68 |
storyAdd(Paragraph('USPS POSTNET', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
69 |
storyAdd(POSTNET('78247-1043')) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
70 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
71 |
storyAdd(Paragraph('USPS 4 State', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
72 |
storyAdd(USPS_4State('01234567094987654321','01234567891')) |
2587 | 73 |
|
2592 | 74 |
from reportlab.graphics.barcode import createBarcodeDrawing |
4222
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
75 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
76 |
storyAdd(Paragraph('EAN13', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
77 |
storyAdd(createBarcodeDrawing('EAN13', value='123456789012')) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
78 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
79 |
storyAdd(Paragraph('EAN13 quiet=False', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
80 |
storyAdd(createBarcodeDrawing('EAN13', value='123456789012', quiet=False)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
81 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
82 |
storyAdd(Paragraph('EAN8', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
83 |
storyAdd(createBarcodeDrawing('EAN8', value='1234567')) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
84 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
85 |
storyAdd(PageBreak()) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
86 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
87 |
storyAdd(Paragraph('EAN5 price=True', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
88 |
storyAdd(createBarcodeDrawing('EAN5', value='11299', price=True)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
89 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
90 |
storyAdd(Paragraph('EAN5 price=True quiet=False', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
91 |
storyAdd(createBarcodeDrawing('EAN5', value='11299', price=True, quiet=False)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
92 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
93 |
storyAdd(Paragraph('EAN5 price=False', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
94 |
storyAdd(createBarcodeDrawing('EAN5', value='11299', price=False)) |
2587 | 95 |
|
4222
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
96 |
storyAdd(Paragraph('ISBN alone', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
97 |
storyAdd(createBarcodeDrawing('ISBN', value='9781565924796')) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
98 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
99 |
storyAdd(Paragraph('ISBN with ean5 price', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
100 |
storyAdd(createBarcodeDrawing('ISBN', value='9781565924796',price='01299')) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
101 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
102 |
storyAdd(Paragraph('ISBN with ean5 price, quiet=False', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
103 |
storyAdd(createBarcodeDrawing('ISBN', value='9781565924796',price='01299',quiet=False)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
104 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
105 |
storyAdd(Paragraph('UPCA', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
106 |
storyAdd(createBarcodeDrawing('UPCA', value='03600029145')) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
107 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
108 |
storyAdd(Paragraph('USPS_4State', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
109 |
storyAdd(createBarcodeDrawing('USPS_4State', value='01234567094987654321',routing='01234567891')) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
110 |
|
4224
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
111 |
storyAdd(Paragraph('QR', styleN)) |
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
112 |
storyAdd(createBarcodeDrawing('QR', value='01234567094987654321')) |
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
113 |
|
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
114 |
storyAdd(Paragraph('QR', styleN)) |
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
115 |
storyAdd(createBarcodeDrawing('QR', value='01234567094987654321',x=30,y=50)) |
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
116 |
|
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
117 |
storyAdd(Paragraph('QR in drawing at (0,0)', styleN)) |
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
118 |
d = Drawing(100,100) |
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
119 |
d.add(Rect(0,0,100,100,strokeWidth=1,strokeColor=colors.red,fillColor=None)) |
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
120 |
d.add(QrCodeWidget(value='01234567094987654321')) |
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
121 |
storyAdd(d) |
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
122 |
|
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
123 |
storyAdd(Paragraph('QR in drawing at (10,10)', styleN)) |
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
124 |
d = Drawing(100,100) |
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
125 |
d.add(Rect(0,0,100,100,strokeWidth=1,strokeColor=colors.red,fillColor=None)) |
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
126 |
d.add(Line(7.5,10,12.5,10,strokeWidth=0.5,strokeColor=colors.blue)) |
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
127 |
d.add(Line(10,7.5, 10, 12.5,strokeWidth=0.5,strokeColor=colors.blue)) |
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
128 |
d.add(QrCodeWidget(value='01234567094987654321',x=10,y=10)) |
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
129 |
storyAdd(d) |
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
130 |
|
4222
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
131 |
storyAdd(Paragraph('Label Size', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
132 |
storyAdd(XBox((2.0 + 5.0/8.0)*inch, 1 * inch, '1x2-5/8"')) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
133 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
134 |
storyAdd(Paragraph('Label Size', styleN)) |
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
135 |
storyAdd(XBox((1.75)*inch, .5 * inch, '1/2x1-3/4"')) |
4224
f5326e699996
attempted fix of QrCodeWidget prompted by https://bitbucket.org/fubu/
robin
parents:
4222
diff
changeset
|
136 |
|
4222
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
137 |
|
760cfe8a8b27
fixes/improvements(or changes) to Edward Greve's EAN5/ISBN patch
robin
parents:
3721
diff
changeset
|
138 |
SimpleDocTemplate('out.pdf').build(story) |
3721 | 139 |
print('saved out.pdf') |
2587 | 140 |
|
141 |
def fullTest(fileName="test_full.pdf"): |
|
142 |
"""Creates large-ish test document with a variety of parameters""" |
|
143 |
||
144 |
story = [] |
|
145 |
||
146 |
styles = getSampleStyleSheet() |
|
147 |
styleN = styles['Normal'] |
|
148 |
styleH = styles['Heading1'] |
|
149 |
styleH2 = styles['Heading2'] |
|
150 |
story = [] |
|
151 |
||
4551 | 152 |
story.append(Paragraph('ReportLab %s Barcode Test Suite - full output' % __RL_Version__,styleH)) |
153 |
story.append(Paragraph('Generated at %s' % time.ctime(time.time()), styleN)) |
|
2587 | 154 |
|
155 |
story.append(Paragraph('About this document', styleH2)) |
|
156 |
story.append(Paragraph('History and Status', styleH2)) |
|
157 |
||
158 |
story.append(Paragraph(""" |
|
4551 | 159 |
This is the test suite and docoumentation for the ReportLab open source barcode API. |
2587 | 160 |
""", styleN)) |
161 |
||
162 |
story.append(Paragraph(""" |
|
163 |
Several years ago Ty Sarna contributed a barcode module to the ReportLab community. |
|
164 |
Several of the codes were used by him in hiw work and to the best of our knowledge |
|
165 |
this was correct. These were written as flowable objects and were available in PDFs, |
|
166 |
but not in our graphics framework. However, we had no knowledge of barcodes ourselves |
|
167 |
and did not advertise or extend the package. |
|
168 |
""", styleN)) |
|
169 |
||
170 |
story.append(Paragraph(""" |
|
171 |
We "wrapped" the barcodes to be usable within our graphics framework; they are now available |
|
172 |
as Drawing objects which can be rendered to EPS files or bitmaps. For the last 2 years this |
|
173 |
has been available in our Diagra and Report Markup Language products. However, we did not |
|
174 |
charge separately and use was on an "as is" basis. |
|
175 |
""", styleN)) |
|
176 |
||
177 |
story.append(Paragraph(""" |
|
178 |
A major licensee of our technology has kindly agreed to part-fund proper productisation |
|
179 |
of this code on an open source basis in Q1 2006. This has involved addition of EAN codes |
|
180 |
as well as a proper testing program. Henceforth we intend to publicise the code more widely, |
|
181 |
gather feedback, accept contributions of code and treat it as "supported". |
|
182 |
""", styleN)) |
|
183 |
||
184 |
story.append(Paragraph(""" |
|
185 |
This involved making available both downloads and testing resources. This PDF document |
|
186 |
is the output of the current test suite. It contains codes you can scan (if you use a nice sharp |
|
187 |
laser printer!), and will be extended over coming weeks to include usage examples and notes on |
|
188 |
each barcode and how widely tested they are. This is being done through documentation strings in |
|
189 |
the barcode objects themselves so should always be up to date. |
|
190 |
""", styleN)) |
|
191 |
||
192 |
story.append(Paragraph('Usage examples', styleH2)) |
|
193 |
story.append(Paragraph(""" |
|
194 |
To be completed |
|
195 |
""", styleN)) |
|
196 |
||
197 |
story.append(Paragraph('The codes', styleH2)) |
|
198 |
story.append(Paragraph(""" |
|
199 |
Below we show a scannable code from each barcode, with and without human-readable text. |
|
200 |
These are magnified about 2x from the natural size done by the original author to aid |
|
201 |
inspection. This will be expanded to include several test cases per code, and to add |
|
202 |
explanations of checksums. Be aware that (a) if you enter numeric codes which are too |
|
203 |
short they may be prefixed for you (e.g. "123" for an 8-digit code becomes "00000123"), |
|
204 |
and that the scanned results and readable text will generally include extra checksums |
|
205 |
at the end. |
|
206 |
""", styleN)) |
|
207 |
||
208 |
codeNames = getCodeNames() |
|
209 |
from reportlab.lib.utils import flatten |
|
210 |
width = [float(x[8:]) for x in sys.argv if x.startswith('--width=')] |
|
211 |
height = [float(x[9:]) for x in sys.argv if x.startswith('--height=')] |
|
212 |
isoScale = [int(x[11:]) for x in sys.argv if x.startswith('--isoscale=')] |
|
213 |
options = {} |
|
214 |
if width: options['width'] = width[0] |
|
215 |
if height: options['height'] = height[0] |
|
216 |
if isoScale: options['isoScale'] = isoScale[0] |
|
217 |
scales = [x[8:].split(',') for x in sys.argv if x.startswith('--scale=')] |
|
3721 | 218 |
scales = list(map(float,scales and flatten(scales) or [1])) |
219 |
scales = list(map(float,scales and flatten(scales) or [1])) |
|
2587 | 220 |
for scale in scales: |
221 |
story.append(PageBreak()) |
|
222 |
story.append(Paragraph('Scale = %.1f'%scale, styleH2)) |
|
223 |
story.append(Spacer(36, 12)) |
|
224 |
for codeName in codeNames: |
|
225 |
s = [Paragraph('Code: ' + codeName, styleH2)] |
|
226 |
for hr in (0,1): |
|
227 |
s.append(Spacer(36, 12)) |
|
228 |
dr = createBarcodeDrawing(codeName, humanReadable=hr,**options) |
|
229 |
dr.renderScale = scale |
|
230 |
s.append(dr) |
|
231 |
s.append(Spacer(36, 12)) |
|
232 |
s.append(Paragraph('Barcode should say: ' + dr._bc.value, styleN)) |
|
233 |
story.append(KeepTogether(s)) |
|
234 |
||
235 |
SimpleDocTemplate(fileName).build(story) |
|
3721 | 236 |
print('created', fileName) |
2587 | 237 |
|
238 |
if __name__=='__main__': |
|
239 |
run() |
|
240 |
fullTest() |
|
3669
40848d552920
fix issue 5, Tsy's createBarcodeInMemory was incomplete
robin
parents:
3502
diff
changeset
|
241 |
def createSample(name,memory): |
40848d552920
fix issue 5, Tsy's createBarcodeInMemory was incomplete
robin
parents:
3502
diff
changeset
|
242 |
f = open(name,'wb') |
40848d552920
fix issue 5, Tsy's createBarcodeInMemory was incomplete
robin
parents:
3502
diff
changeset
|
243 |
f.write(memory) |
40848d552920
fix issue 5, Tsy's createBarcodeInMemory was incomplete
robin
parents:
3502
diff
changeset
|
244 |
f.close() |
40848d552920
fix issue 5, Tsy's createBarcodeInMemory was incomplete
robin
parents:
3502
diff
changeset
|
245 |
createSample('test_cbcim.png',createBarcodeImageInMemory('EAN13', value='123456789012')) |
40848d552920
fix issue 5, Tsy's createBarcodeInMemory was incomplete
robin
parents:
3502
diff
changeset
|
246 |
createSample('test_cbcim.gif',createBarcodeImageInMemory('EAN8', value='1234567', format='gif')) |
4294 | 247 |
createSample('test_cbcim.pdf',createBarcodeImageInMemory('UPCA', value='03600029145',format='pdf', barHeight=40)) |
3669
40848d552920
fix issue 5, Tsy's createBarcodeInMemory was incomplete
robin
parents:
3502
diff
changeset
|
248 |
createSample('test_cbcim.tiff',createBarcodeImageInMemory('USPS_4State', value='01234567094987654321',routing='01234567891',format='tiff')) |