add /Pages reference to /Pages object each /page object
This commit is contained in:
parent
e1b3710c74
commit
1302315bed
1 changed files with 10 additions and 5 deletions
15
img2pdf.py
15
img2pdf.py
|
@ -69,6 +69,11 @@ def main(images, dpi, title=None, author=None, creator=None, producer=None,
|
||||||
|
|
||||||
pagestuples = list()
|
pagestuples = list()
|
||||||
|
|
||||||
|
# create an incomplete pages object so that a /Parent entry can be added to each page
|
||||||
|
pages = obj({
|
||||||
|
"/Type": "/Pages"
|
||||||
|
})
|
||||||
|
|
||||||
for im in images:
|
for im in images:
|
||||||
try:
|
try:
|
||||||
imgdata = Image.open(im)
|
imgdata = Image.open(im)
|
||||||
|
@ -140,6 +145,7 @@ def main(images, dpi, title=None, author=None, creator=None, producer=None,
|
||||||
|
|
||||||
page = obj({
|
page = obj({
|
||||||
"/Type": "/Page",
|
"/Type": "/Page",
|
||||||
|
"/Parent": pages,
|
||||||
"/Resources": {
|
"/Resources": {
|
||||||
"/XObject": {
|
"/XObject": {
|
||||||
"/Im0": image
|
"/Im0": image
|
||||||
|
@ -151,11 +157,9 @@ def main(images, dpi, title=None, author=None, creator=None, producer=None,
|
||||||
|
|
||||||
pagestuples.append((image, content, page))
|
pagestuples.append((image, content, page))
|
||||||
|
|
||||||
pages = obj({
|
# complete pages object with page information
|
||||||
"/Type": "/Pages",
|
pages.content["/Kids"] = [ pagetuple[2] for pagetuple in pagestuples ]
|
||||||
"/Kids": [ pagetuple[2] for pagetuple in pagestuples ],
|
pages.content["/Count"] = len(pagestuples)
|
||||||
"/Count": len(pagestuples)
|
|
||||||
})
|
|
||||||
|
|
||||||
catalog = obj({
|
catalog = obj({
|
||||||
"/Pages": pages,
|
"/Pages": pages,
|
||||||
|
@ -164,6 +168,7 @@ def main(images, dpi, title=None, author=None, creator=None, producer=None,
|
||||||
|
|
||||||
objects = list()
|
objects = list()
|
||||||
objects.append(info.tostring(3*(len(pagestuples)+1)))
|
objects.append(info.tostring(3*(len(pagestuples)+1)))
|
||||||
|
pages.identifier = 2 # manually set it because each page references to it
|
||||||
for i, (image, content, page) in enumerate(reversed(pagestuples)):
|
for i, (image, content, page) in enumerate(reversed(pagestuples)):
|
||||||
objects.append(image.tostring(3*(len(pagestuples)-i+1)-1))
|
objects.append(image.tostring(3*(len(pagestuples)-i+1)-1))
|
||||||
objects.append(content.tostring(3*(len(pagestuples)-i+1)-2))
|
objects.append(content.tostring(3*(len(pagestuples)-i+1)-2))
|
||||||
|
|
Loading…
Reference in a new issue