Summary
I introduce how to write page border with Asciidoctor
.
There is a feature: Page Border
and Surround header
in Word of Microsoft’s Office.
This converter was made for substitution of their.
Demo
Result looks like below.

Usage
There is usage in repository: Shumpei-Tanaka/AsciiDoc-BorderInMargin.
Script
There is latest in repository: Shumpei-Tanaka/AsciiDoc-BorderInMargin .
write_header_border
is function to write border surround header.
It takes values below from style setting.
- header margin
- herder column ratios
write_mergin_border
is function to write page border in mergin.
It takes margin values from style setting.
class PDFConverterCustomTitlePage < (Asciidoctor::Converter.for 'pdf')
'pdf'
register_for def ink_title_page(doc)
super
line_offset: 5, line_width: 1
write_mergin_border line_offset: 5, line_width: 1
write_header_border end
def ink_running_content(*)
line_offset: 5, line_width: 1
write_mergin_border line_offset: 5, line_width: 1
write_header_border super
end
end
def write_header_border(line_offset:, line_width:)
= page_margin
_m_t, m_r, m_b, m_l = theme.header_height
header_height = theme.header_columns
header_columns = theme.header_margin
mh_t, mh_r, _mh_b, mh_l
= header_columns.delete('^0-9,.').split(',').map(&:to_f)
columns
= columns.sum
o_sum = 0
sum = []
ps .pop
columns.each do |col|
columns+= col
sum << sum
ps end
= ps.map { |col| col / o_sum }
ps
= -(page_height - (mh_t - line_offset) - m_b)
p_t = -(page_height - (mh_t + line_offset) - m_b - header_height)
p_b = -line_offset
p_l = page_width - (m_r - line_offset) - m_l
p_r
= page_width - mh_r - mh_l
t_width
= ps.map do |i|
p_vs * i - m_l + mh_l
t_width end
0
move_cursor_to '000000', line_width: line_width, at: p_t, left_projection: line_offset,
stroke_horizontal_rule right_projection: -line_offset
'000000', line_width: line_width, at: p_b, left_projection: line_offset,
stroke_horizontal_rule right_projection: -line_offset
.each do |p_v|
p_vs-p_b, -p_t, at: p_v)
stroke_vertical_line(end
-p_b, -p_t, at: p_l)
stroke_vertical_line(-p_b, -p_t, at: p_r)
stroke_vertical_line(end
def write_mergin_border(line_offset:, line_width:)
= page_margin
m_t, m_r, m_b, m_l
= -(page_height - (m_t - line_offset) - m_b)
p_t = line_offset
p_b = -line_offset
p_l = page_width - (m_r - line_offset) - m_l
p_r
0
move_cursor_to '000000', line_width: line_width, at: p_t, left_projection: line_offset,
stroke_horizontal_rule right_projection: -line_offset
'000000', line_width: line_width, at: p_b, left_projection: line_offset,
stroke_horizontal_rule right_projection: -line_offset
'000000', line_width: line_width, at: p_l, top_projection: line_offset,
stroke_vertical_rule bottom_projection: line_offset
'000000', line_width: line_width, at: p_r, top_projection: line_offset,
stroke_vertical_rule bottom_projection: line_offset
end
Appendix
Way to set Page Border
and Surround header
in Word of Microsoft’s Office.
How to set Page Border
in Word is below.
- Open
Design
→PageBorders
- Push
Box
- Push
OK

Result is below.

How to set Page Border
in Word is below.
- Open
Design
→PageBorders
- Open
Options...
- Set
Measure from
toText
- Check
Surround header

Result is below.
