Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create a presentation with PageSize on Google Slides API

I'm trying to create a new 4:3 presentation, not 16:9.

I read this reference and write some ruby codes, but it didn't work. The new presentation's height is different from what I specified.

Method: presentations.create  |  Slides API  |  Google Developers

# foo.rb
require 'google/apis/slides_v1'
Slide = Google::Apis::SlidesV1 # alias
slides_service = Slide::SlidesService.new
# authorize...
new_presentation_object = Slide::Presentation.new(
  title: "test",
  page_size: Slide::Size.new(
    width:  Slide::Dimension.new(magnitude: 6_858_000, unit: 'EMU'),
    height: Slide::Dimension.new(magnitude: 9_141_000, unit: 'EMU')
  )
)
presentation = slide_service.create_presentation(new_presentation_object, fields: "pageSize,presentationId")
presentation.page_size
# => #<Google::Apis::SlidesV1::Size:0x007f99ef1fb630
#  @height=#<Google::Apis::SlidesV1::Dimension:0x007f99ef1f8278 @magnitude=5143500, @unit="EMU">,
#  @width=#<Google::Apis::SlidesV1::Dimension:0x007f99ef1fa550 @magnitude=9144000, @unit="EMU">>

How do I create a new 4:3 presentation?
I found no API to change PageSize but CreatePresentation, but any ideas to change PageSize are welcome.

like image 476
hkdnet Avatar asked Oct 17 '22 18:10

hkdnet


1 Answers

I found a workaround for this problem.

  1. Create a new presentation. We use this as a template.
  2. Change PageSize as you like. See: Change the size of your slides - Docs editors Help
  3. Copy the presentation via Google Drive API. See: Files: copy  |  Drive REST API  |  Google Developers

Then, we get a new presentation. Though we can't decide PageSize dynamically, this works fine for me.

like image 91
hkdnet Avatar answered Oct 21 '22 06:10

hkdnet