RSS/Atom feed Twitter
Site is read-only, email is disabled

Cannot use function file-pdf-save-multi

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

4 of 4 messages available
Toggle history

Please log in to manage your subscriptions.

Cannot use function file-pdf-save-multi Louis 10 Sep 20:49
  Cannot use function file-pdf-save-multi renzofilini 28 Oct 09:53
   Cannot use function file-pdf-save-multi renzofilini 28 Oct 09:59
    Cannot use function file-pdf-save-multi Ofnuts 28 Oct 13:43
Louis
2012-09-10 20:49:21 UTC (about 12 years ago)

Cannot use function file-pdf-save-multi

Hello,
I am having a problem with function file-pdf-save-multi().

# What I am trying to do

I am trying to render a list of several XCF files into a single PDF, each XCF file being rendered as a page of the output document. I have a first version, which works, but it uses file-pdf-save() to make one PDF file per XCF source file, and assembles them afterward using another program. As I am writing this script for some other people, some using GNU/Linux, and some Mac OS, I would like to keep the list of dependencies as small as possible. So if I could manage to make it pure GIMP (and sh), it would be perfect.

# The (non-working) script

The core part of my script is given at the end of this message. It provides two versions :
- the first one takes a single XCF file and converts it to PDF, using file-pdf-save(). It works, but I would prefer the following one to work: - the second one takes several XCF (actually, twice the same in this dummy version), and converts them as a two-pages PDF, each source XCF being one page of the PDF, using function file-pdf-save-multi(). It does not work, the output being :

ts> Create multipage PDF-Warning: An error occured while creating the PDF file:
error while writing to output stream Make sure you entered a valid filename and that the selected location isn't read only!

Error: Procedure execution of file-pdf-save-multi failed

# Error analysis

The error message is weird: I looked at the source code of the two functions I use (file-pdf-save and file-pdf-save-multi), and the way the output file is handled seems to be the same. However, although the first one succeeds, the second one fails, saying that maybe the location is read only (which is not the case).
http://git.gnome.org/browse/gimp/tree/plug-ins/common/file-pdf-save.c

# My question

I could not find on the Internet any example of file-pdf-save-multi() being used. The only documentation I found was the GIMP documentation, which was not sufficient for me to use it. Can you help me to use this function?

Regards,
Louis

==================== Script ==================================

#!/bin/bash # Usage: script_name.sh file.xcf
# Expected behavior:
# 1) creates output_simple.pdf as the PDF version of the argument # 2) creates output_multi.pdf as a PDF containing two pages, # each of which being a PDF version of the argument. # Actual behavior:
# 1) works
# 2) fails, and I wonder why.
#
# I hope my email agent did not messed up two much with lines breaks...

input=$1 output_base="output"

echo "### Using file-pdf-save" echo "\
(let* \
( \
(image (car (gimp-file-load RUN-NONINTERACTIVE \"$input\" \"$input\"))) \
(drawable (car (gimp-image-merge-visible-layers image CLIP-TO-IMAGE))) \
) \
(file-pdf-save RUN-NONINTERACTIVE image drawable \"${output_base}_simple.pdf\" \"${output_base}_simple.pdf\" TRUE TRUE TRUE) \
) \
(gimp-quit 0)" | \
gimp -i -b -

echo "\n###############" echo "### Using file-pdf-save-multi"

echo "\ (let \
( \
(images (cons-array 2 'double)) \ ) \
( \
(aset images 0 (car (gimp-file-load RUN-NONINTERACTIVE \"$input\" \"$input\"))) \
(aset images 1 (car (gimp-file-load RUN-NONINTERACTIVE \"$input\" \"$input\"))) \
(file-pdf-save-multi RUN-NONINTERACTIVE images 2 TRUE TRUE TRUE \"${output_base}_multi.pdf\" \"${output_base}_multi.pdf\") \ ) \
) \
(gimp-quit 0)" | \
gimp -i -b -

2019-10-28 09:53:43 UTC (about 5 years ago)
postings
2

Cannot use function file-pdf-save-multi

file-pdf-save-multi requires an array of image ids: This is my python code:

#
# PDF file-pdf-save-multi python-fu example # TESTED ON:
# GIMP 2.10.12 Python Console
# Python 2.7.16 (default, May 28 2019, 08:10:12) [GCC 8.3.0 64 bit (AMD64)] #
# Get image array
images = gimp.image_list()
#
# Optionally sort by filename to order pages by filename # images.sort(key=lambda x: x.filename, reverse=False) #
# Extract ids from image array
images_ids = [img.ID for img in images] #
# Save multi page pdf
pdf_filename = "/tmp/multipage_output.pdf" pdb.file_pdf_save_multi(len(images), images_ids, False, True, False, pdf_filename, pdf_filename)

Hello,
I am having a problem with function file-pdf-save-multi().

# What I am trying to do

