Once you have saved the script: custom_page_layout.rb
, you can pass it to the asciidoctor-pdf command to generate the PDF with custom page layouts.
Run the following command:
asciidoctor-pdf -r ./custom_page_layout.rb my_document.adoc
require 'asciidoctor-pdf' | |
class CustomPdfConverter < Asciidoctor::PDF::Converter | |
register_for 'pdf' | |
# Customize the title page layout | |
def layout_title_page(doc) | |
start_new_page | |
font 'Helvetica', size: 48, style: :bold | |
text doc.doctitle, align: :center, valign: :center | |
move_down 30 | |
font 'Helvetica', size: 20 | |
text doc.attr('author', 'Anonymous'), align: :center | |
move_down 10 | |
text doc.attr('revdate', Time.now.strftime('%Y-%m-%d')), align: :center | |
move_down 20 | |
text "Custom Title Page", align: :center | |
end | |
# Customize the part-title layout | |
def layout_part_title(part) | |
start_new_page | |
font 'Helvetica', size: 36, style: :bold | |
text part.title, align: :center, valign: :center | |
move_down 50 | |
font 'Helvetica', size: 24 | |
text "Part #{part.number}", align: :center | |
start_new_page | |
end | |
# Customize the chapter-title layout | |
def layout_chapter_title(chapter, opts = {}) | |
# Start new chapter page | |
start_new_page unless at_page_top? | |
move_down 200 if chapter.number == 1 # Add top padding for the first chapter | |
# Set the custom title for the chapter | |
font 'Helvetica', size: 32, style: :bold | |
text chapter.title, align: :center | |
# Optional: Customize chapter number display | |
move_down 20 | |
font 'Helvetica', size: 18, style: :italic | |
text "Chapter #{chapter.number}", align: :center | |
# Start new page after title if necessary | |
start_new_page | |
end | |
end |
Once you have saved the script: custom_page_layout.rb
, you can pass it to the asciidoctor-pdf command to generate the PDF with custom page layouts.
Run the following command:
asciidoctor-pdf -r ./custom_page_layout.rb my_document.adoc