[Scribus] importing multi-page pdf
Min Xu
mxu
Thu Feb 2 03:11:42 CET 2006
On Wed, Feb 01, 2006 at 08:58:42PM -0500, Gregory Pittman wrote:
> Min Xu wrote:
> > Gregory,
> >
> > Thanks for your wiki article and examples. In fact, I did learn
> > how to loadImage() from pdf or ps from your scripts. However, I found
> > the results have low resolution. You can see it here:
> >
> > http://www.cs.wisc.edu/~xu/tmp/test.gif
> >
> > Also, I didn't see how to change the resolution for the loaded
> > ps image. I assume higher resolution can help.
> >
> >
> I just tried this myself, and I think if you convert your .sla file to a
> PDF you will find that the resolution is much better than this, almost
> as good as the original PDF.
This is interesting. Can you give me more details? I used the following
script to create a .sla file and then use export to get the pdf file.
Anything wrong with my script?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os
try:
import scribus
except ImportError, err:
print "This script only runs from within Scribus."
sys.exit(1)
""" You can import a multi-page pdf file using this script.
"""
TITLE = "Import PDF"
def getPages(filename):
# run pdfinfo to get the pages
for line in os.popen("/usr/bin/pdfinfo %s"%filename).readlines():
tokens = line.split()
if (tokens[0] == "Pages:"): return int(tokens[1])
# something wrong
return 0
if 1:
filename = scribus.fileDialog(TITLE, "*.pdf", "", 0, 1)
prefix = filename[:-4]
if filename:
# find total page number
pages = getPages(filename)
# make a new document
scribus.newDoc(scribus.PAPER_A4, (10, 10, 20, 20), scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.FACINGPAGES, scribus.FIRSTPAGERIGHT)
for i in range(1, pages+1):
# pdftops a page from the pdf file
os.popen("/usr/bin/pdftops -f %d -l %d %s %s_%03d.ps"%(i, i, filename, prefix, i))
# load a page
scribus.gotoPage(i)
name = scribus.createImage(20, 20, 550, 800)
scribus.loadImage("%s_%03d.ps"%(prefix, i), name)
# append a new page at the end of the document for next iteration
scribus.newPage(-1)
# save the file
scribus.saveDocAs("%s.sla"%prefix)
scribus.closeDoc()
scribus.messageBox(TITLE, "file: %s, pages: %d"%(filename, pages), scribus.ICON_WARNING, scribus.BUTTON_OK)
else:
scribus.messageBox(TITLE, "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK)
More information about the scribus
mailing list