Ruby での DOMを使用したHTML文字列の追加

Aspose.PDF - HTML の追加

PDFドキュメントにHTML文字列を追加するには、Aspose.PDF Java for Ruby を使用し、単に AddHtml モジュールを呼び出すだけです。

Ruby コード

# The path to the documents directory.

data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'

# Instantiate Document object

doc = Rjb::import('com.aspose.pdf.Document').new

# Add a page to pages collection of PDF file

page = doc.getPages().add()

# Instantiate HtmlFragment with HTML contents

title = Rjb::import('com.aspose.pdf.HtmlFragment').new("<fontsize=10><b><i>Table</i></b></fontsize>")

# set MarginInfo for margin details

margin = Rjb::import('com.aspose.pdf.MarginInfo').new

margin.setBottom(10)

margin.setTop(200)

# Set margin information

title.setMargin(margin)

# Add HTML Fragment to paragraphs collection of page

page.getParagraphs().add(title)

# Save PDF file

doc.save(data_dir + "html.output.pdf")

puts "HTML added successfully"

実行中のコードのダウンロード

以下に記載されたソーシャルコーディングサイトから Add HTML (Aspose.PDF) をダウンロードしてください。