%
doc_title = "test title";
doc_subject = "test description";
doc_keywords = "test keywords";
htmlcontent = "< € € € & è è © >
heading 1
heading 2
heading 3
heading 4
heading 5
heading 6
ordered list:
- bold text
- italic text
- underlined text
- link to http://www.tecnick.com
- test break
second line
third line - font + 3
- small text
- normal subscript superscript
table:
# | A | B |
---|
1 | A1 | B1 |
---|
2 | A2 € € € & è è | B2 |
---|
3 | A3 | B3 |
---|
image:
";
# ENGLISH
@l = {}
# PAGE META DESCRIPTORS --------------------------------------
@l['a_meta_charset'] = "UTF-8";
@l['a_meta_dir'] = "ltr";
@l['a_meta_language'] = "en";
# TRANSLATIONS --------------------------------------
@l['w_page'] = "page";
# create new PDF document (document units are set by default to millimeters)
pdf = TCPDF.new
# set document information
pdf.SetCreator("TCPDF");
pdf.SetAuthor("TCPDF");
pdf.SetTitle(doc_title);
pdf.SetSubject(doc_subject);
pdf.SetKeywords(doc_keywords);
pdf.SetHeaderData("#{File.join(RAILS_ROOT, 'public')}/logo_example.png", 20, "header title", "first row\nsecond row\nthird row");
#set margins
pdf.SetMargins(15, 27, 15);
#set auto page breaks
pdf.SetAutoPageBreak(true, 25);
pdf.SetPrintHeader
pdf.SetPrintFooter
pdf.SetHeaderMargin(5);
pdf.SetFooterMargin(10);
pdf.SetImageScale(4); #set image scale factor
pdf.SetHeaderFont(["FreeSans", '', 10]);
pdf.SetFooterFont(["FreeSans", '', 8]);
pdf.SetLanguageArray(@l); #set language items
#initialize document
pdf.alias_nb_pages();
pdf.AddPage();
# output some HTML code
pdf.SetFont("vera", "", 10);
pdf.writeHTML(htmlcontent, true, 0);
# output two html columns
first_column_width = 80;
current_y_position = pdf.GetY();
pdf.writeHTMLCell(first_column_width, 0, 0, current_y_position, "hello", 0, 0, 0);
pdf.writeHTMLCell(0, 0, first_column_width, current_y_position, "world", 0, 1, 0);
# output some content
pdf.SetFont("vera", "BI", 20);
pdf.Cell(0,10,"TEST Bold-Italic Cell",1,1,'C');
# output some UTF-8 test content
pdf.AddPage();
pdf.SetFont("FreeSans", "", 12);
utf8text = open(File.join(RAILS_ROOT, 'vendor/plugins/rfpdf',"utf8test.txt"), "rb").read; # get utf-8 text form file
pdf.SetFillColor(230, 240, 255, true);
pdf.Write(5, utf8text, '', 1);
# remove page header/footer
pdf.SetPrintHeader(false);
pdf.SetPrintFooter(false);
# Two HTML columns test
pdf.AddPage();
right_column = "right column right column right column right column right column
right column right column right column right column right column right column
right column right column right column right column right column right column";
left_column = "left column left column left column left column left column left
column left column left column left column left column left column left column
left column left column left column left column left column left column left
column";
first_column_width = 80;
second_column_width = 80;
column_space = 20;
current_y_position = pdf.GetY();
pdf.writeHTMLCell(first_column_width, 0, 0, 0, left_column, 1, 0, 0);
pdf.Cell(0);
pdf.writeHTMLCell(second_column_width, 0, first_column_width+column_space, current_y_position, right_column, 0, 0, 0);
# add page header/footer
pdf.SetPrintHeader(true);
pdf.SetPrintFooter(true);
pdf.AddPage();
# Multicell test
pdf.MultiCell(40, 5, "A test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0, 0);
pdf.MultiCell(40, 5, "B test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0);
pdf.MultiCell(40, 5, "C test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0, 0);
pdf.MultiCell(40, 5, "D test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0, 2);
pdf.MultiCell(40, 5, "F test multicell line 1\ntest multicell line 2\ntest multicell line 3", 1, 'J', 0);
#Close and output PDF document
%><%=pdf.Output()%>