Pywher.

WKHTMLTMTHOPDF FOR HEROKU
Áö±Ý ´Ù¿î·Îµå

Pywher. ¼øÀ§ ¹× ¿ä¾à

±¤°í

  • Rating:
  • ƯÇã:
  • BSD License
  • °¡°Ý:
  • FREE
  • °Ô½ÃÀÚ À̸§:
  • Jason Mayfield
  • °Ô½ÃÀÚ À¥»çÀÌÆ®:
  • https://github.com/codetalkrs/

Pywher. ű×


Pywher. ¼³¸í

WKHTMLTOPDF´Â QT¿¡¼­ Á¦°øÇÏ´Â WebKit ·»´õ¸µ ¿£ÁøÀ» »ç¿ëÇÏ¿© HTMLÀ» PDF·Î º¯È¯ÇÏ´Â ¸í·É ÁÙ ÇÁ·Î±×·¥ÀÔ´Ï´Ù. WebKitÀ» »ç¿ëÇϱ⠶§¹®¿¡ WKHTMLTOPDF¸¦ »ç¿ëÇÏ¿© ½ºÅ©¸° ¼¦À» »ý¼ºÇϰųª Django ¶Ç´Â Rails¿¡¼­ PDF¸¦ »ý¼ºÇÏ°í °á°ú PDF°¡ ¸ÚÁö°Ô º¸ÀÏ ¼ö ÀÖ½À´Ï´Ù. ÀÏ¹Ý ¼³Ä¡ ÇÁ·Î¼¼½º¿¡´Â Qt ´Ù¿î·Îµå ¹× ÄÄÆÄÀÏÀÌ Æ÷ÇÔ µÈ ´ÙÀ½ wkhtmltopdf.butÀ» ´Ù¿î·ÎµåÇÏ¿© ¼³Ä¡ÇؾßÇÕ´Ï´Ù. Heroku Dyno ³»¿¡¼­ ÆÐÅ°Áö¸¦ ´Ù¿î·ÎµåÇÏ°í ÄÄÆÄÀÏ ÇÒ ¼ö ¾øÀ¸¹Ç·Î »ç¿ëÇÏ·Á´Â ¿ÜºÎ ¹ÙÀ̳ʸ®¿¡¼­ °ø±Þ ¾÷ü°¡ ÇÊ¿äÇÕ´Ï´Ù (½º½º·Î ÄÄÆÄÀÏÇÏ´Â ÆÄÀ̽ã ÆÐÅ°Áö°¡ ¾Æ´Ñ). ÀÌ ÆÐÅ°Áö´Â Heroku (Cedar Stack) Dyno Environment¿¡¼­ ÄÄÆÄÀÏ µÈ WKHTMLTOPDF ¹ÙÀ̳ʸ®¸¦ Æ÷ÇÔÇÏ°í »ç¿ëÇÏ´Â °£´ÜÇÑ ¹æ¹ýÀ» Á¦°øÇÕ´Ï´Ù. PIP ¼³Ä¡ PywkherusageOne PywhtmlTmlTOPDF¸¦ »ç¿ëÇÏ¿© PywkherusageOne ½±°Ô WKHTMLTOPDF¸¦ »ç¿ëÇÏ´Â ¹æ¹ýÀº generate_pdf ¸í·ÉÀ» Æ÷ÇÔÇß½À´Ï´Ù. generate_pdf ¸í·ÉÀº URL ¶Ç´Â HTML ¹®¼­¸¦ »ç¿ëÇÏ°í »ý¼º µÈ PDF (Heroku ÀνºÅϽºÀÇ Àӽà µð·ºÅ丮¿¡ ÀúÀå µÉ ¿¹Á¤ÀÎ Python NamedTemporaryFile °³Ã¼)¸¦ ¹ÝȯÇÕ´Ï´Ù. generate_pdf ¸í·ÉÀ» »ç¿ëÇÏ¿© Django ÅÛÇø´À» PDF·Î ·»´õ¸µÇÏ´Â ¿¹Á¦ÀÔ´Ï´Ù. ¹× HTTP ÀÀ´äÀÇ ÀϺηΠ°á°ú PDF¸¦ ¹ÝȯÇÕ´Ï´Ù. OS.PATH °¡Á® ¿À±â WSGIREF.UTIL import filewapperfrom django.http °¡Á® ¿À±â httpresponsefrom django.template import requestContextFrom import get_templatefrom pywher °¡Á® ¿À±â generate_pdfdef return_a_pdf (¿äû) : ÅÛÇø´ = get_template ( 'my_awesome_template.html') html = template.render (requestContext (¿äû)) pdf_file = generate_pdf (html = html) ÀÀ´ä = httpresponse (filewapper (pdf_file), content_type = 'ÀÀ¿ë ÇÁ·Î±×·¥ / pdf') ÀÀ´ä ='ºÎÂø; filename = % s.zip '% basename (pdf_file.name) ÀÀ´ä = pdf_file.tell () pdf_file.tell (0) PDF_FILE.SEEK (0) PDF_FILE.SEEK (0) DeveloptyIfÀÇ ResponseSigage ¾ÛÀ» ·ÎÄ÷ΠÅ×½ºÆ®ÇÏ°í ºÐ¸íÈ÷ ÀÌÁøÀ» ºÐ¸íÈ÷ Å×½ºÆ® ÇÒ °ÍÀÔ´Ï´Ù. Heroku¸¦ À§ÇØ ÄÄÆÄÀÏ µÈ °ÍÀº °³¹ßÀ̳ª Å×½ºÆ® ȯ°æÀÌ °¡±îÀ̼­ Heroku¸¦ ¹ÐÁ¢ÇÏ°Ô ¸ð¹æÇÏÁö ¾Ê´Â ÇÑ ÀÏÇÏÁö ¾ÊÀ» °ÍÀÔ´Ï´Ù. ±×·¯³ª »ý¼º ÇÔ¼ö´Â wkhtmltopdf_cmd¶ó´Â ȯ°æ º¯¼ö¸¦ ã¾Æ ³»°í ÀÖÀ¸¸ç ȯ°æ º¯¼ö°¡ ¼³Á¤µÇÁö ¾ÊÀº °æ¿ì ³»ºÎÀûÀ¸·Î ¹øµé µÈ wkhtmltopdf ¹ÙÀ̳ʸ® ¸¸ »ç¿ëÇÕ´Ï´Ù. µû¶ó¼­, Mac¿¡ÀÖ´Â °æ¿ì : - BREW ¼³Ä¡ wkhtmltopdf ( ÀÌ°Í¿¡ ÇÊ¿äÇÑ È¨ ´ýÇÁ°¡ ÇÊ¿äÇÕ´Ï´Ù. Heroku Vulcan Build Process Singl.ProductÀÇ È¨ÆäÀÌÁö Àüü¸¦ Åë°ú ÇÒ ÇÊ¿ä°¡¾ø´Â ±×ÀÇ ³ë·Â ´öºÐÀÔ´Ï´Ù.


Pywher. °ü·Ã ¼ÒÇÁÆ®¿þ¾î