Mam kilkaset plików pdf (zawierajacych różne tabele), przerabiam je na xml za pomocą pdftohtml:
Kod
pdftohtml filename -xml -enc "UTF-8"
Wynikiem jest plik XML o strukturze:
Kod
page (number=int, width=int, height=int)
text (left=int,top=int,width=int,height=int)
content
text (left=int,top=int,width=int,height=int)
content
który po wizualizacji wygląda np. w ten sposób: http://imgur.com/a/3vDEg
Teraz potrzebuję algorytmu który będzie potrafił tego xml zamienić na tabele html, musi więc:
- wykryć kolumny
- wykryć wiersze
- połączyć treść wierszy (te małe kwadraciki to polskie znaki które są odłączone od reszty)
Macie jakieś fajne pomysły?
Może ktoś z Was spotkał się kiedyś z takim problemem?
Albo w ogóle ide w złym kierunku i takie narzędzie już istnieje? (szukałem, ale nic godnego uwagi nie ma)
Skrypt do wizualizacji plików wynikowych (xml) z pdftohtml, gdyby ktoś chciał sie pobawić:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"/> <title>xmltotable</title> </head> <body> <input type="file" name="file" /> <script type="text/javascript"> window.onload = function() { document.getElementsByTagName('input')[0].addEventListener('change', function(evt) { var reader = new FileReader(); reader.onloadend = function(event) { var parser = new DOMParser(), xml = parser.parseFromString(event.target.result.toString(), 'text/xml'), pages = xml.getElementsByTagName('page'); for(var p in pages) { if(pages.hasOwnProperty(p)) { var page = pages[p], texts = page.getElementsByTagName('text'), canvas = document.createElement('canvas'), ctx = canvas.getContext('2d'); canvas.width = page.getAttribute('width'); canvas.height = page.getAttribute('height'); canvas.style.marginTop = '10px'; ctx.strokeRect(0, 0, canvas.width, canvas.height); for(var t in texts) { if(texts.hasOwnProperty(t)) { var text = texts[t]; ctx.strokeRect( parseInt(text.getAttribute('left')), parseInt(text.getAttribute('top')), parseInt(text.getAttribute('width')), parseInt(text.getAttribute('height')) ); } } document.body.appendChild(canvas); } } }; reader.readAsText(evt.target.files[0], 'UTF-8'); }, false); }; </script> </body> </html>