@@ -1386,6 +1386,19 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
1386
1386
shutil .move (psfile , tmpfile )
1387
1387
1388
1388
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
+
1389
1402
def xpdf_distill (tmpfile , eps = False , ptype = 'letter' , bbox = None , rotated = False ):
1390
1403
"""
1391
1404
Use ghostscript's ps2pdf and xpdf's/poppler's pdftops to distill a file.
@@ -1490,13 +1503,18 @@ def get_bbox(tmpfile, bbox):
1490
1503
return '\n ' .join ([bbox_info , hires_bbox_info ])
1491
1504
1492
1505
1493
- def pstoeps (tmpfile , bbox , rotated = False ):
1506
+ def pstoeps (tmpfile , bbox = None , rotated = False ):
1494
1507
"""
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.
1496
1511
"""
1497
1512
1498
1513
# 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
1500
1518
1501
1519
epsfile = tmpfile + '.eps'
1502
1520
epsh = file (epsfile , 'w' )
@@ -1507,7 +1525,8 @@ def pstoeps(tmpfile, bbox, rotated=False):
1507
1525
while line :
1508
1526
if line .startswith ('%!PS' ):
1509
1527
print >> epsh , "%!PS-Adobe-3.0 EPSF-3.0"
1510
- print >> epsh , bbox_info
1528
+ if bbox :
1529
+ print >> epsh , bbox_info
1511
1530
elif line .startswith ('%%EndComments' ):
1512
1531
epsh .write (line )
1513
1532
print >> epsh , '%%BeginProlog'
@@ -1522,10 +1541,10 @@ def pstoeps(tmpfile, bbox, rotated=False):
1522
1541
if rotate :
1523
1542
print >> epsh , rotate
1524
1543
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' ) ):
1529
1548
pass
1530
1549
else :
1531
1550
epsh .write (line )
0 commit comments