Пример #1
0
 def test_custom_field_style(self):
     "custom default small text style"
     customstyle = ParagraphStyle("customstyle", fontSize=8)
     filler = PdfFormFiller(self.pdf)
     filler.add_text("Joe Smith", 0, (50, 50), (500, 100), style=customstyle)
     filler.write(self.out)
     self.assertHashOutput(self.out, "c60753864a1cb130519856f0a1bb0ab51ab0fcbea7baa4f36f5e101bfe6409b0")
Пример #2
0
 def test_custom_field_padding(self):
     "custom default small text style"
     custompadding = [6, 6, 6, 6]
     filler = PdfFormFiller(self.pdf)
     filler.add_text("Joe Smith", 0, (50, 50), (500, 100), padding=custompadding)
     filler.write(self.out)
     self.assertHashOutput(self.out, "2a195aa2ce8a1cc40465cffb39bcc187bd4555679611589083b8019fbe0933ef")
Пример #3
0
 def test_string_output_path(self):
     "can write to string outputFile"
     filler = PdfFormFiller(self.pdf)
     filler.add_text("Joe Smith", 0, (50, 50), (500, 100))
     tmpout = NamedTemporaryFile()
     filler.write(tmpout.name)
     self.assertHashOutput(tmpout, "d961e57867788345a3bc0ea3adaa34bb81bc439848f30472302bad6ce8e1b3a6")
Пример #4
0
 def test_no_fields(self):
     "Still exports even when no text fields are added"
     filler = PdfFormFiller(self.pdf)
     filler.write(self.out)
     self.assertHashOutput(
         self.out,
         "726d27c0809a73cedde958cb204a897c8f81fc367ca2aadc8101e6d38be8a9c5")
Пример #5
0
 def test_add_fields(self):
     "Can add several text fields"
     filler = PdfFormFiller(self.pdf)
     filler.add_text("Joe Smith", 0, (50, 50), (500, 100))
     filler.add_text("Joe Smith", 0, (50, 200), (500, 250))
     filler.write(self.out)
     self.assertHashOutput(
         self.out,
         "e2813583628380bc084cdede1531739034f2823849bcb9339368abe845af00d7")
Пример #6
0
 def test_add_fields(self):
     "Can add several text fields"
     filler = PdfFormFiller(self.pdf)
     filler.add_text("Joe Smith", 0, (50, 50), (500, 100))
     filler.add_text("Joe Smith", 0, (50, 200), (500, 250))
     filler.write(self.out)
     self.assertHashOutput(self.out, "e2813583628380bc084cdede1531739034f2823849bcb9339368abe845af00d7")
Пример #7
0
 def test_custom_boxes(self):
     "Blue field boxes appear debugging"
     filler = PdfFormFiller(self.pdf, boxes=(0, 0, 255))
     filler.add_text("Joe Smith", 0, (50, 50), (500, 100))
     filler.write(self.out)
     self.assertHashOutput(
         self.out,
         "2dd58978209ddd2c531987d5b12115ea7729e87e7aa7115b09cc18aa5ff45fef")
Пример #8
0
 def test_inlude_boxes(self):
     "Red field boxes appear debugging"
     filler = PdfFormFiller(self.pdf, boxes=True)
     filler.add_text("Joe Smith", 0, (50, 50), (500, 100))
     filler.write(self.out)
     self.assertHashOutput(
         self.out,
         "bf1bcef99f6de11bdf542f40eebd47f1dfc4861e5ec4d6ce65d0acd9228abd2e")
