Does the PDF exporter even accept settings?

I’m struggling with exporting a PDF of the current view to a defined physical size. According to the API docs Model#export should accept a hash with settings, but no settings I provide appear to make any difference. Instead the values from when I last exported a PDF using the UI are used. Does anyone know if the PDF exporter even supports this?

settings_hash = {
  match_screen_profiles: false,
  line_width: 40,
  height_units: Length::Millimeter,
  window_height: 100
}
path = UI.savepanel("Export PDF")
path = "#{path}.pdf" unless path.end_with?(".pdf")
Sketchup.active_model.export(
  path,
  settings_hash
)

It seems the exporter does accept some options, but only some and only if the exact right data types are used. And all errors are silently swallowed -_- .

height_units as Length::Millimeter is ignored but Length::Inches appears to be supported. window_height as integer is ignored but float seems to be supported.

It would be much appreciated if someone could try this on Mac as it uses a different PDF exporter.

# PDF export on Mac.
settings_hash = {
  imageHeight: 200.mm.to_f#, # Taking dimensions in inches?
  #imageWidth: 200.mm.to_f # Using viewport aspect ratio when no width is provided?
}
path = UI.savepanel("Export PDF")
path = "#{path}.pdf" unless path.end_with?(".pdf")
Sketchup.active_model.export(
  path,
  settings_hash
)

Does this export a PDF that is 200 mm high? Does the aspect ratio match the SketchUp viewport when no explicit width is provided?

it exported a PDF that Inkscape reports as 324.4mm w x 243.4mm h. The aspect ratio does appear to match the SketchUp view window it captured.

enetest.pdf (37.5 KB)

1 Like

this julia_test.pdf (8.7 KB) doesn’t show any content at all in the default ‘Preview.app’ but reports extremely large page size and locks the system if you try to resize it…

the second is fan_effects_large.pdf (8.8 KB) a standard export of the same model view…

john

1 Like

(Thinking out loud.) Rather than using a literal hash, try using named arguments and Ruby will collect them into a hash automatically. Also be sure to set the model units (as the docs say that it defaults to feet [which is dumb, it should default to the model’s units.])

path = UI.savepanel("Export PDF")
path = "#{path}.pdf" unless path.end_with?(".pdf")
Sketchup.active_model.export(
  path,
  match_screen_profiles: false,
  line_width: 40,
  height_units: Length::Millimeter,
  window_height: 100,
  model_units: model_units()
)
def model_units()
  opts = Sketchup.active_model.options["UnitsOptions"]
  fmt = opts["LengthFormat"]
  case fmt
  when 0 # Decimal
    unit = opts["LengthUnit"]
    case unit
    when 0 # Inches
      Length::Inches
    when 1 # Feet
      Length::Feet
    when 2 # mm
      Length::Millimeter
    when 3 # cm
      Length::Centimeter
    when 4 # m
      Length::Meter
    end
  when 1 # Architectural
    Length::Inches
  when 2 # Engineering
    Length::Feet
  when 3 # Fractional
    Length::Inches
  end
end ###

This is what I usually do but since the API docs usually use hashes I thought I could give that a try too (and it was also convenient for setting up different settings depending on OS). Turned out the exported did accept the parameters, but not if the height was an integer.

Regarding the Mac exporter, I’m very confused what unit it uses. Could someone try exporting two PDFs with different heights passed, just to see if the value is being used at all?

Here is some code if anyone on Mac wants to test. You may want to locate a new empty folder to easier clean up the files it exports.

dir = UI.select_directory
Sketchup.active_model.export(
  "#{dir}/pdf size test 1.pdf",
  imageHeight: 1
)
Sketchup.active_model.export(
  "#{dir}/pdf size test 1.0.pdf",
  imageHeight: 1.0
)
Sketchup.active_model.export(
  "#{dir}/pdf size test 10.pdf",
  imageHeight: 10
)
Sketchup.active_model.export(
  "#{dir}/pdf size test 10.0.pdf",
  imageHeight: 10.0
)

It would be interesting to know if there is a size different at all, and what size the PDFs have.

all same…

john

1 Like

Thanks! I’ll go fill a bug report for this.

Edit: Logged https://github.com/SketchUp/api-issue-tracker/issues/403

2 Likes

There are errors in the documentation for PDF export on Mac.
The options linked to pdf export are named:
image_height (not imageHeight)
image_width (not imageWidth)
line_weight
of those options only image_weight is having an effect on files in my initial testing. I’ll continue to investigate and will get the documentation updated.

3 Likes

But “image_weight” is not one of those options. :wink:

oops late at,
night image_width

I want an option for image_weight :smiley: ! Are you afraid of your laptop being stolen? Just create an image with a weight of 100 kg and no one can carry it until you delete the file :3 .

1 Like

Yea, I could use a scale to look at images…

1 Like

Then we’d have scaled PDFs!

On a Mac, I’ve preferred to use the print dialog and save as pdf instead of the native pdf exporter as posted here. Page setup effects the result: paper size, paper scale and line weight factor in 2019. A better exporter would probably still be welcome though.