프로그래밍

[Node.js] PDF에 Watermark 찍기

Mesia 2017. 9. 19. 10:29

[PDF 관련 라이브러리] 

=============================================

(1) hummusJS / hummusRecipe

 - https://github.com/galkahana/HummusJS

 - https://github.com/chunyenHuang/hummusRecipe

 - 이미지 및 텍스트 추가 편집이 상당히 용이하고 transparency 값을 줄 수 있음. 

 - (단, PDF-1.3 파일버전은 지원하지 않으면 종종 PDF-1.4에서도 파일을 읽다가 PDF parsing error 를 내는 경우도 있음) 

(2) PDFKit

 - http://pdfkit.org/

 - http://www.oodlestechnologies.com/blogs/Creating-a-pdf-with-text-and-image-in-NodeJS

 - 이미지 및 텍스트 추가 편집이 용이하고 transparency 값을 줄 수 있음. (단, 기존의 PDF 파일 수정 방법을 모르겠음) 

(3) pdfjs (rkusa) 

 - https://github.com/rkusa/pdfjs

 - 이미지 및 텍스트 추가 편집이 용이하나 transparency 값을 줄 수 없음


[npm install gm] 

=============================================

 - gm은 노드에서 많이 사용하는 이미지 프로세싱 라이브러리 중 하나다.  

 - http://blog.jeonghwan.net/이미지-업로드-2-gm-모듈로-이미지-리사이징

 - npm install --save gm --prefix ./


[Install GraphicsMagick on Windows]

=============================================

 - http://www.graphicsmagick.org/INSTALL-windows.html


(1) GraphicsMagick-1.3.26-Q16-win64-dll.exe 설치 (next & next)

(2) gs921w64.exe 설치 (next & next) 

(3) type-ghostscript.mgk 파일에서 fonts 경로 수정

 - 'n019003l.pf' File does not exist 오류가 나면, 해당 폰트 경로를 찾아 수정해준다. 

 - C:\Program Files\GraphicsMagick-1.3.26-Q16\type-ghostscript.mgk


[GraphicsMagick Usage]

=============================================

 - http://aheckmann.github.io/gm/docs.html

 - http://www.graphicsmagick.org/GraphicsMagick.html

 - gm("img.png").watermark(brightness, saturation)

 - gm("img.png").watermark(50, 20)

 - gm composite -watermark 50x50 image.jpg watermark.png output.jpg


gm convert in_image.jpg -background transparent -fill grey -font Calibri -size 140x80 -pointsize 200 -gravity center -draw "text 100,100 'copyright text'" output.jpg


https://stackoverflow.com/questions/20997701/apply-watermark-with-text-image-using-graphicsmagick

https://github.com/aheckmann/gm

http://gonzalogm.com/2017/01/23/dynamic-images-with-graphicsmagick-on-node-js/


http://rhodesmill.org/brandon/2009/pdf-watermark-margins/

https://stackoverflow.com/questions/20997701/apply-watermark-with-text-image-using-graphicsmagick


[Node.Js Watermark Example]

-------------------------------------------

var fs = require('fs');

var gm = require('gm');


var watermark = 'watermark_sample.png';

var inImagePath = 'tent.jpg';

var outImagePath = 'outImage.jpg';


gm(inImagePath)

.command("composite")

.resize(700, 700)

.watermark(20, 0)

.in(watermark)

.write(outImagePath, function (err) {

  if (!err) 

  console.log('done');

  else 

  console.log(err);

});

-------------------------------------------


https://github.com/galkahana/HummusJS/issues/160