Prawn - Import Image from Url

prawn - import image from URL

you need to do the following -

require "open-uri"

Prawn::Document.generate(INSERT_YOUR_PDF_FILENAME_HERE) do
image open(INSERT_YOUR_URL_HERE)
end

Refer to http://rubydoc.info/gems/prawn/0.12.0/frames for more details.

Prawn - Links inside table cells

You can specify inline_format for the cell and create the link yourself:

cell_email = pdf.make_cell(
:content => "<link href='mailto:#{booking.user_email}'>#{booking.user_email}</link>",
:inline_format => true
)

You can specify inline_format for the whole table, too:

table data, :cell_style => { :inline_format => true }

Prawn's inline_format supports <b>, <i>, <u>, <strikethrough>, <sub>, <sup>, <font>, <color> and <link>.

How to download specific GIF images (condition: phd*.gif) from a website using Python's BeautifulSoup?

Instead of checking the name in the loop, you can use BeautifulSoup's built-in support for regular expressions. Provide the compiled regular expression as a value of src argument:

import re

from bs4 import BeautifulSoup as bs # note, you should use beautifulsoup4

for image in soup.find_all("img", src=re.compile('phd\d+\.gif$')):
...

phd\d+\.gif$ regular expression would search for text starting with phd, followed by 1 or more digits, followed by dot, followed by gif at the end of the string.

Note that you are using an outdated and unmaintained BeautifulSoup3, switch to beautifulsoup4:

pip install beautifulsoup4


Related Topics



Leave a reply



Submit