Git Product home page Git Product logo

Comments (2)

JasonBarnabe avatar JasonBarnabe commented on June 10, 2024 3

I'm adding images to PDFs with no problems other than this one. Those 300s really do represent the image's dimensions.

require 'origami'
include Origami

def add_kitty(cm_with_size)

  pdf = PDF.read('pdf-sample.pdf')
  page = pdf.get_page(1)

  img = Graphics::ImageXObject.from_image_file('1327.jpeg', 'jpg')
  img.Width  = 500
  img.Height = 422
  img.ColorSpace = Origami::Graphics::Color::Space::DEVICE_RGB
  img.BitsPerComponent = 8
  img.Interpolate = false
  page.add_xobject(img, :kitty)

  contents = Origami::ContentStream.new

  # Reimplementation of ContentStream#draw_image
  contents.instructions << PDF::Instruction.new('q')
  if cm_with_size
    contents.instructions << PDF::Instruction.new('cm', img.Width, 0, 0, img.Height, 0, 0)
  else
    contents.instructions << PDF::Instruction.new('cm', 300, 0, 0, 300, 0, 0)
  end
  contents.instructions << PDF::Instruction.new('Do', :kitty)
  contents.instructions << PDF::Instruction.new('Q')

  page.setContents([page.Contents, contents])

  pdf.save("pdf-with-kitty-#{cm_with_size ? 'cm_with_size' : 'cm_default'}.pdf")
end

add_kitty(true)
add_kitty(false)

Inputs:

1327
pdf-sample.pdf

Outputs:

pdf-with-kitty-cm_default.pdf
pdf-with-kitty-cm_with_size.pdf

from origami.

gdelugre avatar gdelugre commented on June 10, 2024

Actually those are just dummy values in the transformation matrix, they do not mean anything.

The support for drawing images in Origami is very limited. I don't think this is going to work with this code, there is no support of colorimetric spaces, image attributes and so on. I should probably just have raised a NotImplementedError.

from origami.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.