@@ -1386,6 +1386,19 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
13861386 shutil .move (psfile , tmpfile )
13871387
13881388
1389+ # While it is best if above steps preserve the original bounding
1390+ # box, there seem to be cases when it is not. For those cases,
1391+ # the original bbox can be restored during the pstoeps step.
1392+
1393+ if eps :
1394+ # pstoeps(tmpfile, bbox, rotated=rotated)
1395+
1396+ # For some versions of gs, above steps result in an ps file
1397+ # where the original bbox is no more correct. Do not adjust
1398+ # bbox for now.
1399+ pstoeps (tmpfile )
1400+
1401+
13891402def xpdf_distill (tmpfile , eps = False , ptype = 'letter' , bbox = None , rotated = False ):
13901403 """
13911404 Use ghostscript's ps2pdf and xpdf's/poppler's pdftops to distill a file.
@@ -1490,13 +1503,18 @@ def get_bbox(tmpfile, bbox):
14901503 return '\n ' .join ([bbox_info , hires_bbox_info ])
14911504
14921505
1493- def pstoeps (tmpfile , bbox , rotated = False ):
1506+ def pstoeps (tmpfile , bbox = None , rotated = False ):
14941507 """
1495- Convert the postscript to encapsulated postscript.
1508+ Convert the postscript to encapsulated postscript. The bbox of
1509+ the eps file will be replaced with the given *bbox* argument. If
1510+ None, original bbox will be used.
14961511 """
14971512
14981513 # if rotated==True, the output eps file need to be rotated
1499- bbox_info , rotate = get_bbox_header (bbox , rotated = rotated )
1514+ if bbox :
1515+ bbox_info , rotate = get_bbox_header (bbox , rotated = rotated )
1516+ else :
1517+ bbox_info , rotate = None , None
15001518
15011519 epsfile = tmpfile + '.eps'
15021520 epsh = file (epsfile , 'w' )
@@ -1507,7 +1525,8 @@ def pstoeps(tmpfile, bbox, rotated=False):
15071525 while line :
15081526 if line .startswith ('%!PS' ):
15091527 print >> epsh , "%!PS-Adobe-3.0 EPSF-3.0"
1510- print >> epsh , bbox_info
1528+ if bbox :
1529+ print >> epsh , bbox_info
15111530 elif line .startswith ('%%EndComments' ):
15121531 epsh .write (line )
15131532 print >> epsh , '%%BeginProlog'
@@ -1522,10 +1541,10 @@ def pstoeps(tmpfile, bbox, rotated=False):
15221541 if rotate :
15231542 print >> epsh , rotate
15241543 break
1525- elif line .startswith ('%%Bound' ) \
1526- or line .startswith ('%%HiResBound' ) \
1527- or line .startswith ('%%DocumentMedia' ) \
1528- or line .startswith ('%%Pages' ):
1544+ elif bbox and ( line .startswith ('%%Bound' ) \
1545+ or line .startswith ('%%HiResBound' ) \
1546+ or line .startswith ('%%DocumentMedia' ) \
1547+ or line .startswith ('%%Pages' ) ):
15291548 pass
15301549 else :
15311550 epsh .write (line )
0 commit comments