Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6864719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:56:50+00:00 2026-05-27T02:56:50+00:00

I use Rubyvis to generate SVG plots, and then allow the user to save

  • 0

I use Rubyvis to generate SVG plots, and then allow the user to save either to SVG directly, or to some other format using RMagick.

The SVG plots have a set size, which is specified in the SVG file. It seems to me, then, that it should be trivial to convert to a PDF of the same size.

Unfortunately, this appears not to be the case. I can produce a PDF in this manner, but it is much larger (dimension-wise) than the PDFs produced if I first open the SVG in inkscape and then print-to-file as a PDF.

Worse, the PDF image quality is terrible.

Am I missing some instruction for Magick? Here’s the code:

image = Magick::Image::from_blob(svg_string_data) { self.format = 'SVG' }
image[0].format = 'PDF'
image[0].to_blob

I then write the value returned (the PDF blob) directly into a file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:56:51+00:00Added an answer on May 27, 2026 at 2:56 am

    The answer comes to you based on a tip from cptjazz on github.

    First of all, the documentation for RMagick is often wrong. I doubt this is a version problem, because the ImageMagick-hosted docs are v2.12.0, and I’m using v2.13.1. Either way, here is what you need to know.

    The docs claim you can use image[0]['pdf', 'use-cropbox'] = true, since true.to_s yields the String ‘true’. In fact, it needs an explicit string, and the []= method takes only one key, not two.

    I did not experiment with pdf:use-trimbox, mainly because I wanted an option that also works for postscript. For postscript, you should be able to amend it only slightly, and set ps:use-cropbox to ‘true’, but RMagick’s docs are unclear as to how one may properly set the geometry on a PS, PS2, or PS3. (Normally in ImageMagick, one would set the density to ‘300×300’ and the geometry to ‘24%’, supposedly.) And for some reason, PS3-format output files do not scale as well as the PDFs produced by RMagick. But I digress.

    Here is what I used for PDF:

    image = Magick::Image::from_blob(svg_string) { self.format = 'SVG' }
    image[0].format = 'PDF'
    image[0]["use-cropbox"] = 'true'
    image[0].to_blob
    

    And here is what I used for PS:

    image = Magick::Image::from_blob(svg_string) { self.format = 'SVG' }
    page  = image[0].page.dup
    image[0]["use-cropbox"] = 'true'
    image[0].format = 'PS3'
    image[0].density = '100x100'
    image[0].page = page
    image[0].to_blob
    

    For some reason, setting a higher density makes the image smaller. Why that should be is a mystery.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Use: The user searches for a partial postcode such as 'RG20' which should then
Use case: user clicks the link on a webpage - boom! load of files
Use case: I've just entered insert mode, and typed some text. Now I want
Use Case When a user goes to my website, they will be confronted with
use Control::CLI; $cli = new Control::CLI('SSH'); $cli->connect(Host=>'10.10.10.10',Username=>'user',Password=>'pwd'); $cli->waitfor('>'); $cli->print('Show XXXXXXXXXXXXXXXXXXXX| grep Active'); @f=$cli->waitfor('>'); print
Use case: User launches app The user enters google password The app lets the
Use Case: End-User searches for something and an ArrayCollection is returned with Result objects.
use javascript or other method ? have any recommendation?
I use Firebug and the Mozilla JS console heavily, but every now and then
Use MongoDB GridFS store images and images stored directly on disk What are the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.