Index: setup.py
===================================================================
--- setup.py	(revision 14019)
+++ setup.py	(working copy)
@@ -26,5 +26,5 @@
         ],
     },
  	
-    install_requires = [ 'Trac >= 0.11' ]
+    install_requires = [ 'Trac >= 1.0' ]
 )
Index: wikitopdf/formats.py
===================================================================
--- wikitopdf/formats.py	(revision 14019)
+++ wikitopdf/formats.py	(working copy)
@@ -40,6 +40,10 @@
         # Prepare html doc arguments
         codepage = self.env.config.get('trac', 'default_charset', 'iso-8859-1')
 
+        # utf-8 not supported in htmldoc 1.8
+        if codepage == 'utf-8':
+            codepage = 'iso-8859-1'
+
         oformat = { 'pdf':'pdf14', 'ps':'ps2', 'html':'html'}[format]
         htmldoc_args = { 'book': '', 'format': oformat, 'charset': codepage }
             
@@ -70,8 +74,12 @@
 
         # htmldoc doesn't support utf-8, we need to use some other input encoding
         codepage = self.env.config.get('trac', 'default_charset', 'iso-8859-1')
+        if codepage == 'utf-8':
+            codepage = 'iso-8859-1'
+
         base_dir = self.env.config.get('wikitopdf', 'base_dir')
-        
+
+        req.args['page'] = pagename  # artifically manipulate pagename in request for wiki_to_pdf function
         page = wiki_to_pdf(WikiPage(self.env, pagename).text, self.env, req, base_dir, codepage)
         
         hfile, hfilename = mkstemp('wikitopdf')
@@ -107,4 +115,4 @@
         os.close(hfile)
                 
         return hfilename
-    
\ No newline at end of file
+    
Index: wikitopdf/wikitopdf.py
===================================================================
--- wikitopdf/wikitopdf.py	(revision 14019)
+++ wikitopdf/wikitopdf.py	(working copy)
@@ -14,6 +14,10 @@
 from trac.mimeview.api import Context, IContentConverter
 from trac.util import escape
 from trac.wiki.formatter import format_to_html
+from trac.attachment import Attachment  # Attachment class has a function
+                                        # to convert old file location to 
+                                        # new hash-based file location (
+                                        # >=Trac v1.0)
 
 EXCLUDE_RES = [
     re.compile(r'\[\[PageOutline([^]]*)\]\]'),
@@ -47,11 +51,10 @@
     for r in EXCLUDE_RES:
         text = r.sub('', text)
     
-    env.log.debug('WikiToPdf => Wiki intput for WikiToPdf: %r' % text)
+    env.log.debug('WikiToPdf => Wiki input for WikiToPdf: %r' % text)
     
     context = Context.from_request(req, resource='wiki', id=req.args.get('page', 'False'))
     page = format_to_html(env, context, text)
-    
     page = page.replace('<img', '<img border="0"')
     page = page.replace('?format=raw', '')
 
@@ -82,6 +85,7 @@
             theimg = page[addrpos+5:]
             thepos = theimg.find('"')
             theimg = theimg[:thepos]
+
             if theimg[:1] == '/':
                 theimg = tracuri + theimg
             try:
@@ -95,17 +99,52 @@
                 theimg = theimg.replace(" ","%20")
                 urlretrieve(theimg, newimg)
                 IMG_CACHE[theimg] = newimg
-                env.log.debug("ISLAM the image is %s new image is %s" % ( theimg, newimg))
+                env.log.debug("the image is %s new image is %s" % ( theimg, newimg))
                 imgcounter += 1
                 page = page[:addrpos+5] + newimg + page[addrpos+5+thepos:]
-                simgpos = page.find('<img', addrpos)
+                imgpos = page.find('<img', addrpos)
     else:
         # Use old search for images in path
         page = page.replace('raw-attachment', 'attachments')
+
         while imgpos != -1:
             addrpos = page.find('src="', imgpos)
+            end_of_src_field = page.find('"', addrpos+5)
+            if 'tracmath' in page[addrpos:end_of_src_field]:  # TracMath equation image
+                end_of_tracmath = page.find('tracmath', addrpos) + len('tracmath')
+                file_path = base_dir + '/mathcache' + page[end_of_tracmath: end_of_src_field]
+                page = page[:addrpos+5] + file_path + page[end_of_src_field:]
+                imgpos = page.find('<img', addrpos)
+                env.log.debug('WikiToPdf => tracmath path: ' + file_path)
+                continue  # next while iteration
+
 #            base_dir = base_dir.encode('ascii')
-            page = page[:addrpos+5] + base_dir + page[addrpos+5:]
+            # Normal attachment image
+            # separate realm (wiki, tickets)
+            realm_begin = page.find('attachments/', addrpos+5)
+            realm_end = page.find('/', realm_begin + len('attachments/'))
+            parent_end = page.find('/', realm_end+1)  # separate parent ticket, wiki page
+            filename_end = page.find('"', parent_end+1)  # separate filename
+            if -1 in [realm_begin, realm_end, parent_end, filename_end]:
+                # if any of the indices is -1, not found go to next img tag
+                imgpos = page.find('<img', addrpos)
+                continue
+
+            realm = page[realm_begin+len('attachments/'): realm_end]  # realm (tickets, wiki)
+            parent = page[realm_end+1: parent_end]  # parent (ticket, wikipage)
+            filename = page[parent_end+1: filename_end]  # attachment filename
+            morepath = filename.split('/')
+            if len(morepath) > 1:
+                parent = parent + '/' + '/'.join(morepath[:-1])
+                filename = morepath[-1]
+            env.log.debug('realm: '+realm+' parent: '+parent+' filename: '+filename)
+            # Use migration to trac 1.0 function in Attachment class to convert
+            # realm, parent, filename to a path in the filesystem using hash
+            # functions for dir names and filenames
+            file_path = Attachment._get_path(base_dir, realm, parent, filename)
+
+            env.log.debug('WikiToPdf => Converted file path is ' + file_path)
+            page = page[:addrpos+5] + file_path + page[filename_end:]
             imgpos = page.find('<img', addrpos)
     
     # Add center tags, since htmldoc 1.9 does not handle align="center"
@@ -223,7 +262,12 @@
 
     def convert_content(self, req, input_type, text, output_type):
 
-        codepage = self.env.config.get('trac', 'default_charset', 'iso-8859-1') 
+        codepage = self.env.config.get('trac', 'default_charset', 'iso-8859-1')
+
+        if codepage == 'utf-8':
+        # utf-8 not supported by htmldoc 1.8
+            codepage = 'iso-8859-1'
+
         base_dir = self.env.config.get('wikitopdf', 'base_dir')
 
         page = wiki_to_pdf(text, self.env, req, base_dir, codepage)
