@@ -368,6 +368,10 @@ def processBackground(backgroundTags, bg_notFoundDirList, cewe_folder, backgroun
368368 backgroundTag = curTag
369369 break
370370
371+ if pagetype == PageType .Normal and isAlbumDoubleSide (productstyle ) and backgroundTag .get ('alignment' ) == "3" :
372+ areaWidth = areaWidth / 2
373+ areaXOffset = areaXOffset + areaWidth
374+
371375 if (cewe_folder and backgroundTag is not None
372376 and backgroundTag .get ('designElementId' ) is not None ):
373377 bg = backgroundTag .get ('designElementId' )
@@ -392,17 +396,8 @@ def processBackground(backgroundTags, bg_notFoundDirList, cewe_folder, backgroun
392396 try :
393397 bgPath = ""
394398 bgPath = findFileInDirs ([bg + '.bmp' , bg + '.webp' , bg + '.jpg' ], backgroundLocations )
395-
396- # Feb 2025, removed single/double side differentiation here, which basically cured
397- # issue https://github.com/bash0/cewe2pdf/issues/198. I can only imagine that we have
398- # tried to cure single/double page problems with "partial fixes" through the years
399- # without understanding or testing all the cases. It is true that this solution does
400- # not show the "forced empty pages" on the inside of the covers as white, a la CEWE,
401- # but rather uses the background colour of the cover page. This whiteness is what
402- # issue 198 is really complaining about, and I agree with it. Cover page colour is
403- # a better choice when we are creating a pdf.
404-
405399 logging .debug (f"Reading background file: { bgPath } " )
400+
406401 # webp doesn't work with PIL.Image.open in Anaconda 5.3.0 on Win10
407402 imObj = PIL .Image .open (bgPath )
408403 # create a in-memory byte array of the image file
@@ -411,10 +406,11 @@ def processBackground(backgroundTags, bg_notFoundDirList, cewe_folder, backgroun
411406 imObj = imObj .convert ("RGB" )
412407 imObj .save (memFileHandle , 'jpeg' )
413408 memFileHandle .seek (0 )
414- # im = imread(bgpath) #does not work with 1-bit images
415- pdf .drawImage (ImageReader (
416- memFileHandle ), f * areaXOffset , 0 , width = f * areaWidth , height = f * areaHeight )
409+
417410 # pdf.drawImage(ImageReader(bgpath), f * ax, 0, width=f * aw, height=f * ah)
411+ # but im = ImageReader(bgpath) does not work with 1-bit images,so ...
412+ pdf .drawImage (ImageReader (memFileHandle ), f * areaXOffset , 0 , width = f * areaWidth , height = f * areaHeight )
413+
418414 except Exception :
419415 if bgPath not in bg_notFoundDirList :
420416 logging .error ("Could not find background or error when adding to pdf" )
@@ -1741,7 +1737,8 @@ def convertMcf(albumname, keepDoublePages: bool, pageNumbers=None, mcfxTmpDir=No
17411737 # cover pages. Add 2 so that pagecount represents the actual number of printed pdf pages we expect in the normal single sided
17421738 # pdf print (a basic album is 26 inside pages, plus front and back cover, i.e. 28). If we use keepDoublePages, then we'll
17431739 # actually be producing 2 more (the inside covers) but halving the number of final output pdf pages, making 15 double pages.
1744- # There is also a totalpages attribute in the mcf, but oddly in my files it is 3 more than the normalpages value. Why not 4 more?
1740+ # There is also a totalpages attribute in the mcf, but in my files it is 5 more than the normalpages value. Why not 4 more? I
1741+ # guess that may be because it is a count of the <page> elements and not actually related to the number of printed pages.
17451742 imagedir = fotobook .get ('imagedir' )
17461743
17471744 # generate a list of available clip-arts
@@ -1779,7 +1776,7 @@ def IsOddPage(n):
17791776 lastpage = IsLastPage (n ) # bool assign is clearer with parens so pylint: disable=superfluous-parens
17801777
17811778 # The <page> sections all have a pagenr attribute. The normal pages run from pagenr 1 to pagenr 26 while there are
1782- # actually FIVE page elements with pagenr 0 in an album file, 4 coming before pagenr 1 and 1 after pagenr 26
1779+ # actually FIVE page elements with pagenr 0 in a default album file, 4 coming before pagenr 1 and 1 after pagenr 26
17831780 if isAlbumProduct (productstyle ) and ((n == 0 ) or IsBackCover (n )): # clearest like this so pylint: disable=consider-using-in
17841781 fullcoverpages = [i for i in
17851782 fotobook .findall ("./page[@pagenr='0'][@type='FULLCOVER']" )
@@ -1807,14 +1804,15 @@ def IsOddPage(n):
18071804 page = [i for i in
18081805 fotobook .findall ("./page[@pagenr='0'][@type='EMPTY']" )
18091806 + fotobook .findall ("./page[@pagenr='0'][@type='emptypage']" )
1810- if i .find ("./area" ) is not None ]
1807+ if i .find ("./area" ) is not None or i . find ( "./background[@alignment='1']" ) is not None ]
18111808 if len (page ) >= 1 :
18121809 page = page [0 ]
18131810 # If there is on page 1 only text, the area-tag is still on page 0.
18141811 # So this will either include the text (which is put in page 0),
18151812 # or the packground which is put in page 1.
18161813 else :
1817- page = None # if we find no empty page with an area tag, we need to set this to None to prevent an exception later.
1814+ logging .error (f'Failed to locate initial emptypage when processing page { n } ' )
1815+ page = None
18181816
18191817 # Look for the the first page and set it up for processing
18201818 realFirstPageList = fotobook .findall ("./page[@pagenr='1'][@type='normalpage']" )
@@ -1845,14 +1843,15 @@ def IsOddPage(n):
18451843 page = [i for i in
18461844 fotobook .findall ("./page[@pagenr='0'][@type='EMPTY']" )
18471845 + fotobook .findall ("./page[@pagenr='0'][@type='emptypage']" )
1848- if i .find ("./area" ) is None ]
1846+ if i .find ("./area" ) is None or i . find ( "./background[@alignment='3']" ) is not None ]
18491847 if len (page ) >= 1 :
18501848 # set up to process the special section for the inside cover
18511849 page = page [0 ]
18521850 pageNumber = n + 1
18531851 oddpage = IsOddPage (pageNumber )
18541852 pagetype = PageType .BackInsideCover
18551853 else :
1854+ logging .error (f'Failed to locate final emptypage when processing last page { n } ' )
18561855 page = None # catastrophe
18571856
18581857 else :
0 commit comments