Пример #9
0
def make_lstpdf(pnam, lst):
    pdfmetrics.registerFont(
        TTFont("IPAexGothic", "/usr/share/fonts/ipaexg.ttf"))
    sty1 = ParagraphStyle("sty1", fontName="IPAexGothic", fontSize=16)
    sty2 = ParagraphStyle("sty2",
                          alignment=TA_RIGHT,
                          fontName="IPAexGothic",
                          fontSize=9)
    pdf = PyPDF2.PdfFileMerger()
    for ag, k in lst:
        ff = PdfFormFiller(get_abst(k))
        p = ff.pdf.getPage(0)
        ff.add_text(ag, 0, (40, 14), (100, 40), sty1)
        ff.add_text(app.setting.orsj, 0, (0, 14), (p.mediaBox[2] - 40, 40),
                    sty2)
        ff.add_text(
            app.setting.year + " " + app.setting.ncon,
            0,
            (0, 24),
            (p.mediaBox[2] - 40, 40),
            sty2,
        )
        n = min(2, ff.pdf.getNumPages())
        with TemporaryFile() as fp:
            ff.write(fp)
            fp.seek(0)
            fr = PyPDF2.PdfFileReader(fp)
            pdf.append(fr, pages=(0, n))
        if n < 2:
            with open(get_abst("empty"), "rb") as fp:
                pdf.append(fp)
    if os.path.exists(pnam):
        os.remove(pnam)
        time.sleep(0.05)
    try:
        pdf.write(pnam)
    except:
        pass
Пример #10
0
 def test_custom_default_style(self):
     "custom default small text style"
     customstyle = ParagraphStyle("customstyle", fontSize=8)
     filler = PdfFormFiller(self.pdf, style=customstyle)
     filler.add_text("Joe Smith", 0, (50, 50), (500, 100))
     filler.write(self.out)
     self.assertHashOutput(
         self.out,
         "c60753864a1cb130519856f0a1bb0ab51ab0fcbea7baa4f36f5e101bfe6409b0")
Пример #11
0
 def test_string_output_path(self):
     "can write to string outputFile"
     filler = PdfFormFiller(self.pdf)
     filler.add_text("Joe Smith", 0, (50, 50), (500, 100))
     tmpout = NamedTemporaryFile()
     filler.write(tmpout.name)
     self.assertHashOutput(
         tmpout,
         "d961e57867788345a3bc0ea3adaa34bb81bc439848f30472302bad6ce8e1b3a6")
Пример #12
0
 def test_custom_default_padding(self):
     "custom default small text style"
     custompadding = [6, 6, 6, 6]
     filler = PdfFormFiller(self.pdf, padding=custompadding)
     filler.add_text("Joe Smith", 0, (50, 50), (500, 100))
     filler.write(self.out)
     self.assertHashOutput(
         self.out,
         "2a195aa2ce8a1cc40465cffb39bcc187bd4555679611589083b8019fbe0933ef")
Пример #13
0
from pdfformfiller import PdfFormFiller
filler = PdfFormFiller("./bluecard_application_hp.pdf")
#filler = PdfFormFiller("./sampleform.pdf")
#filler.add_text("TEST TEXT", 1, (x1, y1), (x2, y2))
#filler.add_text("XXXXXXXXXX", 1, (36, 318), (48, 330))

# Mr checkbox: ((35, 335), (47, 347)
filler.add_text(chr(10003), 1, (140, 79), (149, 92))

# family name:
filler.add_text("O'Dell", 1, (110, 130), (286, 144))

filler.write("./bluecard_application_hp_FILLED.pdf")
Пример #14
0
 def test_custom_boxes(self):
     "Blue field boxes appear debugging"
     filler = PdfFormFiller(self.pdf, boxes=(0, 0, 255))
     filler.add_text("Joe Smith", 0, (50, 50), (500, 100))
     filler.write(self.out)
     self.assertHashOutput(self.out, "2dd58978209ddd2c531987d5b12115ea7729e87e7aa7115b09cc18aa5ff45fef")
Пример #15
0
 def test_inlude_boxes(self):
     "Red field boxes appear debugging"
     filler = PdfFormFiller(self.pdf, boxes=True)
     filler.add_text("Joe Smith", 0, (50, 50), (500, 100))
     filler.write(self.out)
     self.assertHashOutput(self.out, "bf1bcef99f6de11bdf542f40eebd47f1dfc4861e5ec4d6ce65d0acd9228abd2e")
Пример #16
0
 def test_no_fields(self):
     "Still exports even when no text fields are added"
     filler = PdfFormFiller(self.pdf)
     filler.write(self.out)
     self.assertHashOutput(self.out, "726d27c0809a73cedde958cb204a897c8f81fc367ca2aadc8101e6d38be8a9c5")