1. Products
  2.   PDF
  3.   Ruby
  4.   Origami
 
  

Open Source Ruby Library to Generate PDF Processing Apps

Free Ruby PDF API that enables developers to analyze, modify and create malicious PDF files with ease. Encrypt PDF documents using RC4 or AES.

Origami is a pure Ruby library that enables software developers to create powerful apps for handling PDF documents using Ruby commands. The library has provided support for analyzing, modifying, or creating malicious PDF files with ease. Origami can also write your own set of Ruby scripts suited to your needs. The library has provided support for PDF document encryption using RC4 or AES. The library is very fast and memory-efficient intended for auditing PDFs.

Origami is very easy to use and has included several important basic and advanced features related to PDF documents manipulation such as, add a file attachment to a PDF document, create new PDFs, adding JavaScript to a document, PDF file encryption and decryption, create PDF with digital signatures, embedded SWF file to PDF documents, modifying PDFs, editing page raw content, adding styles to PDF, compression filters with predictor functions, PDF annotations support and so on.

.

Previous Next

Getting Started with Origami

To install the Origami on your system, please run the following command.  

Install Origami with ruby gems

 gem install origami

PDF Creation via Ruby Library

The open source Ruby library Origami enables software developers to generate and process PDF documents inside their own applications. Developers can easily create new PDF documents by directly instantiating a new PDF object. It supports several important features such as adding a new page, inserting an image, add flash-object, attach documents to PDF, encrypt PDF documents, and much more. 

PDF File Creation via Ruby Library

pdf = Origami::PDF.new
pdf.append_page
pdf.pages.first.write "Hello", size: 30

pdf.save("example.pdf")

# Another way of doing it

Origami::PDF.write("example.pdf") do |pdf|
  pdf.append_page do |page|
    page.write "Hello", size: 30
  end
end

Embedded Flash SWF File in PDFs

The Origami Ruby library allows software developers to programmatically create a PDF document with an embedded SWF file. While creating a new PDF file you can easily embed a flash asset inside a PDF document. After that, you can also generate a flash annotation on the page and can set the player position on the page. The library also supports add or remove an object to the PDF file, attach an embedded file to the PDF, Exports the document Graphic file, and much more.

PDF File Creation via Ruby Library


  # Embeding a Flash asset inside a PDF document.

  SWF_PATH = File.join(__dir__, "helloworld.swf")
  OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"

  # Creating a new file
  pdf = PDF.new

  # Embedding the SWF file into the PDF.
  swf = pdf.attach_file(SWF_PATH)

  # Creating a Flash annotation on the page.
  pdf.append_page do |page|
    annot = page.add_flash_application(swf,
                    windowed: true,
                    navigation_pane: true,
                    toolbar: true)

    # Setting the player position on the page.
    annot.Rect = Rectangle.new [204, 573, 403, 718]
  end

  pdf.save(OUTPUT_FILE)

  puts "PDF file saved as #{OUTPUT_FILE}."

 Extract Data from PDF via Ruby

The open source Ruby library Origami gives software developers the capability to extract their valuable data from PDF using Ruby commands. The library has provided several important functions that help users to extract decoded streams, JavaScript, file attachments, and more. It supports extracting numerous types of data such as streams, scripts, embedded images, Extracts metadata streams, embedded font files, attachments, and more.

 

 Add New Page & Content to Existing PDF

Working with PDFs is very challenging while using Ruby script. It is often required to add a new page or content to an existing PDF file. The open source Ruby library Origami gives software developers the capability to insert pages at a particular location inside a PDF file and latter can add images, text, or logos to an existing PDF file using a couple of lines of Ruby code.

Adding New Page or Content to PDF File via Ruby


  # Add Content to PDF File via Ruby.

  pdf   = Origami::PDF.read(path)
  contents = Origami::ContentStream.new
  contents.write('some text', {
    x: 200,
    y: 200,
  })
  pdf.get_page(1).setContents([pdf.get_page(1).Contents, contents])
  pdf.save(path)
 
 English