-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
142 lines (121 loc) · 3.44 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from pikepdf import Pdf,Object,Stream,Name
import img2pdf
from log import Log
from pages.Page import Page
def test_create_pdf(outdir):
pdf = Pdf.new()
font = pdf.make_indirect(
Object.parse(
"""
<<
/Type /Font
/Subtype /Type1
/Name /F1
/BaseFont /Helvetica
/Encoding /UTF-8
>>"""
)
)
width, height = 900, 900
image_data = b"\xff\xff\x00" * (width * height)
image = Stream(pdf, image_data)
image.stream_dict = Object.parse(
b"""
<<
/Type /XObject
/Subtype /Image
/ColorSpace /DeviceRGB
/BitsPerComponent 8
/Width 600
/Height 600
>>"""
)
rfont = {'/F1': font}
xobj = {'/Im1': image}
resources = {'/Font': rfont, '/XObject': xobj}
mediabox = [0, 0, 612, 792]
stream =b"""
q 144 0 0 144 234 324 cm /Im1 Do Q
"""
contents = Stream(pdf, stream)
page_dict = {
'/Type': Name('/Page'),
'/MediaBox': mediabox,
'/Contents': contents,
'/Resources': resources,
}
qpdf_page_dict = page_dict
page = pdf.make_indirect(qpdf_page_dict)
pdf.pages.append(page)
pdf.save(f"{outdir}//hi.pdf")
# def make_image_pdf(outdir):
# pdf = Pdf.new()
# font = pdf.make_indirect(
# Object.parse(
# """
# <<
# /Type /Font
# /Subtype /Type1
# /Name /F1
# /BaseFont /Helvetica
# /Encoding /UTF-8
# >>"""
# )
# )
# width, height = 900, 900
# with open("test//image.png", "rb") as image:
# image_data = image.read1()
# image = Stream(pdf, image_data)
# print(image.read_bytes())
# image.stream_dict = Object.parse(
# b"""
# <<
# /Type /XObject
# /Subtype /Image
# /ColorSpace /DeviceRGB
# /BitsPerComponent 8
# /Width 600
# /Height 600
# >>"""
# )
# rfont = {'/F1': font}
# xobj = {'/Im1': image}
# resources = {'/Font': rfont, '/XObject': xobj}
# mediabox = [0, 0, 612, 792]
# stream =b"""
# q 144 0 0 144 234 324 cm /Im1 Do Q
# """
# contents = Stream(pdf, stream)
# page_dict = {
# '/Type': Name('/Page'),
# '/MediaBox': mediabox,
# '/Contents': contents,
# '/Resources': resources,
# }
# qpdf_page_dict = page_dict
# page = pdf.make_indirect(qpdf_page_dict)
# pdf.pages.append(page)
# pdf.save(f"{outdir}//imagePDF.pdf")
def make_image_pdf(source_pdf:str):
with open(source_pdf,"wb") as f :
f.write(
img2pdf.convert(
"test//image.png"
)
)
def make_an_empyt_pdf(name:str):
# open("test//empty.pdf","w")
dst=Pdf.new();
dst.save(f"test//{name}.pdf")
# make_an_empyt_pdf("emp")
# make_image_pdf("test//simple_page.pdf")
# import logging
# import logging
# logging.debug('This is a debug message')
# logging.info('This is an info message')
# logging.warning('This is a warning message')
# logging.error('This is an error message')
# logging.critical('This is a critical message')
# import colorama
# from colorama import Fore
# print(Fore.RED + 'This text is red in color')