Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64105

Re: Converting folders of jpegs to single pdf per folder

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <mail@timgolden.me.uk>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'root': 0.05; 'filenames': 0.09; 'python': 0.11; 'mostly': 0.14; '"w")': 0.16; '(and,': 0.16; 'dirnames,': 0.16; 'dirpath)': 0.16; 'dirpath,': 0.16; 'from:addr:timgolden.me.uk': 0.16; 'from:name:tim golden': 0.16; 'golden': 0.16; 'iterating': 0.16; 'message- id:@timgolden.me.uk': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'subject:Converting': 0.16; 'subject:folder': 0.16; 'temp': 0.16; 'tends': 0.16; 'textfile': 0.16; 'tjg': 0.16; 'thursday,': 0.16; 'wrote:': 0.18; 'library': 0.18; 'example': 0.22; 'import': 0.22; 'creating': 0.23; 'header :User-Agent:1': 0.23; 'directory.': 0.24; 'example.': 0.24; 'harry': 0.24; "haven't": 0.24; 'sort': 0.25; 'asking': 0.27; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'tim': 0.29; 'especially': 0.30; "i'm": 0.30; 'directory,': 0.31; 'subject:per': 0.31; 'file': 0.32; 'run': 0.32; 'quite': 0.32; 'text': 0.33; 'could': 0.34; 'problem': 0.35; 'hundreds': 0.35; 'usual': 0.35; 'but': 0.35; 'google': 0.35; 'useful': 0.36; 'thanks': 0.36; 'should': 0.36; 'january': 0.37; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'generating': 0.39; 'pdf': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'above,': 0.60; "you're": 0.61; 'email addr:gmail.com': 0.63; 'name': 0.63; 'such': 0.63; 'side': 0.67; 'walk': 0.74; 'from:addr:mail': 0.83; 'about?': 0.84; 'capture': 0.91; 'contents.': 0.91
Date Thu, 16 Jan 2014 20:07:59 +0000
From Tim Golden <mail@timgolden.me.uk>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Converting folders of jpegs to single pdf per folder
References <CAJ3b0o828ZOAYM8Gt0BsLcZ97beGAnQWT9C+_7yFE4HSjiiU3Q@mail.gmail.com> <mailman.5602.1389901256.18130.python-list@python.org> <0c648d2d-d8b3-4848-8b37-1e5e1ae40327@googlegroups.com>
In-Reply-To <0c648d2d-d8b3-4848-8b37-1e5e1ae40327@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5604.1389902872.18130.python-list@python.org> (permalink)
Lines 48
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1389902872 news.xs4all.nl 2845 [2001:888:2000:d::a6]:34356
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:64105

Show key headers only | View raw


On 16/01/2014 19:50, vasishtha.spier@gmail.com wrote:
> On Thursday, January 16, 2014 11:41:04 AM UTC-8, Tim Golden wrote:
> The usual go-to library for PDF generation is ReportLab. I haven't used
>>
>> it for a long while but I'm quite certain it would have no problem
>>
>> including images.
>>
>>
>>
>> Do I take it that it's the PDF-generation side of things you're asking
>>
>> about? Or do you need help iterating over hundreds of directories and files?
>>
>>
>>
>> TJG
>
> Its mostly the PDF generating side I need but I haven't yet used the Python directory and file traversing functions so an example of this would also be useful especially showing how I could capture the directory name and use that as the name of the pdf file I'm creating from the directory contents.
>
> Thanks again,
> Harry
>

Here's a quick example. (And, by the way, please try to avoid the sort 
of double-spacing above, especially if you're coming from Google Groups 
which tends to produce such effects).

This should walk down the Python directory, creating a text file for 
each directory. The textfile will contain the names of all the files in 
the directory. (NB this might create a lot of text files so run it 
inside some temp directory).

<code>
import os

root = "c:/temp"

for dirpath, dirnames, filenames in os.walk(root):
     print("Looking at", dirpath)
     txt_filename = os.path.basename(dirpath) + ".txt"
     with open(txt_filename, "w") as f:
       f.write("\n".join(filenames))

</code>


TJG

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Converting folders of jpegs to single pdf per folder Tim Golden <mail@timgolden.me.uk> - 2014-01-16 19:41 +0000
  Re: Converting folders of jpegs to single pdf per folder vasishtha.spier@gmail.com - 2014-01-16 11:50 -0800
    Re: Converting folders of jpegs to single pdf per folder Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-16 20:01 +0000
    Re: Converting folders of jpegs to single pdf per folder Tim Golden <mail@timgolden.me.uk> - 2014-01-16 20:07 +0000
      Re: Converting folders of jpegs to single pdf per folder vasishtha.spier@gmail.com - 2014-01-16 21:42 -0800
        Re: Converting folders of jpegs to single pdf per folder Tim Golden <mail@timgolden.me.uk> - 2014-01-17 08:53 +0000
        Re: Converting folders of jpegs to single pdf per folder Tim Golden <mail@timgolden.me.uk> - 2014-01-17 09:01 +0000
    Re: Converting folders of jpegs to single pdf per folder Tim Golden <mail@timgolden.me.uk> - 2014-01-16 20:12 +0000
      Re: Converting folders of jpegs to single pdf per folder vasishtha.spier@gmail.com - 2014-01-16 12:20 -0800

csiph-web