Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SVG image Support #97

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ A template plugin allowing the inclusion of ERB-enabled RBPDF template files.
* Image
- 8bit PNG image support without MiniMagick/RMagick library.
- PNG(with alpha channel)/JPEG/GIF/WebP image support. (use MiniMagick or RMagick library)
- SVG image support. (use REXML for XML parsing.)


##
Expand Down
2 changes: 1 addition & 1 deletion example/rails/app/controllers/example006_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def index
<dd>White cold drink</dd>
</dl>
<div style="text-align:center">IMAGES<br />
<img src="' + PDF_EXAMPLE_LOGO + '" alt="test alt attribute" width="100" height="100" border="0" /><img src="' + PDF_TIGER_AI + '" alt="test alt attribute" width="100" height="100" border="0" /><img src="' + PDF_EXAMPLE_LOGO+ '" alt="test alt attribute" width="100" height="100" border="0" />
<img src="' + PDF_EXAMPLE_LOGO + '" alt="test alt attribute" width="100" height="100" border="0" /><img src="' + PDF_SVG_TEST_TUX + '" alt="test alt attribute" width="100" height="100" border="0" /><img src="' + PDF_EXAMPLE_LOGO+ '" alt="test alt attribute" width="100" height="100" border="0" />
</div>'

# output the HTML content
Expand Down
8 changes: 4 additions & 4 deletions example/rails/app/controllers/example012_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def index
style = {'width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '10,20,5,10', 'phase' => 10, 'color' => [255, 0, 0]}
style2 = {'width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => [255, 0, 0]}
style3 = {'width' => 1, 'cap' => 'round', 'join' => 'round', 'dash' => '2,10', 'color' => [255, 0, 0]}
style4 = {'L' => 0,
style4 = {'L' => nil,
'T' => {'width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => '20,10', 'phase' => 10, 'color' => [100, 100, 255]},
'R' => {'width' => 0.50, 'cap' => 'round', 'join' => 'miter', 'dash' => 0, 'color' => [50, 50, 127]},
'B' => {'width' => 0.75, 'cap' => 'square', 'join' => 'miter', 'dash' => '30,10,5,10'}}
Expand Down Expand Up @@ -107,7 +107,7 @@ def index

# Polygonal Line
pdf.set_line_style({'width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => [0, 0, 164]})
pdf.poly_line([80,165,90,160,100,165,110,160,120,165,130,160,140,165], 'D', nil, nil)
pdf.poly_line([80,165,90,160,100,165,110,160,120,165,130,160,140,165], 'D')

# Regular polygon
pdf.text(5, 169, 'Regular polygon examples')
Expand All @@ -124,8 +124,8 @@ def index
pdf.set_line_style(style5)
pdf.star_polygon(20, 230, 15, 20, 3, 0, 1, 'F')
pdf.star_polygon(55, 230, 15, 12, 5)
pdf.star_polygon(55, 230, 7, 12, 5, 45, 0, 'DF', {'all' => style7}, [220, 220, 200], 'F', [255, 200, 200])
pdf.star_polygon(90, 230, 15, 20, 6, 0, 1, 'DF', {'all' => style5}, [220, 220, 200], 'F', [255, 200, 200])
pdf.star_polygon(55, 230, 7, 12, 5, 45, 0, 'DF', {'all' => style7}, [220, 220, 200], 'F', nil, [255, 200, 100])
pdf.star_polygon(90, 230, 15, 20, 6, 0, 1, 'DF', {'all' => style5}, [220, 220, 200], 'F', nil, [255, 200, 100])
pdf.star_polygon(125, 230, 15, 5, 2, 30, 1, nil, {'all' => style5}, nil, nil, style6)
pdf.star_polygon(160, 230, 15, 10, 3)
pdf.star_polygon(160, 230, 7, 50, 26)
Expand Down
2 changes: 1 addition & 1 deletion example/rails/app/controllers/example039_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def index
pdf.write(0, 'Example of HTML Justification', '', 0, 'L', true, 0, false, false, 0)

# create some HTML content
html = '<span style="text-align:justify;">a <u>abc</u> abcdefghijkl abcdef abcdefg <b>abcdefghi</b> a abc abcd <img src="' + PDF_EXAMPLE_LOGO + '" border="0" height="41" width="41" /> <img src="' + PDF_TIGER_AI + '" alt="test alt attribute" width="100" height="100" border="0" /> abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg <b>abcdefghi</b> a <u>abc</u> abcd abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg abcdefghi a abc abcd <a href="https://github.com/naitoh/rbpdf">abcdef abcdefg</a> start a abc before <span style="background-color:yellow">yellow color</span> after a abc abcd abcdef abcdefg abcdefghi a abc abcd end abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi<br />abcd abcdef abcdefg abcdefghi<br />abcd abcde abcdef</span>'
html = '<span style="text-align:justify;">a <u>abc</u> abcdefghijkl abcdef abcdefg <b>abcdefghi</b> a abc abcd <img src="' + PDF_EXAMPLE_LOGO + '" border="0" height="41" width="41" /> <img src="' + PDF_SVG_TEST_TUX + '" alt="test alt attribute" width="100" height="100" border="0" /> abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg <b>abcdefghi</b> a <u>abc</u> abcd abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg <b>abcdefghi</b> a abc abcd abcdef abcdefg abcdefghi a abc abcd <a href="https://github.com/naitoh/rbpdf">abcdef abcdefg</a> start a abc before <span style="background-color:yellow">yellow color</span> after a abc abcd abcdef abcdefg abcdefghi a abc abcd end abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi a abc abcd abcdef abcdefg abcdefghi<br />abcd abcdef abcdefg abcdefghi<br />abcd abcde abcdef</span>'

# set core font
pdf.set_font('helvetica', '', 10)
Expand Down
80 changes: 80 additions & 0 deletions example/rails/app/controllers/example058_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# coding: UTF-8
#============================================================+
# Begin : 2010-04-22
# Last Update : 2010-05-20
#
# Description : Example 058 for RBPDF class
# SVG Image
#
# Author: Jun NAITOH
# License: LGPL 2.1 or later
#============================================================+

require("example_common.rb")

class Example058Controller < ApplicationController
def index
# create new PDF document
pdf = RBPDF.new(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false)

# set document information
pdf.set_creator(PDF_CREATOR)
pdf.set_author(PDF_AUTHOR)
pdf.set_title('RBPDF Example 058')
pdf.set_subject('RBPDF Tutorial')
pdf.set_keywords('RBPDF, PDF, example, test, guide')

# set default header data
pdf.set_header_data(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE + ' 058', PDF_HEADER_STRING)

# set header and footer fonts
pdf.set_header_font([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN])
pdf.set_footer_font([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA])

# set default monospaced font
pdf.set_default_monospaced_font(PDF_FONT_MONOSPACED)

# set margins
pdf.set_margins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT)
pdf.set_header_margin(PDF_MARGIN_HEADER)
pdf.set_footer_margin(PDF_MARGIN_FOOTER)

# set auto page breaks
pdf.set_auto_page_break(true, PDF_MARGIN_BOTTOM)

# set image scale factor
pdf.set_image_scale(PDF_IMAGE_SCALE_RATIO)

# set some language-dependent strings
pdf.set_language_array($l)

# ---------------------------------------------------------

# set font
pdf.set_font('helvetica', '', 20)

# add a page
pdf.add_page()

# NOTE: Uncomment the following line to rasterize SVG image using the ImageMagick library.
# pdf.setRasterizeVectorImages(true);

pdf.image_svg(PDF_SVG_TEST_TESTSVG, 15, 30, 0, 0, 'https://github.com/naitoh/rbpdf', '', '', 1, false)

pdf.image_svg(PDF_SVG_TEST_TUX, 30, 100, 0, 100, '', '', '', 0, false)

pdf.set_font('helvetica', '', 8)
pdf.set_y(195)
txt = '© The copyright holder of the above Tux image is Larry Ewing, allows anyone to use it for any purpose, provided that the copyright holder is properly attributed. Redistribution, derivative work, commercial use, and all other use is permitted.'
pdf.write(0, txt, '', 0, 'L', true, 0, false, false, 0)

# ---------------------------------------------------------

# Close and output PDF document
send_data pdf.output(), :type => "application/pdf", :disposition => "inline"
end
end

#============================================================+
# END OF FILE
#============================================================+
3 changes: 2 additions & 1 deletion example/rails/app/controllers/example_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
PDF_IMAGE_DEMO_WEBP="#{PUBLIC}/image_demo.webp"
PDF_UTF8TEST_TXT="#{PUBLIC}/utf8test.txt"
PDF_TABLE_DATA_DEMO_TXT="#{PUBLIC}/table_data_demo.txt"
PDF_TIGER_AI="#{PUBLIC}/tiger.ai"
PDF_PNG_TEST_ALPHA_PNG="#{PUBLIC}/png_test_alpha.png"
PDF_PNG_TEST_MSK_ALPHA_PNG="#{PUBLIC}/png_test_msk_alpha.png"
PDF_PNG_TEST_NON_ALPHA_PNG="#{PUBLIC}/png_test_non_alpha.png"
PDF_GIF_TEST_MSK_ALPHA_PNG="#{PUBLIC}/gif_test_msk_alpha.png"
PDF_GIF_TEST_NON_ALPHA_PNG="#{PUBLIC}/gif_test_non_alpha.png"
PDF_GIF_TEST_ALPHA_GIF="#{PUBLIC}/gif_test_alpha.gif"
PDF_WEBP_TEST_ALPHA_PNG="#{PUBLIC}/webp_test_alpha.webp"
PDF_SVG_TEST_TESTSVG="#{PUBLIC}/testsvg.svg"
PDF_SVG_TEST_TUX="#{PUBLIC}/tux.svg"

if !defined? send_data
def send_data(data, options = {})
Expand Down
Loading