Page 1 of 1

Appending 2, single page files into a PDF document

Posted: 2015-06-21T16:04:07-07:00
by bantry11
I have a folder full of scanned pages, either PDF or JPG images that are single page for each file.

I tried creating a script with a long list of convert comments, e.g.

convert b1_0004a.jpg b1_0004b.jpg b1_0004.pdf
convert b1_0005a.jpg b1_0005b.jpg b1_0005.pdf
...

All of the PDF's that were created on mac platform had the following suffix .pdf? and the file could not be open.

I have now tried convert all .jpg to .pdf and that has worked.

All first pages have are denoted with an "a" and all second pages are denoted with a "b" within the file name, "c" for 3rd page.
I would like to combine file1a.jpg with file1b.jpg to file1.pdf
or
file1a.pdf with file1b.pdf to file1.pdf

or
file1a.pdf with file1b.pdf with file1c.pdf to file1.pdf (a three page document)

I have created 3 input folders: single page, double page, and triple page documents. Perhaps, that would make it easier to process in that I know that within the double page folder, I will want to create a series of 2 page PDF files from 2 PDF Image or 2 JPG Images. In the 3 page folder, I want to create a 3 page PDF document from 3 PDF or JPG images.

Re: Appending 2, single page files into a PDF document

Posted: 2015-06-21T16:49:33-07:00
by fmw42
You should always provide your version of IM and platform. Also what tool is not opening the pdf files?

These commands work fine for me on IM 6.1.9.6 Q16 Mac OSX Snow Leopard

convert logo: logo1.jpg
convert logo: logo2.jpg
convert logo1.jpg logo2.jpg logo12.pdf

The pdf file opens fine in Preview and in Adobe Reader.

Perhaps you are mixing RGB and CMYK jpeg images? Check to see that they both are sRGB? Do they have profiles?

Re: Appending 2, single page files into a PDF document

Posted: 2015-06-22T00:58:41-07:00
by bantry11
OS is Mac 10.9.5 and IM is ImageMagick 6.9.1-5 Q16 x86_64 2015-06-13. The JPG images were created in a single pass by duplex fujitsu scanner. I'm trying to collate front side with back side of a page into a single PDF. On the rare occassion, I will need to collate up to 4 sides into a single PDF. I do have a few pages in the directory, that may have come from my phone as the original was too large to scan. I don't believe that I would be mixing this content within a single file. I tried to open up file in Mac Preview. The odd thing was that all of the files that were created when I used a single line with convert fileA.jpg fileB.jpg file.pdf created a PDF output with .PDF?. There was a "?" in the generated file, even thought I did not name file with a "?".

Re: Appending 2, single page files into a PDF document

Posted: 2015-06-22T08:57:11-07:00
by fmw42
Might you have typed an illegal character at the end by accident? Does it happen if you convert one jpg to a pdf? Try adding -strip before the output as a test to see if it has to do with any meta data.

Re: Appending 2, single page files into a PDF document

Posted: 2015-06-22T14:25:30-07:00
by bantry11
I was able on the command line to use
convert b1_0004a.jpg b1_0004b.jpg b1_0004.pdf

It created a 2 page pdf file from both jpgs. Worked fine.

I then tried creating a script and the result was the same as previous all .pdf files created where .pdf?.

The first lines were:
#!/bin/bash
convert b1_0005a.jpg b1_0005b.jpg b1_0005.pdf
convert b1_0008a.jpg b1_0008b.jpg b1_0008.pdf

It continued for several hundred lines with same format. When I executed it, it came up with all *.pdf? files. Could there be temp space that is running out or something? Is there are way without a script to convert files with a simpler command based on a consistent file naming scheme as above?

Re: Appending 2, single page files into a PDF document

Posted: 2015-06-22T14:41:59-07:00
by fmw42
What happens if you run your script with only one convert in it? Did you save your script as something.sh and then make it executable with chmod u+x something.sh? Then run it as: bash something.sh Is there a proper return/newline at the end of each line in your script? What text editor did you use to create the script file? In OS 10.6.8 Snow Leopard, my TextEdit does not allow one to save as simple .txt format. Be sure you are saving as simple .txt format and not anything else.

SOLVED - Re: Appending 2, single page files into a PDF document

Posted: 2015-06-23T10:10:08-07:00
by bantry11
I figured out problem. I had control characters in my script. Fixed by using the following:
perl -pi -e 's/\r/\n/g' convert.sh

Other methods suggested for getting rid of ^M did not work on Mac. The "?" was appended to the suffix as it was a control character.

Re: Appending 2, single page files into a PDF document

Posted: 2015-06-23T16:32:25-07:00
by fmw42
BBEdit text editor on the Mac has a Zap Gremlins tool that would show those kinds of issues. I recommend BBEdit if you want to purchase a good text editor.