I am trying to render a list of several XCF files into a single PDF, each XCF file being rendered as a page of the output document. I have a
first version, which works, but it uses file-pdf-save() to make one PDF
file per XCF source file, and assembles them afterward using another program. As I am writing this script for some other people, some using GNU/Linux, and some Mac OS, I would like to keep the list of dependencies as small as possible. So if I could manage to make it pure
GIMP (and sh), it would be perfect.

# The (non-working) script

The core part of my script is given at the end of this message. It provides two versions :
- the first one takes a single XCF file and converts it to PDF, using file-pdf-save(). It works, but I would prefer the following one to work:
- the second one takes several XCF (actually, twice the same in this dummy version), and converts them as a two-pages PDF, each source XCF being one page of the PDF, using function file-pdf-save-multi(). It does
not work, the output being :

ts> Create multipage PDF-Warning: An error occured while creating the PDF file:
error while writing to output stream Make sure you entered a valid filename and that the selected location isn't read only!

Error: Procedure execution of file-pdf-save-multi failed

# Error analysis

The error message is weird: I looked at the source code of the two functions I use (file-pdf-save and file-pdf-save-multi), and the way the
output file is handled seems to be the same. However, although the first
one succeeds, the second one fails, saying that maybe the location is read only (which is not the case).
http://git.gnome.org/browse/gimp/tree/plug-ins/common/file-pdf-save.c

# My question

I could not find on the Internet any example of file-pdf-save-multi() being used. The only documentation I found was the GIMP documentation, which was not sufficient for me to use it. Can you help me to use this function?

Regards,
Louis

==================== Script ==================================

#!/bin/bash # Usage: script_name.sh file.xcf
# Expected behavior:
# 1) creates output_simple.pdf as the PDF version of the argument # 2) creates output_multi.pdf as a PDF containing two pages, # each of which being a PDF version of the argument. # Actual behavior:
# 1) works
# 2) fails, and I wonder why.
#
# I hope my email agent did not messed up two much with lines breaks...

input=$1
output_base="output"

echo "### Using file-pdf-save" echo "\
(let* \
( \
(image (car (gimp-file-load RUN-NONINTERACTIVE \"$input\" \"$input\"))) \
(drawable (car (gimp-image-merge-visible-layers image CLIP-TO-IMAGE))) \
) \
(file-pdf-save RUN-NONINTERACTIVE image drawable \"${output_base}_simple.pdf\" \"${output_base}_simple.pdf\" TRUE TRUE TRUE) \
) \
(gimp-quit 0)" | \
gimp -i -b -

echo "\n###############" echo "### Using file-pdf-save-multi"

echo "\ (let \
( \
(images (cons-array 2 'double)) \ ) \
( \
(aset images 0 (car (gimp-file-load RUN-NONINTERACTIVE \"$input\" \"$input\"))) \
(aset images 1 (car (gimp-file-load RUN-NONINTERACTIVE \"$input\" \"$input\"))) \
(file-pdf-save-multi RUN-NONINTERACTIVE images 2 TRUE TRUE TRUE \"${output_base}_multi.pdf\" \"${output_base}_multi.pdf\") \ ) \
) \
(gimp-quit 0)" | \
gimp -i -b -

renzofilini (via www.gimpusers.com/forums)
2019-10-28 09:59:35 UTC (about 5 years ago)
postings
2

Cannot use function file-pdf-save-multi

Attached file with correct formatting.

file-pdf-save-multi requires an array of image ids: This is my python code:

#
# PDF file-pdf-save-multi python-fu example # TESTED ON:
# GIMP 2.10.12 Python Console
# Python 2.7.16 (default, May 28 2019, 08:10:12) [GCC 8.3.0 64 bit (AMD64)]
#
# Get image array
images = gimp.image_list()
#
# Optionally sort by filename to order pages by filename # images.sort(key=lambda x: x.filename, reverse=False) #
# Extract ids from image array
images_ids = [img.ID for img in images] #
# Save multi page pdf
pdf_filename = "/tmp/multipage_output.pdf" pdb.file_pdf_save_multi(len(images), images_ids, False, True, False, pdf_filename, pdf_filename)

Attachments:
* https://www.gimpusers.com/system/attachments/1277/original/file-pdf-save-multi-example.py

renzofilini (via www.gimpusers.com/forums)
Ofnuts
2019-10-28 13:43:35 UTC (about 5 years ago)

Cannot use function file-pdf-save-multi

On 10/28/19 10:59 AM, renzofilini wrote:

pdf_filename = "/tmp/multipage_output.pdf" pdb.file_pdf_save_multi(len(images), images_ids, False, True, False, pdf_filename, pdf_filename)

Works for me (Ubuntu 16.04).

In more recent release of Ubuntu, Gimp installed as a snap package is restricted by default to your Home tree. You have to tweak things to make it write elsewhere.

Otherwise, Gimp and OS versions?