diff --git a/record-and-playback/core/lib/recordandplayback/generators/presentation.rb b/record-and-playback/core/lib/recordandplayback/generators/presentation.rb index 513191a2645e5c004eeab612469b56a8f66bfaaa..df439046ceb82273324db969f893d450948bba25 100755 --- a/record-and-playback/core/lib/recordandplayback/generators/presentation.rb +++ b/record-and-playback/core/lib/recordandplayback/generators/presentation.rb @@ -57,6 +57,25 @@ module BigBlueButton FileUtils.mv(temp_out,pdf_out) # Process.wait end + + # Extract a page from a pdf file as a png image + def self.extract_png_page_from_pdf(page_num, pdf_presentation, png_out, resize = '800x600') + BigBlueButton.logger.info("Task: Extracting a page from pdf file as png image") + temp_out = "/tmp/#{File.basename(png_out)}" + command = "ghostscript -dSAFER -dBATCH -dNOPAUSE -dQUIET -dFirstPage=#{page_num} -dLastPage=#{page_num} -sDEVICE=png16m -dUseCropBox -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -r300 -sOutputFile=#{temp_out} #{NO_PDF_MARK_WORKAROUND} #{pdf_presentation}" + status = BigBlueButton.execute(command, false) + if status.success? + # Resize to the requested size + command = "convert #{temp_out} -resize #{resize} -quality 90 +dither -depth 8 -colors 256 #{png_out}" + BigBlueButton.execute(command) + else + # If page extraction failed, generate a blank white image at requested size + command = "convert -size #{resize} xc:white -quality 90 +dither -depth 8 -colors 256 #{png_out}" + BigBlueButton.execute(command) + end + ensure + FileUtils.rm_f(temp_out) + end # Convert a pdf page to a png. def self.convert_pdf_to_png(pdf_page, png_out) diff --git a/record-and-playback/presentation/scripts/process/presentation.rb b/record-and-playback/presentation/scripts/process/presentation.rb index c745ad9c7f184a72d347bc3857562e1e2c503c31..a930133ae00ccdc6128315a314ddc528aadbb094 100755 --- a/record-and-playback/presentation/scripts/process/presentation.rb +++ b/record-and-playback/presentation/scripts/process/presentation.rb @@ -84,14 +84,11 @@ if not FileTest.directory?(target_dir) pres_pdf = "#{pres_dir}/#{pres}" end if !File.exists?(pres_pdf) - raise "Could not find pdf file for presentation #{pres}" + BigBlueButton.logger.warning("Could not find pdf file for presentation #{pres}") end 1.upto(num_pages) do |page| - pdf_page = "#{pres_dir}/slide-#{page}.pdf" - BigBlueButton::Presentation.extract_page_from_pdf(page, pres_pdf, pdf_page) - #BigBlueButton::Presentation.convert_pdf_to_png(pdf_page, "#{target_pres_dir}/slide-#{page}.png") - command = "convert -density 300x300 #{pdf_page} -resize 1600x1200 -background white -flatten -quality 90 +dither -depth 8 -colors 256 #{target_pres_dir}/slide-#{page}.png" - BigBlueButton.execute(command) + BigBlueButton::Presentation.extract_png_page_from_pdf( + page, pres_pdf, "#{target_pres_dir}/slide-#{page}.png", '1600x1200') if File.exist?("#{pres_dir}/textfiles/slide-#{page}.txt") then FileUtils.cp("#{pres_dir}/textfiles/slide-#{page}.txt", "#{target_pres_dir}/textfiles") end