기본 콘텐츠로 건너뛰기

[node.js] 파일 리더기 만들기 - 사용 모듈 정리, pdf 구조, hwp 구조

pdf -> html 변환

가장 무난하다.기본적으로 pdf는 htm와 비슷한 형태의 구조를 가지고 있다.
크게 header, body, xref table, trailer의 구조로 되어있다.pdf는 환경에 상관없이 표현을 하기 위한 목적을 가지고 있는 파일이다. 이런 이유 때문에 무난히 진행이 된 것 같다.
pdf2htmlex와 pdftohtmljs라는 모듈을 이용을 했다.
var pdftohtml = require('pdftohtmljs'); var converter = new pdftohtml('test.pdf', "sample.html"); converter.convert('ipad').then(function() { console.log("Success"); }).catch(function(err) { console.error("Conversion error: " + err); });

이미지나, text같은 것들이 거의 100%로 변환이 된다.

docx -> html 변환

docx파일을 html파일로 변환을 할 때는 style 적용과 한글이 깨지는 문제가 있다.
텍스트들을 전부 잘 읽기는 하는데 스타일 정보를 제대로 가져오지 못하기 때문에 좀 애매하다
- Headings.
- Lists.
- Customisable mapping from your own docx styles to HTML. For instance, you could convert WarningHeading to h1.warning by providing an appropriate style mapping.
- Tables. The formatting of the table itself, such as borders, is currently ignored, but the formatting of the text is treated the same as in the rest of the document.
- Footnotes and endnotes.
- Images.
Bold, italics, underlines, strikethrough, superscript and subscript.
Links.
Line breaks.
Text boxes. The contents of the text box are treated as a separate paragraph that appears after the paragraph containing the text box.
Comments.
위 내용에 한에서만 스타일 변경이 가능은 한 것 같은데 생각보다 잘 되지 않는다...
mammoth라는 모듈을 이용했다.
var mammoth = require("mammoth"); var options = { styleMap: [ // "u => em", // "p[style-name='Section Title'] => h1:fresh", // "p[style-name='Subsection Title'] => h2:fresh" ], includeDefaultStyleMap: false }; mammoth.convertToHtml({path: './reader/test.docx'}, {}).then(result=>{ let text = result.value; let message = result.messages; console.log(text); console.log(message); })

hwp -> html 변환

우선 hwp를 완전히 html로 변환하지 못했다.
하지만 Microsoft에서 hwp의 ml을 공개를 해서 hwp를 hwpml로 변환을 하였다.
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <HWPML Version="2.8" SubVersion="8.0.0.0" Style="embed"><HEAD SecCnt="1"><DOCSUMMARY><TITLE>hello world</TITLE><AUTHOR>누군가</AUTHOR><DATE>201751일 월요일 오전 9:38:44</DATE></DOCSUMMARY><DOCSETTING><BEGINNUMBER Page="1" Footnote="1" Endnote="1" Picture="1" Table="1" Equation="1"/><CARETPOS List="0" Para="5" Pos="0"/></DOCSETTING><MAPPINGTABLE><FACENAMELIST><FONTFACE Lang="Hangul" Count="2"><FONT Id="0" Type="ttf" Name="함초롬돋움"><TYPEINFO FamilyType="2" SerifStyle="3" Weight="5" Proportion="4" Contrast="0" StrokeVariation="1" ArmStyle="1" Letterform="1" Midline="1" XHeight="1"/></FONT><FONT Id="1" Type="ttf" Name="함초롬바탕"><TYPEINFO FamilyType="2" SerifStyle="3" Weight="5" Proportion="4" Contrast="0" StrokeVariation="1" ArmStyle="1" Letterform="1" Midline="1" XHeight="1"/></FONT></FONTFACE><FONTFACE Lang="Latin" Count="2"><FONT Id="0" Type="ttf" Name="함초롬돋움"><TYPEINFO FamilyType="2" SerifStyle="3" Weight="5" Proportion="4" Contrast="0" StrokeVariation="1" ArmStyle="1" Letterform="1" Midline="1" XHeight="1"/></FONT><FONT Id="1" Type="ttf" Name="함초롬바탕"><TYPEINFO FamilyType="2" SerifStyle="3" Weight="5" Proportion="4" Contrast="0" StrokeVariation="1" ArmStyle="1" Letterform="1" Midline="1" XHeight="1"/></FONT></FONTFACE><FONTFACE Lang="Hanja" Count="2"><FONT Id="0" Type="ttf" Name="함초롬돋움"><TYPEINFO FamilyType="2" SerifStyle="3" Weight="5" Proportion="4" Contrast="0" StrokeVariation="1" ArmStyle="1" Letterform="1" Midline="1" XHeight="1"/></FONT><FONT Id="1" Type="ttf" Name="함초롬바탕"><TYPEINFO FamilyType="2" SerifStyle="3" Weight="5" Proportion="4" Contrast="0" StrokeVariation="1" ArmStyle="1" Letterform="1" Midline="1" XHeight="1"/></FONT></FONTFACE><FONTFACE Lang="Japanese" Count="2"><FONT Id="0" Type="ttf" Name="함초롬돋움"><TYPEINFO FamilyType="2" SerifStyle="3" Weight="5" Proportion="4" Contrast="0" StrokeVariation="1" ArmStyle="1" Letterform="1" Midline="1" XHeight="1"/></FONT><FONT Id="1" Type="ttf" Name="함초롬바탕"><TYPEINFO FamilyType="2" SerifStyle="3" Weight="5" Proportion="4" Contrast="0" StrokeVariation="1" ArmStyle="1" Letterform="1" Midline="1" XHeight="1"/></FONT></FONTFACE><FONTFACE Lang="Other" Count="2"><FONT Id="0" Type="ttf" Name="함초롬돋움"><TYPEINFO FamilyType="2" SerifStyle="3" Weight="5" Proportion="4" Contrast="0" StrokeVariation="1" ArmStyle="1" Letterform="1" Midline="1" XHeight="1"/></FONT><FONT Id="1" Type="ttf" Name="함초롬바탕"><TYPEINFO FamilyType="2" SerifStyle="3" Weight="5" Proportion="4" Contrast="0" StrokeVariation="1" ArmStyle="1" Letterform="1" Midline="1" XHeight="1"/></FONT></FONTFACE><FONTFACE Lang="Symbol" Count="2"><FONT Id="0" Type="ttf" Name="함초롬돋움"><TYPEINFO FamilyType="2" SerifStyle="3" Weight="5" Proportion="4" Contrast="0" StrokeVariation="1" ArmStyle="1" Letterform="1" Midline="1" XHeight="1"/></FONT><FONT Id="1" Type="ttf" Name="함초롬바탕"><TYPEINFO FamilyType="2" SerifStyle="3" Weight="5" Proportion="4" Contrast="0" StrokeVariation="1" ArmStyle="1" Letterform="1" Midline="1" XHeight="1"/></FONT></FONTFACE><FONTFACE Lang="User" Count="2"><FONT Id="0" Type="ttf" Name="함초롬돋움"><TYPEINFO FamilyType="2" SerifStyle="3" Weight="5" Proportion="4" Contrast="0" StrokeVariation="1" ArmStyle="1" Letterform="1" Midline="1" XHeight="1"/></FONT><FONT Id="1" Type="ttf" Name="함초롬바탕"><TYPEINFO FamilyType="2" SerifStyle="3" Weight="5" Proportion="4" Contrast="0" StrokeVariation="1" ArmStyle="1" Letterform="1" Midline="1" XHeight="1"/></FONT></FONTFACE></FACENAMELIST><BORDERFILLLIST Count="1"><BORDERFILL Id="1" ThreeD="false" Shadow="false" Slash="0" BackSlash="0" CrookedSlash="0" CounterSlash="0" CounterBackSlash="0" BreakCellSeparateLine="0" CenterLine="0"><LEFTBORDER Type="None" Width="0.1mm" Color="0"/><RIGHTBORDER Type="None" Width="0.1mm" Color="0"/><TOPBORDER Type="None" Width="0.1mm" Color="0"/><BOTTOMBORDER Type="None" Width="0.1mm" Color="0"/><DIAGONAL Type="Solid" Width="0.1mm" Color="0"/><FILLBRUSH><WINDOWBRUSH FaceColor="4294967295" HatchColor="0" HatchStyle="-1" Alpha="0"/></FILLBRUSH></BORDERFILL></BORDERFILLLIST><CHARSHAPELIST Count="8"><CHARSHAPE Id="0" Height="1000" TextColor="0" ShadeColor="4294967295" UseFontSpace="false" UseKerning="false" SymMark="0" BorderFillId="1"><FONTID Hangul="1" Latin="1" Hanja="1" Japanese="1" Other="1" Symbol="1" User="1"/><RATIO Hangul="100" Latin="100" Hanja="100" Japanese="100" Other="100" Symbol="100" User="100"/><CHARSPACING Hangul="0" Latin="0" Hanja="0" Japanese="0" Other="0" Symbol="0" User="0"/><RELSIZE Hangul="100" Latin="100" Hanja="100" Japanese="100" Other="100" Symbol="100" User="100"/><CHAROFFSET Hangul="0" Latin="0" Hanja="0" Japanese="0" Other="0" Symbol="0" User="0"/></CHARSHAPE><CHARSHAPE Id="1" Height="1000" TextColor="0" ShadeColor="4294967295" UseFontSpace="false" UseKerning="false" SymMark="0" BorderFillId="1"><FONTID Hangul="0" Latin="0" Hanja="0" Japanese="0" Other="0" Symbol="0" User="0"/><RATIO Hangul="100" Latin="100" Hanja="100" Japa>daf</CHAR></TEXT></P></SECTION></BODY></HWPML>
해당 마크업 파일에는 스타일 정보, 내용 등이 들어있기 때문에 해당 파일을 파싱을 하면 가능하다.
일단 pyhwp라는 라이브러리가 있긴한데 이게 python특정 버전에서만 작동을 하는 것 같다. python3.x로 포팅을 시켜볼려고 했는데 잘 안되는......
다음으로 java를 이용해서 파싱을 해볼까 한다. 다행이 node bridge로 java연동이 되는 것 같다.
node-hwp라는 모듈을 사용하였다.
var hwp = require("./node-hwp"); var fs = require('fs'); hwp.open('helo.hwp', function(err, doc){ console.log(doc.toHML()); // fs.writeFile('test1.html', doc.toHML()); });
위 코드를 실행시키면 node-hwp가 없어서 에러가 뜰 것이다. 해당 모듈이 npm 받아지지 않아서 직접 git clone을 했다.
$ git clone https://github.com/123jimin/node-hwp.git

댓글

이 블로그의 인기 게시물

[git] git log 확인하기

git log를 통해서 커밋 이력과 해당 커밋에서 어떤 작업이 있었는지에 대해 조회를 할 수 있다. 우선 git에서의 주요 명령어부터 알아보겠다. $ git push [branch name] $ git pull [branch name] 여기서 branch name은 로컬일 경우 해당 브런치 이름만 적으면 되지만 깃허브 원격 저장소로 연결을 원할 경우는 해당 브런치 이름 앞에 꼭 origin을 붙이도록 한다. $ git brnch [branch name] $ git checkout [branch name] branch일경우 해당 브런치를 생성을 한다. 여기서 현재의 브런치를 기준으로 브런치를 따는것이다. checkout은 브런치를 바꾸는 것이다.(HEAD~[숫자]를 이용하면 해당 커밋으로 움직일수 있다.. 아니면 해당 커밋 번호를 통해 직접 옮기는것도 가능하다.) -> 해당 커밋으로 옮기는 것일뿐 실질적으로 바뀌는 것은 없다. 해당 커밋으로 완전히 되돌리려면 reset이라는 명령어를 써야한다. 처음 checkout을 쓰면 매우 신기하게 느껴진다. 막 폴더가 생겼다가 지워졌다가 ㅋㅋㅋㅋㅋ  master 브런치에서는 ht.html파일이 존재하지만 a브런치에서는 존재하지않는다. checkout 으로 변경을 하면 D 로 명시를 해준다.  $ git log 해당 브런치의 커밋 내역을 보여준다. a 브런치의 커밋 내역들이다. (머지 테스트를 하느라 커밋 내용이 거의 비슷하다 ㅋㅋ) master 브런치의 커밋 내역들이다. 커밋 번호, 사용자, 날짜, 내용순으로 등장을 한다. 이건 단순히 지금까지의 내역을 훑어보기 좋다. 좀더 세밀한 내용을 봐보자. $ git log --stat --stat을 붙이면 기존의 로그에서 간략하게 어떤 파일에서

[git] pull을 하여 최신코드를 내려받자

보면 먼가 로고가 다르게 뜨는것을 확인을 할 수가있다. C:\Users\mung\Desktop\etc\study\python-gene>git checkout remotes/origin/master Note: checking out 'remotes/origin/master'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example:   git checkout -b HEAD is now at 29e282a... fetch test C:\Users\mung\Desktop\etc\study\python-gene>git branch * (HEAD detached at origin/master)   master   test1   test2 깃이 잘 쓰면 참 좋은놈인데 어지간히 쓰기가 까다롭다. 처음에 깃을 푸시 성공하는데만 한달정도 걸렸던걸로 기억이 난다.. ㅋㅋㅋ 여담으로  깃 프로필을 가면 아래사진 처럼 보인다. 기여도에 따라서 초록색으로 작은 박스가 채워지는데 저걸 잔디라고 표현을 한다고 합니다 ㅎ 저 사진은 제 깃 기여도 사진입니당 ㅋㅋㅋㅋ 다시 본론으로 돌아와서 ㅋㅋ pull을 하면 깃에 최신 소

[kali linux] sqlmap - post요청 injection 시도

아래 내용은 직접 테스트 서버를 구축하여 테스트 함을 알립니다.  실 서버에 사용하여 얻는 불이익에는 책임을 지지 않음을 알립니다. sqlmap을 이용하여 get요청이 아닌 post요청에 대해서 injection공격을 시도하자. 뚀한 다양한 플래그를 이용하여 DB 취약점 테스트를 진행을 해보려고 한다. 서버  OS : windows 7 64bit Web server : X Server engine : node.js Framework : expresss Use modules : mysql Address : 172.30.1.30 Open port : 6000번 공격자 OS : kali linux 64bit use tools : sqlmap Address : 172.30.1.57 우선 서버측 부터  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 var  express  =  require( 'express' ); var  app  =  express(); var  mysql  =  require( 'mysql' ); var  ccc  =  mysql.createConnection({     host: '127.0.0.1' ,     user: 'root' ,     post: '3306' ,     password: '*********' ,     database: 'test' }) app.post(