Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupdocs-cloud-gists/7d74f35d66764d9b889668f79f77ed59 to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/7d74f35d66764d9b889668f79f77ed59 to your computer and use it in GitHub Desktop.
Convert Excel Spreadsheets to PDF using Ruby
#XLSX to PDF Conversion with Watermark using Ruby
# Create necessary API instances
@apiInstance = GroupDocsConversionCloud::ConvertApi.from_keys(@app_sid, @app_key)
# Prepare convert settings
@watermark = GroupDocsConversionCloud::WatermarkOptions.new
@watermark.text = "CONFIDENTIAL"
@watermark.color = "Red"
@watermark.width = 100
@watermark.height = 100
@watermark.background = false
@watermark.bold = true;
@watermark.top = 300;
@watermark.left = 200;
@settings = GroupDocsConversionCloud::ConvertSettings.new
@settings.file_path = "xlsx-to-pdf/four-pages.xlsx"
@settings.format = "pdf"
@convertOptions = GroupDocsConversionCloud::PdfConvertOptions.new
@convertOptions.watermark_options = @watermark
@settings.convert_options = @convertOptions
@settings.output_path = "xlsx-to-pdf"
# Convert
result = @apiInstance.convert_document(GroupDocsConversionCloud::ConvertDocumentRequest.new(@settings))
puts("Spreadsheet successfully converted to PDF with Watermark")
# Create Conversion API instance
@apiInstance = GroupDocsConversionCloud::ConvertApi.from_keys(@app_sid, @app_key)
# Initialize and set convert settings
@settings = GroupDocsConversionCloud::ConvertSettings.new
@settings.file_path = "xlsx-to-pdf/four-pages.xlsx"
@settings.format = "pdf"
# Set Spreadsheet Conversion LoadOptions
@loadOptions = GroupDocsConversionCloud::SpreadsheetLoadOptions.new
@loadOptions.hide_comments = true
@loadOptions.one_page_per_sheet = true
@settings.load_options = @loadOptions
@settings.output_path = "xlsx-to-pdf"
# Convert XLSX to PDF
result = @apiInstance.convert_document(GroupDocsConversionCloud::ConvertDocumentRequest.new(@settings))
puts("Spreadsheet successfully converted to PDF")
# Convert Specific Pages of XLSX to PDF in Ruby
# Create necessary API instances
@apiInstance = GroupDocsConversionCloud::ConvertApi.from_keys(@app_sid, @app_key)
# Set convert settings
@settings = GroupDocsConversionCloud::ConvertSettings.new
@settings.file_path = "xlsx-to-pdf/four-pages.xlsx"
@settings.format = "pdf"
@convertOptions = GroupDocsConversionCloud::PdfConvertOptions.new
@convertOptions.pages = [1, 3]
@settings.convert_options = @convertOptions
@settings.output_path = "xlsx-to-pdf"
# Convert specific pages to PDF
@result = @apiInstance.convert_document(GroupDocsConversionCloud::ConvertDocumentRequest.new(@settings))
puts("Spreadsheet pages successfully converted to PDF")

You can easily convert Excel spreadsheets to PDF documents programmatically on the cloud. In this article, you will learn how to convert Excel spreadsheets to PDF using REST API in Ruby.

The following topics are covered in this article:

  1. Excel to PDF Conversion REST API and Ruby SDK
  2. Convert Excel to PDF using a REST API in Ruby
  3. Convert Specific Excel Spreadsheets to PDF in Ruby
  4. Excel to PDF Conversion in Ruby using Advanced Options
  5. Convert Excel to PDF and Add Watermark
  6. Online XLSX to PDF Converter for Free
# Load the gem in your ruby application for http://api.groupdocs.cloud
require 'groupdocs_conversion_cloud'
# Get your client_id and client_secret from https://dashboard.groupdocs.cloud after free registration.
@app_sid = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
@app_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Create Conversion API instance
@apiInstance = GroupDocsConversionCloud::ConvertApi.from_keys(@app_sid, @app_key)
# Initialize and set convert settings
@settings = GroupDocsConversionCloud::ConvertSettings.new
@settings.file_path = "xlsx-to-pdf/four-pages.xlsx"
@settings.format = "pdf"
# Set Spreadsheet Conversion LoadOptions
@loadOptions = GroupDocsConversionCloud::SpreadsheetLoadOptions.new
@loadOptions.hide_comments = true
@loadOptions.one_page_per_sheet = true
@convertOptions = GroupDocsConversionCloud::PdfConvertOptions.new
@convertOptions.center_window = true
@convertOptions.compress_images = false
@convertOptions.display_doc_title = true
@convertOptions.dpi = 1024.0
@convertOptions.fit_window = false
@convertOptions.from_page = 1
@convertOptions.grayscale = false
@convertOptions.image_quality = 100
@convertOptions.linearize = false
@convertOptions.margin_top = 5
@convertOptions.margin_left = 5
@convertOptions.password = "password"
@convertOptions.unembed_fonts = true
@convertOptions.remove_unused_streams = true
@convertOptions.remove_unused_objects = true
@convertOptions.remove_pdfa_compliance = false
@settings.load_options = @loadOptions
@settings.convert_options = @convertOptions
@settings.output_path = "xlsx-to-pdf"
# Convert XLSX to PDF
result = @apiInstance.convert_document(GroupDocsConversionCloud::ConvertDocumentRequest.new(@settings))
puts("XLSX converted to PDF using advance options")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment