Class: SelectPdf::HtmlToPdfClient

Inherits:
ApiClient
  • Object
show all
Defined in:
lib/selectpdf.rb

Overview

Html To Pdf Conversion with SelectPdf Online API.

Code sample:

require 'selectpdf'

$stdout.sync = true

print "This is SelectPdf-#{SelectPdf::CLIENT_VERSION}\n"

url = 'https://selectpdf.com'
local_file = 'Test.pdf'
api_key = 'Your API key here'

begin
  client = SelectPdf::HtmlToPdfClient.new(api_key)

  # set parameters - see full list at https://selectpdf.com/html-to-pdf-api/

  client.page_size = SelectPdf::PageSize::A4 # PDF page size
  client.page_orientation = SelectPdf::PageOrientation::PORTRAIT # PDF page orientation
  client.margins = 0 # PDF page margins
  client.rendering_engine = SelectPdf::RenderingEngine::WEBKIT # rendering engine
  client.conversion_delay = 1 # conversion delay
  client.navigation_timeout = 30 # navigation timeout
  client.page_numbers = FALSE # page numbers
  client.page_breaks_enhanced_algorithm = TRUE # enhanced page break algorithm

  # additional properties

  # client.use_css_print = TRUE # enable CSS media print
  # client.disable_javascript = TRUE # disable javascript
  # client.disable_internal_links = TRUE # disable internal links
  # client.disable_external_links = TRUE # disable external links
  # client.keep_images_together = TRUE # keep images together
  # client.scale_images = TRUE # scale images to create smaller pdfs
  # client.single_page_pdf = TRUE # generate a single page PDF
  # client.user_password = 'password' # secure the PDF with a password

  # generate automatic bookmarks

  # client.pdf_bookmarks_selectors = 'H1, H2' # create outlines (bookmarks) for the specified elements
  # client.viewer_page_mode = SelectPdf::PageMode::USE_OUTLINES # display outlines (bookmarks) in viewer

  print "Starting conversion ...\n"

  # convert url to file
  client.convert_url_to_file(url, local_file)

  # convert url to memory
  # pdf = client.convert_url(url)

  # convert html string to file
  # client.convert_html_string_to_file('This is some <b>html</b>.', local_file)

  # convert html string to memory
  # pdf = client.convert_html_string('This is some <b>html</b>.')

  print "Finished! Number of pages: #{client.number_of_pages}.\n"

  # get API usage
  usage_client = SelectPdf::UsageClient.new(api_key)
  usage = usage_client.get_usage(FALSE)
  print("Usage: #{usage}\n")
  print('Conversions remained this month: ', usage['available'], "\n")
rescue SelectPdf::ApiException => e
  print("An error occurred: #{e}")
end

Instance Attribute Summary

Attributes inherited from ApiClient

#api_async_endpoint, #api_endpoint, #api_web_elements_endpoint, #async_calls_max_pings, #async_calls_ping_interval, #number_of_pages

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ HtmlToPdfClient

Construct the Html To Pdf Client.

Parameters:

  • api_key

    API Key.


697
698
699
700
701
# File 'lib/selectpdf.rb', line 697

def initialize(api_key)
  super()
  @api_endpoint = 'https://selectpdf.com/api2/convert/'
  @parameters['key'] = api_key
end

Instance Method Details

#background_color=(background_color) ⇒ Object

Specify the background color of the PDF page in RGB html format. The default is #FFFFFF.

Parameters:

  • background_color

    Background color in #RRGGBB format.


1180
1181
1182
1183
1184
1185
1186
# File 'lib/selectpdf.rb', line 1180

def background_color=(background_color)
  unless /^#?[0-9a-fA-F]{6}$/.match(background_color)
    raise ApiException.new('Color value must be in #RRGGBB format.'), 'Color value must be in #RRGGBB format.'
  end

  @parameters['background_color'] = background_color
end

#conversion_delay=(conversion_delay) ⇒ Object

Introduce a delay (in seconds) before the actual conversion to allow the web page to fully load. This method is an alias for min_load_time. The default value is 1 second. Use a larger value if the web page has content that takes time to render when it is displayed in the browser.

Parameters:

  • conversion_delay

    Delay in seconds.


1139
1140
1141
# File 'lib/selectpdf.rb', line 1139

def conversion_delay=(conversion_delay)
  self.min_load_time = conversion_delay
end

#convert_html_string(html_string) ⇒ Object

Convert the specified HTML string to PDF.

Parameters:

  • html_string

    HTML string with the content being converted.


960
961
962
# File 'lib/selectpdf.rb', line 960

def convert_html_string(html_string)
  convert_html_string_with_base_url(html_string, nil)
end

#convert_html_string_async(html_string) ⇒ Object

Convert the specified HTML string to PDF with an asynchronous call.

Parameters:

  • html_string

    HTML string with the content being converted.


983
984
985
# File 'lib/selectpdf.rb', line 983

def convert_html_string_async(html_string)
  convert_html_string_with_base_url_async(html_string, nil)
end

#convert_html_string_to_file(html_string, file_path) ⇒ Object

Convert the specified HTML string to PDF and writes the resulted PDF to a local file.

Parameters:

  • html_string

    HTML string with the content being converted.

  • file_path

    Local file including path if necessary.


976
977
978
# File 'lib/selectpdf.rb', line 976

def convert_html_string_to_file(html_string, file_path)
  convert_html_string_with_base_url_to_file(html_string, nil, file_path)
end

#convert_html_string_to_file_async(html_string, file_path) ⇒ Object

Convert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to a local file.

Parameters:

  • html_string

    HTML string with the content being converted.

  • file_path

    Local file including path if necessary.


999
1000
1001
# File 'lib/selectpdf.rb', line 999

def convert_html_string_to_file_async(html_string, file_path)
  convert_html_string_with_base_url_to_file_async(html_string, nil, file_path)
end

#convert_html_string_to_stream(html_string, stream) ⇒ Object

Convert the specified HTML string to PDF and writes the resulted PDF to an output stream.

Parameters:

  • html_string

    HTML string with the content being converted.

  • stream

    The output stream where the resulted PDF will be written.


968
969
970
# File 'lib/selectpdf.rb', line 968

def convert_html_string_to_stream(html_string, stream)
  convert_html_string_to_stream_with_base_url(html_string, nil, stream)
end

#convert_html_string_to_stream_async(html_string, stream) ⇒ Object

Convert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to an output stream.

Parameters:

  • html_string

    HTML string with the content being converted.

  • stream

    The output stream where the resulted PDF will be written.


991
992
993
# File 'lib/selectpdf.rb', line 991

def convert_html_string_to_stream_async(html_string, stream)
  convert_html_string_to_stream_with_base_url_async(html_string, nil, stream)
end

#convert_html_string_to_stream_with_base_url(html_string, base_url, stream) ⇒ Object

Convert the specified HTML string to PDF and writes the resulted PDF to an output stream. Use a base url to resolve relative paths to resources.

Parameters:

  • html_string

    HTML string with the content being converted.

  • base_url

    Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.

  • stream

    The output stream where the resulted PDF will be written.


865
866
867
868
869
870
871
872
# File 'lib/selectpdf.rb', line 865

def convert_html_string_to_stream_with_base_url(html_string, base_url, stream)
  @parameters.delete('url')
  @parameters['async'] = 'False'
  @parameters['html'] = html_string
  @parameters['base_url'] = base_url unless base_url.nil? || base_url.empty?

  perform_post(stream)
end

#convert_html_string_to_stream_with_base_url_async(html_string, base_url, stream) ⇒ Object

Convert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to an output stream. Use a base url to resolve relative paths to resources.

Parameters:

  • html_string

    HTML string with the content being converted.

  • base_url

    Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.

  • stream

    The output stream where the resulted PDF will be written.


937
938
939
940
# File 'lib/selectpdf.rb', line 937

def convert_html_string_to_stream_with_base_url_async(html_string, base_url, stream)
  result = convert_html_string_with_base_url_async(html_string, base_url)
  stream.write(result)
end

#convert_html_string_with_base_url(html_string, base_url) ⇒ Object

Convert the specified HTML string to PDF. Use a base url to resolve relative paths to resources.

Parameters:

  • html_string

    HTML string with the content being converted.

  • base_url

    Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.


851
852
853
854
855
856
857
858
# File 'lib/selectpdf.rb', line 851

def convert_html_string_with_base_url(html_string, base_url)
  @parameters.delete('url')
  @parameters['async'] = 'False'
  @parameters['html'] = html_string
  @parameters['base_url'] = base_url unless base_url.nil? || base_url.empty?

  perform_post
end

#convert_html_string_with_base_url_async(html_string, base_url) ⇒ Object

Convert the specified HTML string to PDF with an asynchronous call. Use a base url to resolve relative paths to resources.

Parameters:

  • html_string

    HTML string with the content being converted.

  • base_url

    Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.

Raises:

  • (ApiException.new('Asynchronous call did not finish in expected timeframe.'))

899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
# File 'lib/selectpdf.rb', line 899

def convert_html_string_with_base_url_async(html_string, base_url)
  @parameters.delete('url')
  @parameters['html'] = html_string
  @parameters['base_url'] = base_url unless base_url.nil? || base_url.empty?

  job_id = start_async_job

  if job_id.nil? || job_id.empty?
    raise ApiException.new('An error occurred launching the asynchronous call.'), 'An error occurred launching the asynchronous call.'
  end

  no_pings = 0

  while no_pings < @async_calls_max_pings
    no_pings += 1

    # sleep for a few seconds before next ping
    sleep(@async_calls_ping_interval)

    async_job_client = AsyncJobClient.new(@parameters['key'], @job_id)
    async_job_client.api_endpoint = @api_async_endpoint

    result = async_job_client.result

    next if result.nil?

    @number_of_pages = async_job_client.number_of_pages
    return result
  end

  raise ApiException.new('Asynchronous call did not finish in expected timeframe.'), 'Asynchronous call did not finish in expected timeframe.'
end

#convert_html_string_with_base_url_to_file(html_string, base_url, file_path) ⇒ Object

Convert the specified HTML string to PDF and writes the resulted PDF to a local file. Use a base url to resolve relative paths to resources.

Parameters:

  • html_string

    HTML string with the content being converted.

  • base_url

    Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.

  • file_path

    Local file including path if necessary.


879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
# File 'lib/selectpdf.rb', line 879

def convert_html_string_with_base_url_to_file(html_string, base_url, file_path)
  @parameters.delete('url')
  @parameters['async'] = 'False'
  @parameters['html'] = html_string
  @parameters['base_url'] = base_url unless base_url.nil? || base_url.empty?

  begin
    File.open(file_path, 'wb') do |file|
      perform_post(file)
    end
  rescue ApiException
    FileUtils.rm(file_path) if File.exist?(file_path)
    raise
  end
end

#convert_html_string_with_base_url_to_file_async(html_string, base_url, file_path) ⇒ Object

Convert the specified HTML string to PDF with an asynchronous call and writes the resulted PDF to a local file. Use a base url to resolve relative paths to resources.

Parameters:

  • html_string

    HTML string with the content being converted.

  • base_url

    Base url used to resolve relative paths to resources (css, images, javascript, etc). Must be a http:// or https:// publicly available url.

  • file_path

    Local file including path if necessary.


947
948
949
950
951
952
953
954
955
# File 'lib/selectpdf.rb', line 947

def convert_html_string_with_base_url_to_file_async(html_string, base_url, file_path)
  result = convert_html_string_with_base_url_async(html_string, base_url)
  File.open(file_path, 'wb') do |file|
    file.write(result)
  end
rescue ApiException
  FileUtils.rm(file_path) if File.exist?(file_path)
  raise
end

#convert_url(url) ⇒ Object

Convert the specified url to PDF. SelectPdf online API can convert http:// and https:// publicly available urls.

Parameters:

  • url

    Address of the web page being converted.

Returns:

  • The resulted pdf.


708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
# File 'lib/selectpdf.rb', line 708

def convert_url(url)
  if !url.downcase.start_with?('http://') && !url.downcase.start_with?('https://')
    raise ApiException.new('The supported protocols for the converted webpage are http:// and https://.'), 'The supported protocols for the converted webpage are http:// and https://.'
  end

  if url.downcase.start_with?('http://localhost')
    raise ApiException.new('Cannot convert local urls. SelectPdf online API can only convert publicly available urls.'), 'Cannot convert local urls. SelectPdf online API can only convert publicly available urls.'
  end

  @parameters['url'] = url
  @parameters.delete('html')
  @parameters.delete('base_url')
  @parameters['async'] = 'False'

  perform_post
end

#convert_url_async(url) ⇒ Object

Convert the specified url to PDF using an asynchronous call. SelectPdf online API can convert http:// and https:// publicly available urls.

Parameters:

  • url

    Address of the web page being converted.

Returns:

  • The resulted pdf.

Raises:

  • (ApiException.new('Asynchronous call did not finish in expected timeframe.'))

781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
# File 'lib/selectpdf.rb', line 781

def convert_url_async(url)
  if !url.downcase.start_with?('http://') && !url.downcase.start_with?('https://')
    raise ApiException.new('The supported protocols for the converted webpage are http:// and https://.'), 'The supported protocols for the converted webpage are http:// and https://.'
  end

  if url.downcase.start_with?('http://localhost')
    raise ApiException.new('Cannot convert local urls. SelectPdf online API can only convert publicly available urls.'), 'Cannot convert local urls. SelectPdf online API can only convert publicly available urls.'
  end

  @parameters['url'] = url
  @parameters.delete('html')
  @parameters.delete('base_url')

  job_id = start_async_job

  if job_id.nil? || job_id.empty?
    raise ApiException.new('An error occurred launching the asynchronous call.'), 'An error occurred launching the asynchronous call.'
  end

  no_pings = 0

  while no_pings < @async_calls_max_pings
    no_pings += 1

    # sleep for a few seconds before next ping
    sleep(@async_calls_ping_interval)

    async_job_client = AsyncJobClient.new(@parameters['key'], @job_id)
    async_job_client.api_endpoint = @api_async_endpoint

    result = async_job_client.result

    next if result.nil?

    @number_of_pages = async_job_client.number_of_pages
    return result
  end

  raise ApiException.new('Asynchronous call did not finish in expected timeframe.'), 'Asynchronous call did not finish in expected timeframe.'
end

#convert_url_to_file(url, file_path) ⇒ Object

Convert the specified url to PDF and writes the resulted PDF to a local file. SelectPdf online API can convert http:// and https:// publicly available urls.

Parameters:

  • url

    Address of the web page being converted.

  • file_path

    Local file including path if necessary.


752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
# File 'lib/selectpdf.rb', line 752

def convert_url_to_file(url, file_path)
  if !url.downcase.start_with?('http://') && !url.downcase.start_with?('https://')
    raise ApiException.new('The supported protocols for the converted webpage are http:// and https://.'), 'The supported protocols for the converted webpage are http:// and https://.'
  end

  if url.downcase.start_with?('http://localhost')
    raise ApiException.new('Cannot convert local urls. SelectPdf online API can only convert publicly available urls.'), 'Cannot convert local urls. SelectPdf online API can only convert publicly available urls.'
  end

  @parameters['url'] = url
  @parameters.delete('html')
  @parameters.delete('base_url')
  @parameters['async'] = 'False'

  begin
    File.open(file_path, 'wb') do |file|
      perform_post(file)
    end
  rescue ApiException
    FileUtils.rm(file_path) if File.exist?(file_path)
    raise
  end
end

#convert_url_to_file_async(url, file_path) ⇒ Object

Convert the specified url to PDF using an asynchronous call and writes the resulted PDF to a local file. SelectPdf online API can convert http:// and https:// publicly available urls.

Parameters:

  • url

    Address of the web page being converted.

  • file_path

    Local file including path if necessary.


837
838
839
840
841
842
843
844
845
# File 'lib/selectpdf.rb', line 837

def convert_url_to_file_async(url, file_path)
  result = convert_url_async(url)
  File.open(file_path, 'wb') do |file|
    file.write(result)
  end
rescue ApiException
  FileUtils.rm(file_path) if File.exist?(file_path)
  raise
end

#convert_url_to_stream(url, stream) ⇒ Object

Convert the specified url to PDF and writes the resulted PDF to an output stream. SelectPdf online API can convert http:// and https:// publicly available urls.

Parameters:

  • url

    Address of the web page being converted.

  • stream

    The output stream where the resulted PDF will be written.


730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
# File 'lib/selectpdf.rb', line 730

def convert_url_to_stream(url, stream)
  if !url.downcase.start_with?('http://') && !url.downcase.start_with?('https://')
    raise ApiException.new('The supported protocols for the converted webpage are http:// and https://.'), 'The supported protocols for the converted webpage are http:// and https://.'
  end

  if url.downcase.start_with?('http://localhost')
    raise ApiException.new('Cannot convert local urls. SelectPdf online API can only convert publicly available urls.'), 'Cannot convert local urls. SelectPdf online API can only convert publicly available urls.'
  end

  @parameters['url'] = url
  @parameters.delete('html')
  @parameters.delete('base_url')
  @parameters['async'] = 'False'

  perform_post(stream)
end

#convert_url_to_stream_async(url, stream) ⇒ Object

Convert the specified url to PDF using an asynchronous call and writes the resulted PDF to an output stream. SelectPdf online API can convert http:// and https:// publicly available urls.

Parameters:

  • url

    Address of the web page being converted.

  • stream

    The output stream where the resulted PDF will be written.


827
828
829
830
# File 'lib/selectpdf.rb', line 827

def convert_url_to_stream_async(url, stream)
  result = convert_url_async(url)
  stream.write(result)
end

#cookies=(cookies) ⇒ Object

Set HTTP cookies for the web page being converted.

Parameters:

  • cookies

    HTTP cookies that will be sent to the page being converted.


1672
1673
1674
# File 'lib/selectpdf.rb', line 1672

def cookies=(cookies)
  @parameters['cookies_string'] = URI.encode_www_form(cookies)
end

#disable_external_links=(disable_external_links) ⇒ Object

Do not create external links in the PDF. The default value is False and external links are created.

Parameters:

  • disable_external_links

    Disable external links or not.


1212
1213
1214
# File 'lib/selectpdf.rb', line 1212

def disable_external_links=(disable_external_links)
  @parameters['disable_external_links'] = disable_external_links
end

#disable_internal_links=(disable_internal_links) ⇒ Object

Do not create internal links in the PDF. The default value is False and internal links are created.

Parameters:

  • disable_internal_links

    Disable internal links or not.


1205
1206
1207
# File 'lib/selectpdf.rb', line 1205

def disable_internal_links=(disable_internal_links)
  @parameters['disable_internal_links'] = disable_internal_links
end

#disable_javascript=(disable_javascript) ⇒ Object

Do not run JavaScript in web pages. The default value is False and javascript is executed.

Parameters:

  • disable_javascript

    Disable javascript or not.


1198
1199
1200
# File 'lib/selectpdf.rb', line 1198

def disable_javascript=(disable_javascript)
  @parameters['disable_javascript'] = disable_javascript
end

#doc_add_creation_date=(doc_add_creation_date) ⇒ Object

Add the date and time when the PDF document was created to the PDF document information. The default value is False.

Parameters:

  • doc_add_creation_date

    Add creation date to the document metadata or not.


1261
1262
1263
# File 'lib/selectpdf.rb', line 1261

def doc_add_creation_date=(doc_add_creation_date)
  @parameters['doc_add_creation_date'] = doc_add_creation_date
end

#doc_author=(doc_author) ⇒ Object

Set the name of the PDF document author.

Parameters:

  • doc_author

    Document author.


1254
1255
1256
# File 'lib/selectpdf.rb', line 1254

def doc_author=(doc_author)
  @parameters['doc_author'] = doc_author
end

#doc_keywords=(doc_keywords) ⇒ Object

Set the PDF document keywords.

Parameters:

  • doc_keywords

    Document keywords.


1247
1248
1249
# File 'lib/selectpdf.rb', line 1247

def doc_keywords=(doc_keywords)
  @parameters['doc_keywords'] = doc_keywords
end

#doc_subject=(doc_subject) ⇒ Object

Set the subject of the PDF document.

Parameters:

  • doc_subject

    Document subject.


1240
1241
1242
# File 'lib/selectpdf.rb', line 1240

def doc_subject=(doc_subject)
  @parameters['doc_subject'] = doc_subject
end

#doc_title=(doc_title) ⇒ Object

Set the PDF document title.

Parameters:

  • doc_title

    Document title.


1233
1234
1235
# File 'lib/selectpdf.rb', line 1233

def doc_title=(doc_title)
  @parameters['doc_title'] = doc_title
end

#draw_html_background=(draw_html_background) ⇒ Object

Set a flag indicating if the web page background is rendered in PDF. The default value is TRUE.

Parameters:

  • draw_html_background

    Draw the HTML background or not.


1191
1192
1193
# File 'lib/selectpdf.rb', line 1191

def draw_html_background=(draw_html_background)
  @parameters['draw_html_background'] = draw_html_background
end

Set an optional base url parameter can be used together with the footer HTML to resolve relative paths from the html string.

Parameters:

  • footer_base_url

    Footer base url.


1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
# File 'lib/selectpdf.rb', line 1458

def footer_base_url=(footer_base_url)
  if !footer_base_url.downcase.start_with?('http://') && !footer_base_url.downcase.start_with?('https://')
    raise ApiException.new('The supported protocols for the converted webpage are http:// and https://.'), 'The supported protocols for the converted webpage are http:// and https://.'
  end

  if footer_base_url.downcase.start_with?('http://localhost')
    raise ApiException.new('Cannot convert local urls. SelectPdf online API can only convert publicly available urls.'), 'Cannot convert local urls. SelectPdf online API can only convert publicly available urls.'
  end

  @parameters['footer_base_url'] = footer_base_url
end

Control the visibility of the footer on the even numbered pages of the generated pdf document. The default value is True.

Parameters:

  • footer_display_on_even_pages

    Display footer on even pages or not.


1487
1488
1489
# File 'lib/selectpdf.rb', line 1487

def footer_display_on_even_pages=(footer_display_on_even_pages)
  @parameters['footer_display_on_even_pages'] = footer_display_on_even_pages
end

Control the visibility of the footer on the first page of the generated pdf document. The default value is True.

Parameters:

  • footer_display_on_first_page

    Display footer on the first page or not.


1473
1474
1475
# File 'lib/selectpdf.rb', line 1473

def footer_display_on_first_page=(footer_display_on_first_page)
  @parameters['footer_display_on_first_page'] = footer_display_on_first_page
end

Add a special footer on the last page of the generated pdf document only. The default value is False. Use footer_url or footer_html and footer_base_url to specify the content of the last page footer. Use footer_height to specify the height of the special last page footer.

Parameters:

  • footer_display_on_last_page

    Display special footer on the last page or not.


1496
1497
1498
# File 'lib/selectpdf.rb', line 1496

def footer_display_on_last_page=(footer_display_on_last_page)
  @parameters['footer_display_on_last_page'] = footer_display_on_last_page
end

Control the visibility of the footer on the odd numbered pages of the generated pdf document. The default value is True.

Parameters:

  • footer_display_on_odd_pages

    Display footer on odd pages or not.


1480
1481
1482
# File 'lib/selectpdf.rb', line 1480

def footer_display_on_odd_pages=(footer_display_on_odd_pages)
  @parameters['footer_display_on_odd_pages'] = footer_display_on_odd_pages
end

The height of the pdf document footer. This height is specified in points. 1 point is 1/72 inch. The default value is 50.

Parameters:

  • footer_height

    Footer height.


1429
1430
1431
# File 'lib/selectpdf.rb', line 1429

def footer_height=(footer_height)
  @parameters['footer_height'] = footer_height
end

Set the raw html that is converted and rendered in the pdf document footer.

Parameters:

  • footer_html

    The raw html that is converted and rendered in the pdf document footer.


1451
1452
1453
# File 'lib/selectpdf.rb', line 1451

def footer_html=(footer_html)
  @parameters['footer_html'] = footer_html
end

Set the url of the web page that is converted and rendered in the PDF document footer.

Parameters:

  • footer_url

    The url of the web page that is converted and rendered in the pdf document footer.


1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
# File 'lib/selectpdf.rb', line 1436

def footer_url=(footer_url)
  if !footer_url.downcase.start_with?('http://') && !footer_url.downcase.start_with?('https://')
    raise ApiException.new('The supported protocols for the converted webpage are http:// and https://.'), 'The supported protocols for the converted webpage are http:// and https://.'
  end

  if footer_url.downcase.start_with?('http://localhost')
    raise ApiException.new('Cannot convert local urls. SelectPdf online API can only convert publicly available urls.'), 'Cannot convert local urls. SelectPdf online API can only convert publicly available urls.'
  end

  @parameters['footer_url'] = footer_url
end

Set the height in pixels used by the converter's internal browser window during the conversion of the footer content. The default value is 0px and it means that the page height is automatically calculated by the converter.

Parameters:

  • footer_web_page_height

    Browser window height in pixels. Set it to 0px to automatically calculate page height.


1511
1512
1513
# File 'lib/selectpdf.rb', line 1511

def footer_web_page_height=(footer_web_page_height)
  @parameters['footer_web_page_height'] = footer_web_page_height
end

Set the width in pixels used by the converter's internal browser window during the conversion of the footer content. The default value is 1024px.

Parameters:

  • footer_web_page_width

    Browser window width in pixels.


1503
1504
1505
# File 'lib/selectpdf.rb', line 1503

def footer_web_page_width=(footer_web_page_width)
  @parameters['footer_web_page_width'] = footer_web_page_width
end

#header_base_url=(header_base_url) ⇒ Object

Set an optional base url parameter can be used together with the header HTML to resolve relative paths from the html string.

Parameters:

  • header_base_url

    Header base url.


1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
# File 'lib/selectpdf.rb', line 1371

def header_base_url=(header_base_url)
  if !header_base_url.downcase.start_with?('http://') && !header_base_url.downcase.start_with?('https://')
    raise ApiException.new('The supported protocols for the converted webpage are http:// and https://.'), 'The supported protocols for the converted webpage are http:// and https://.'
  end

  if header_base_url.downcase.start_with?('http://localhost')
    raise ApiException.new('Cannot convert local urls. SelectPdf online API can only convert publicly available urls.'), 'Cannot convert local urls. SelectPdf online API can only convert publicly available urls.'
  end

  @parameters['header_base_url'] = header_base_url
end

#header_display_on_even_pages=(header_display_on_even_pages) ⇒ Object

Control the visibility of the header on the even numbered pages of the generated pdf document. The default value is True.

Parameters:

  • header_display_on_even_pages

    Display header on even pages or not.


1400
1401
1402
# File 'lib/selectpdf.rb', line 1400

def header_display_on_even_pages=(header_display_on_even_pages)
  @parameters['header_display_on_even_pages'] = header_display_on_even_pages
end

#header_display_on_first_page=(header_display_on_first_page) ⇒ Object

Control the visibility of the header on the first page of the generated pdf document. The default value is True.

Parameters:

  • header_display_on_first_page

    Display header on the first page or not.


1386
1387
1388
# File 'lib/selectpdf.rb', line 1386

def header_display_on_first_page=(header_display_on_first_page)
  @parameters['header_display_on_first_page'] = header_display_on_first_page
end

#header_display_on_odd_pages=(header_display_on_odd_pages) ⇒ Object

Control the visibility of the header on the odd numbered pages of the generated pdf document. The default value is True.

Parameters:

  • header_display_on_odd_pages

    Display header on odd pages or not.


1393
1394
1395
# File 'lib/selectpdf.rb', line 1393

def header_display_on_odd_pages=(header_display_on_odd_pages)
  @parameters['header_display_on_odd_pages'] = header_display_on_odd_pages
end

#header_height=(header_height) ⇒ Object

The height of the pdf document header. This height is specified in points. 1 point is 1/72 inch. The default value is 50.

Parameters:

  • header_height

    Header height.


1342
1343
1344
# File 'lib/selectpdf.rb', line 1342

def header_height=(header_height)
  @parameters['header_height'] = header_height
end

#header_html=(header_html) ⇒ Object

Set the raw html that is converted and rendered in the pdf document header.

Parameters:

  • header_html

    The raw html that is converted and rendered in the pdf document header.


1364
1365
1366
# File 'lib/selectpdf.rb', line 1364

def header_html=(header_html)
  @parameters['header_html'] = header_html
end

#header_url=(header_url) ⇒ Object

Set the url of the web page that is converted and rendered in the PDF document header.

Parameters:

  • header_url

    The url of the web page that is converted and rendered in the pdf document header.


1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
# File 'lib/selectpdf.rb', line 1349

def header_url=(header_url)
  if !header_url.downcase.start_with?('http://') && !header_url.downcase.start_with?('https://')
    raise ApiException.new('The supported protocols for the converted webpage are http:// and https://.'), 'The supported protocols for the converted webpage are http:// and https://.'
  end

  if header_url.downcase.start_with?('http://localhost')
    raise ApiException.new('Cannot convert local urls. SelectPdf online API can only convert publicly available urls.'), 'Cannot convert local urls. SelectPdf online API can only convert publicly available urls.'
  end

  @parameters['header_url'] = header_url
end

#header_web_page_height=(header_web_page_height) ⇒ Object

Set the height in pixels used by the converter's internal browser window during the conversion of the header content. The default value is 0px and it means that the page height is automatically calculated by the converter.

Parameters:

  • header_web_page_height

    Browser window height in pixels. Set it to 0px to automatically calculate page height.


1415
1416
1417
# File 'lib/selectpdf.rb', line 1415

def header_web_page_height=(header_web_page_height)
  @parameters['header_web_page_height'] = header_web_page_height
end

#header_web_page_width=(header_web_page_width) ⇒ Object

Set the width in pixels used by the converter's internal browser window during the conversion of the header content. The default value is 1024px.

Parameters:

  • header_web_page_width

    Browser window width in pixels.


1407
1408
1409
# File 'lib/selectpdf.rb', line 1407

def header_web_page_width=(header_web_page_width)
  @parameters['header_web_page_width'] = header_web_page_width
end

#keep_images_together=(keep_images_together) ⇒ Object

Avoid breaking images between PDF pages. The default value is False and images are split between pages if larger.

Parameters:

  • keep_images_together

    Try to keep images on same page or not.


1226
1227
1228
# File 'lib/selectpdf.rb', line 1226

def keep_images_together=(keep_images_together)
  @parameters['keep_images_together'] = keep_images_together
end

#margin_bottom=(margin_bottom) ⇒ Object

Set bottom margin of the PDF pages. Default value is 5pt.

Parameters:

  • margin_bottom

    Margin value in points. 1pt = 1/72 inch.


1059
1060
1061
# File 'lib/selectpdf.rb', line 1059

def margin_bottom=(margin_bottom)
  @parameters['margin_bottom'] = margin_bottom
end

#margin_left=(margin_left) ⇒ Object

Set left margin of the PDF pages. Default value is 5pt.

Parameters:

  • margin_left

    Margin value in points. 1pt = 1/72 inch.


1066
1067
1068
# File 'lib/selectpdf.rb', line 1066

def margin_left=(margin_left)
  @parameters['margin_left'] = margin_left
end

#margin_right=(margin_right) ⇒ Object

Set right margin of the PDF pages. Default value is 5pt.

Parameters:

  • margin_right

    Margin value in points. 1pt = 1/72 inch.


1052
1053
1054
# File 'lib/selectpdf.rb', line 1052

def margin_right=(margin_right)
  @parameters['margin_right'] = margin_right
end

#margin_top=(margin_top) ⇒ Object

Set top margin of the PDF pages. Default value is 5pt.

Parameters:

  • margin_top

    Margin value in points. 1pt = 1/72 inch.


1045
1046
1047
# File 'lib/selectpdf.rb', line 1045

def margin_top=(margin_top)
  @parameters['margin_top'] = margin_top
end

#margins=(margin) ⇒ Object

Set all margins of the PDF pages to the same value. Default value is 5pt.

Parameters:

  • margin

    Margin value in points. 1pt = 1/72 inch.


1073
1074
1075
1076
1077
1078
# File 'lib/selectpdf.rb', line 1073

def margins=(margin)
  @parameters['margin_top'] = margin
  @parameters['margin_right'] = margin
  @parameters['margin_bottom'] = margin
  @parameters['margin_left'] = margin
end

#max_load_time=(max_load_time) ⇒ Object

Set the maximum amount of time (in seconds) that the convert will wait for the page to load. This method is an alias for navigation_timeout. A timeout error is displayed when this time elapses. The default value is 30 seconds. Use a larger value (up to 120 seconds allowed) for pages that take a long time to load.

Parameters:

  • max_load_time

    Timeout in seconds.


1147
1148
1149
# File 'lib/selectpdf.rb', line 1147

def max_load_time=(max_load_time)
  @parameters['max_load_time'] = max_load_time
end

#min_load_time=(min_load_time) ⇒ Object

Introduce a delay (in seconds) before the actual conversion to allow the web page to fully load. This property is an alias for conversion_delay. The default value is 1 second. Use a larger value if the web page has content that takes time to render when it is displayed in the browser.

Parameters:

  • min_load_time

    Delay in seconds.


1131
1132
1133
# File 'lib/selectpdf.rb', line 1131

def min_load_time=(min_load_time)
  @parameters['min_load_time'] = min_load_time
end

Set the maximum amount of time (in seconds) that the convert will wait for the page to load. This method is an alias for max_load_time. A timeout error is displayed when this time elapses. The default value is 30 seconds. Use a larger value (up to 120 seconds allowed) for pages that take a long time to load.

Parameters:

  • navigation_timeout

    Timeout in seconds.


1155
1156
1157
# File 'lib/selectpdf.rb', line 1155

def navigation_timeout=(navigation_timeout)
  self.max_load_time = navigation_timeout
end

#owner_password=(owner_password) ⇒ Object

Set PDF owner password.

Parameters:

  • owner_password

    PDF owner password.


1108
1109
1110
# File 'lib/selectpdf.rb', line 1108

def owner_password=(owner_password)
  @parameters['owner_password'] = owner_password
end

#page_breaks_enhanced_algorithm=(page_breaks_enhanced_algorithm) ⇒ Object

Get or set a flag indicating if an enhanced custom page breaks algorithm is used. The enhanced algorithm is a little bit slower but it will prevent the appearance of hidden text in the PDF when custom page breaks are used. The default value for this property is False.

Parameters:

  • page_breaks_enhanced_algorithm

    Enable enhanced page breaks algorithm or not.


1665
1666
1667
# File 'lib/selectpdf.rb', line 1665

def page_breaks_enhanced_algorithm=(page_breaks_enhanced_algorithm)
  @parameters['page_breaks_enhanced_algorithm'] = page_breaks_enhanced_algorithm
end

#page_height=(page_height) ⇒ Object

Set PDF page height in points. Default value is 842pt (A4 page height in points). 1pt = 1/72 inch. This is taken into account only if page size is set to SelectPdf::PageSize::CUSTOM using page_size property.

Parameters:

  • page_height

    Page height in points.


1027
1028
1029
# File 'lib/selectpdf.rb', line 1027

def page_height=(page_height)
  @parameters['page_height'] = page_height
end

#page_numbers=(page_numbers) ⇒ Object

Show page numbers. Default value is True. Page numbers will be displayed in the footer of the PDF document.

Parameters:

  • page_numbers

    Show page numbers or not.


1518
1519
1520
# File 'lib/selectpdf.rb', line 1518

def page_numbers=(page_numbers)
  @parameters['page_numbers'] = page_numbers
end

#page_numbers_alignment=(page_numbers_alignment) ⇒ Object

Set the alignment of the page numbers text. The default value is SelectPdf::PageNumbersAlignment::RIGHT.

Parameters:

  • page_numbers_alignment

    The alignment of the page numbers text.


1562
1563
1564
1565
1566
1567
1568
1569
# File 'lib/selectpdf.rb', line 1562

def page_numbers_alignment=(page_numbers_alignment)
  unless [1, 2, 3].include?(page_numbers_alignment)
    raise ApiException.new('Allowed values for Page Numbers Alignment: 1 (Left), 2 (Center), 3 (Right).'),
          'Allowed values for Page Numbers Alignment: 1 (Left), 2 (Center), 3 (Right).'
  end

  @parameters['page_numbers_alignment'] = page_numbers_alignment
end

#page_numbers_color=(page_numbers_color) ⇒ Object

Specify the color of the page numbers text in #RRGGBB html format. The default value is #333333.

Parameters:

  • page_numbers_color

    Page numbers color.


1574
1575
1576
1577
1578
1579
1580
# File 'lib/selectpdf.rb', line 1574

def page_numbers_color=(page_numbers_color)
  unless /^#?[0-9a-fA-F]{6}$/.match(page_numbers_color)
    raise ApiException.new('Color value must be in #RRGGBB format.'), 'Color value must be in #RRGGBB format.'
  end

  @parameters['page_numbers_color'] = page_numbers_color
end

#page_numbers_first=(page_numbers_first) ⇒ Object

Control the page number for the first page being rendered. The default value is 1.

Parameters:

  • page_numbers_first

    First page number.


1525
1526
1527
# File 'lib/selectpdf.rb', line 1525

def page_numbers_first=(page_numbers_first)
  @parameters['page_numbers_first'] = page_numbers_first
end

#page_numbers_font_name=(page_numbers_font_name) ⇒ Object

Set the font used to display the page numbers text. The default value is “Helvetica”.

Parameters:

  • page_numbers_font_name

    The font used to display the page numbers text.


1548
1549
1550
# File 'lib/selectpdf.rb', line 1548

def page_numbers_font_name=(page_numbers_font_name)
  @parameters['page_numbers_font_name'] = page_numbers_font_name
end

#page_numbers_font_size=(page_numbers_font_size) ⇒ Object

Set the size of the font used to display the page numbers. The default value is 10 points.

Parameters:

  • page_numbers_font_size

    The size in points of the font used to display the page numbers.


1555
1556
1557
# File 'lib/selectpdf.rb', line 1555

def page_numbers_font_size=(page_numbers_font_size)
  @parameters['page_numbers_font_size'] = page_numbers_font_size
end

#page_numbers_offset=(page_numbers_offset) ⇒ Object

Control the total number of pages offset in the generated pdf document. The default value is 0.

Parameters:

  • page_numbers_offset

    Offset for the total number of pages in the generated pdf document.


1532
1533
1534
# File 'lib/selectpdf.rb', line 1532

def page_numbers_offset=(page_numbers_offset)
  @parameters['page_numbers_offset'] = page_numbers_offset
end

#page_numbers_pos_y=(page_numbers_pos_y) ⇒ Object

Specify the position in points on the vertical where the page numbers text is displayed in the footer. The default value is 10 points.

Parameters:

  • page_numbers_pos_y

    Page numbers Y position in points.


1585
1586
1587
# File 'lib/selectpdf.rb', line 1585

def page_numbers_pos_y=(page_numbers_pos_y)
  @parameters['page_numbers_pos_y'] = page_numbers_pos_y
end

#page_numbers_template=(page_numbers_template) ⇒ Object

Set the text that is used to display the page numbers. It can contain the placeholder {page_number} for the current page number and {total_pages} for the total number of pages. The default value is “Page: {page_number} of {total_pages}”.

Parameters:

  • page_numbers_template

    Page numbers template.


1541
1542
1543
# File 'lib/selectpdf.rb', line 1541

def page_numbers_template=(page_numbers_template)
  @parameters['page_numbers_template'] = page_numbers_template
end

#page_orientation=(page_orientation) ⇒ Object

Set PDF page orientation. Default value is Portrait.

Parameters:

  • page_orientation

    PDF page orientation. Possible values: Portrait, Landscape. Use constants from SelectPdf::PageOrientation class.


1034
1035
1036
1037
1038
1039
1040
# File 'lib/selectpdf.rb', line 1034

def page_orientation=(page_orientation)
  unless /(?i)^(Portrait|Landscape)$/.match(page_orientation)
    raise ApiException.new('Allowed values for Page Orientation: Portrait, Landscape.'), 'Allowed values for Page Orientation: Portrait, Landscape.'
  end

  @parameters['page_orientation'] = page_orientation
end

#page_size=(page_size) ⇒ Object

Set PDF page size. Default value is A4. If page size is set to Custom, use setPageWidth and setPageHeight methods to set the custom width/height of the PDF pages.

Parameters:

  • page_size

    PDF page size. Possible values: Custom, A0, A1, A2, A3, A4, A5, A6, A7, A8, Letter, HalfLetter, Ledger, Legal. Use constants from SelectPdf::PageSize class.


1007
1008
1009
1010
1011
1012
1013
# File 'lib/selectpdf.rb', line 1007

def page_size=(page_size)
  unless /(?i)^(Custom|A0|A1|A2|A3|A4|A5|A6|A7|A8|Letter|HalfLetter|Ledger|Legal)$/.match(page_size)
    raise ApiException.new('Allowed values for Page Size: Custom, A0, A1, A2, A3, A4, A5, A6, A7, A8, Letter, HalfLetter, Ledger, Legal.'), 'Allowed values for Page Size: Custom, A0, A1, A2, A3, A4, A5, A6, A7, A8, Letter, HalfLetter, Ledger, Legal.'
  end

  @parameters['page_size'] = page_size
end

#page_width=(page_width) ⇒ Object

Set PDF page width in points. Default value is 595pt (A4 page width in points). 1pt = 1/72 inch. This is taken into account only if page size is set to SelectPdf::PageSize::CUSTOM using page_size property.

Parameters:

  • page_width

    Page width in points.


1019
1020
1021
# File 'lib/selectpdf.rb', line 1019

def page_width=(page_width)
  @parameters['page_width'] = page_width
end

#pdf_bookmarks_selectors=(pdf_bookmarks_selectors) ⇒ Object

Generate automatic bookmarks in pdf. The elements that will be bookmarked are defined using CSS selectors. For example, the selector for all the H1 elements is “H1”, the selector for all the elements with the CSS class name 'myclass' is “*.myclass” and the selector for the elements with the id 'myid' is “*#myid”. Read more about CSS selectors <a href=“www.w3schools.com/cssref/css_selectors.asp” target=“_blank”>here</a>.

Parameters:

  • pdf_bookmarks_selectors

    CSS selectors used to identify HTML elements, comma separated.


1594
1595
1596
# File 'lib/selectpdf.rb', line 1594

def pdf_bookmarks_selectors=(pdf_bookmarks_selectors)
  @parameters['pdf_bookmarks_selectors'] = pdf_bookmarks_selectors
end

#pdf_hide_elements=(pdf_hide_elements) ⇒ Object

Exclude page elements from the conversion. The elements that will be excluded are defined using CSS selectors. For example, the selector for all the H1 elements is “H1”, the selector for all the elements with the CSS class name 'myclass' is “*.myclass” and the selector for the elements with the id 'myid' is “*#myid”. Read more about CSS selectors <a href=“www.w3schools.com/cssref/css_selectors.asp” target=“_blank”>here</a>.

Parameters:

  • pdf_hide_elements

    CSS selectors used to identify HTML elements, comma separated.


1603
1604
1605
# File 'lib/selectpdf.rb', line 1603

def pdf_hide_elements=(pdf_hide_elements)
  @parameters['pdf_hide_elements'] = pdf_hide_elements
end

#pdf_name=(pdf_name) ⇒ Object

Specify the name of the pdf document that will be created. The default value is Document.pdf.

Parameters:

  • pdf_name

    Name of the generated PDF document.


1083
1084
1085
# File 'lib/selectpdf.rb', line 1083

def pdf_name=(pdf_name)
  @parameters['pdf_name'] = pdf_name
end

#pdf_show_only_element_id=(pdf_show_only_element_id) ⇒ Object

Convert only a specific section of the web page to pdf. The section that will be converted to pdf is specified by the html element ID. The element can be anything (image, table, table row, div, text, etc).

Parameters:

  • pdf_show_only_element_id

    HTML element ID.


1612
1613
1614
# File 'lib/selectpdf.rb', line 1612

def pdf_show_only_element_id=(pdf_show_only_element_id)
  @parameters['pdf_show_only_element_id'] = pdf_show_only_element_id
end

#pdf_web_elements_selectors=(pdf_web_elements_selectors) ⇒ Object

Get the locations of page elements from the conversion. The elements that will have their locations retrieved are defined using CSS selectors. For example, the selector for all the H1 elements is “H1”, the selector for all the elements with the CSS class name 'myclass' is “*.myclass” and the selector for the elements with the id 'myid' is “*#myid”. Read more about CSS selectors <a href=“www.w3schools.com/cssref/css_selectors.asp” target=“_blank”>here</a>.

Parameters:

  • pdf_web_elements_selectors

    CSS selectors used to identify HTML elements, comma separated.


1621
1622
1623
# File 'lib/selectpdf.rb', line 1621

def pdf_web_elements_selectors=(pdf_web_elements_selectors)
  @parameters['pdf_web_elements_selectors'] = pdf_web_elements_selectors
end

#render_on_timeout=(render_on_timeout) ⇒ Object

Try to render the PDF even in case of the web page loading timeout. The default value is False and an exception is raised in case of web page navigation timeout.

Parameters:

  • render_on_timeout

    Render in case of timeout or not.


1219
1220
1221
# File 'lib/selectpdf.rb', line 1219

def render_on_timeout=(render_on_timeout)
  @parameters['render_on_timeout'] = render_on_timeout
end

#rendering_engine=(rendering_engine) ⇒ Object

Set the rendering engine used for the HTML to PDF conversion. Default value is WebKit.

Parameters:

  • rendering_engine

    HTML rendering engine. Use constants from SelectPdf::RenderingEngine class.


1090
1091
1092
1093
1094
1095
1096
# File 'lib/selectpdf.rb', line 1090

def rendering_engine=(rendering_engine)
  unless /(?i)^(WebKit|Restricted|Blink)$/.match(rendering_engine)
    raise ApiException.new('Allowed values for Rendering Engine: WebKit, Restricted, Blink.'), 'Allowed values for Rendering Engine: WebKit, Restricted, Blink.'
  end

  @parameters['engine'] = rendering_engine
end

#scale_images=(scale_images) ⇒ Object

Set a flag indicating if the images from the page are scaled during the conversion process. The default value is False and images are not scaled.

Parameters:

  • scale_images

    Scale images or not.


1648
1649
1650
# File 'lib/selectpdf.rb', line 1648

def scale_images=(scale_images)
  @parameters['scale_images'] = scale_images
end

#secure_protocol=(secure_protocol) ⇒ Object

Set the protocol used for secure (HTTPS) connections. Set this only if you have an older server that only works with older SSL connections.

Parameters:

  • secure_protocol

    Secure protocol. Possible values: 0 (TLS 1.1 or newer), 1 (TLS 1.0), 2 (SSL v3 only). Use constants from SelectPdf::SecureProtocol class.


1162
1163
1164
1165
1166
1167
1168
# File 'lib/selectpdf.rb', line 1162

def secure_protocol=(secure_protocol)
  unless [0, 1, 2].include?(secure_protocol)
    raise ApiException.new('Allowed values for Secure Protocol: 0 (TLS 1.1 or newer), 1 (TLS 1.0), 2 (SSL v3 only).'), 'Allowed values for Secure Protocol: 0 (TLS 1.1 or newer), 1 (TLS 1.0), 2 (SSL v3 only).'
  end

  @parameters['protocol'] = secure_protocol
end

#set_custom_parameter(parameter_name, parameter_value) ⇒ Object

Set a custom parameter. Do not use this method unless advised by SelectPdf.

Parameters:

  • parameter_name

    Parameter name.

  • parameter_value

    Parameter value.


1680
1681
1682
# File 'lib/selectpdf.rb', line 1680

def set_custom_parameter(parameter_name, parameter_value)
  @parameters[parameter_name] = parameter_value
end

#show_footer=(show_footer) ⇒ Object

Control if a custom footer is displayed in the generated PDF document. The default value is False.

Parameters:

  • show_footer

    Show footer or not.


1422
1423
1424
# File 'lib/selectpdf.rb', line 1422

def show_footer=(show_footer)
  @parameters['show_footer'] = show_footer
end

#show_header=(show_header) ⇒ Object

Control if a custom header is displayed in the generated PDF document. The default value is False.

Parameters:

  • show_header

    Show header or not.


1335
1336
1337
# File 'lib/selectpdf.rb', line 1335

def show_header=(show_header)
  @parameters['show_header'] = show_header
end

#single_page_pdf=(single_page_pdf) ⇒ Object

Generate a single page PDF. The converter will automatically resize the PDF page to fit all the content in a single page. The default value of this property is False and the PDF will contain several pages if the content is large.

Parameters:

  • single_page_pdf

    Generate a single page PDF or not.


1656
1657
1658
# File 'lib/selectpdf.rb', line 1656

def single_page_pdf=(single_page_pdf)
  @parameters['single_page_pdf'] = single_page_pdf
end

#skip_decoding=(skip_decoding) ⇒ Object

Internal use only.

Parameters:

  • skip_decoding

    The default value is True.


1641
1642
1643
# File 'lib/selectpdf.rb', line 1641

def skip_decoding=(skip_decoding)
  @parameters['skip_decoding'] = skip_decoding
end

#startup_mode=(startup_mode) ⇒ Object

Set converter startup mode. The default value is SelectPdf::StartupMode::AUTOMATIC and the conversion is started immediately. By default this is set to SelectPdf::StartupMode::AUTOMATIC and the conversion is started as soon as the page loads (and conversion delay set with conversion_delay elapses). If set to SelectPdf::StartupMode::MANUAL, the conversion is started only by a javascript call to SelectPdf.startConversion() from within the web page.

Parameters:

  • startup_mode

    Converter startup mode.


1630
1631
1632
1633
1634
1635
1636
# File 'lib/selectpdf.rb', line 1630

def startup_mode=(startup_mode)
  unless /(?i)^(Automatic|Manual)$/.match(startup_mode)
    raise ApiException.new('Allowed values for Startup Mode: Automatic, Manual.'), 'Allowed values for Startup Mode: Automatic, Manual.'
  end

  @parameters['startup_mode'] = startup_mode
end

#use_css_print=(use_css_print) ⇒ Object

Specify if the CSS Print media type is used instead of the Screen media type. The default value is FALSE.

Parameters:

  • use_css_print

    Use CSS Print media or not.


1173
1174
1175
# File 'lib/selectpdf.rb', line 1173

def use_css_print=(use_css_print)
  @parameters['use_css_print'] = use_css_print
end

#user_password=(user_password) ⇒ Object

Set PDF user password.

Parameters:

  • user_password

    PDF user password.


1101
1102
1103
# File 'lib/selectpdf.rb', line 1101

def user_password=(user_password)
  @parameters['user_password'] = user_password
end

#viewer_center_window=(viewer_center_window) ⇒ Object

Set a flag specifying whether to position the document's window in the center of the screen. The default value is False.

Parameters:

  • viewer_center_window

    Center window or not.


1293
1294
1295
# File 'lib/selectpdf.rb', line 1293

def viewer_center_window=(viewer_center_window)
  @parameters['viewer_center_window'] = viewer_center_window
end

#viewer_display_doc_title=(viewer_display_doc_title) ⇒ Object

Set a flag specifying whether the window's title bar should display the document title taken from document information. The default value is False.

Parameters:

  • viewer_display_doc_title

    Display title or not.


1300
1301
1302
# File 'lib/selectpdf.rb', line 1300

def viewer_display_doc_title=(viewer_display_doc_title)
  @parameters['viewer_display_doc_title'] = viewer_display_doc_title
end

#viewer_fit_window=(viewer_fit_window) ⇒ Object

Set a flag specifying whether to resize the document's window to fit the size of the first displayed page. The default value is False.

Parameters:

  • viewer_fit_window

    Fit window or not.


1307
1308
1309
# File 'lib/selectpdf.rb', line 1307

def viewer_fit_window=(viewer_fit_window)
  @parameters['viewer_fit_window'] = viewer_fit_window
end

#viewer_hide_menu_bar=(viewer_hide_menu_bar) ⇒ Object

Set a flag specifying whether to hide the pdf viewer application's menu bar when the document is active. The default value is False.

Parameters:

  • viewer_hide_menu_bar

    Hide menu bar or not.


1314
1315
1316
# File 'lib/selectpdf.rb', line 1314

def viewer_hide_menu_bar=(viewer_hide_menu_bar)
  @parameters['viewer_hide_menu_bar'] = viewer_hide_menu_bar
end

#viewer_hide_toolbar=(viewer_hide_toolbar) ⇒ Object

Set a flag specifying whether to hide the pdf viewer application's tool bars when the document is active. The default value is False.

Parameters:

  • viewer_hide_toolbar

    Hide tool bars or not.


1321
1322
1323
# File 'lib/selectpdf.rb', line 1321

def viewer_hide_toolbar=(viewer_hide_toolbar)
  @parameters['viewer_hide_toolbar'] = viewer_hide_toolbar
end

#viewer_hide_window_ui=(viewer_hide_window_ui) ⇒ Object

Set a flag specifying whether to hide user interface elements in the document's window (such as scroll bars and navigation controls), leaving only the document's contents displayed.

Parameters:

  • viewer_hide_window_ui

    Hide window UI or not.


1328
1329
1330
# File 'lib/selectpdf.rb', line 1328

def viewer_hide_window_ui=(viewer_hide_window_ui)
  @parameters['viewer_hide_window_ui'] = viewer_hide_window_ui
end

#viewer_page_layout=(viewer_page_layout) ⇒ Object

Set the page layout to be used when the document is opened in a PDF viewer. The default value is SelectPdf::PageLayout::ONE_COLUMN.

Use constants from SelectPdf::PageLayout class.

Parameters:

  • viewer_page_layout

    Page layout. Possible values: 0 (Single Page), 1 (One Column), 2 (Two Column Left), 3 (Two Column Right).


1269
1270
1271
1272
1273
1274
1275
# File 'lib/selectpdf.rb', line 1269

def viewer_page_layout=(viewer_page_layout)
  unless [0, 1, 2, 3].include?(viewer_page_layout)
    raise ApiException.new('Allowed values for Page Layout: 0 (Single Page), 1 (One Column), 2 (Two Column Left), 3 (Two Column Right).'), 'Allowed values for Page Layout: 0 (Single Page), 1 (One Column), 2 (Two Column Left), 3 (Two Column Right).'
  end

  @parameters['viewer_page_layout'] = viewer_page_layout
end

#viewer_page_mode=(viewer_page_mode) ⇒ Object

Set the document page mode when the pdf document is opened in a PDF viewer. The default value is SelectPdf::PageMode::USE_NONE.

Use constants from SelectPdf::PageMode class.

Parameters:

  • viewer_page_mode

    Page mode. Possible values: 0 (Use None), 1 (Use Outlines), 2 (Use Thumbs), 3 (Full Screen), 4 (Use OC), 5 (Use Attachments).


1281
1282
1283
1284
1285
1286
1287
1288
# File 'lib/selectpdf.rb', line 1281

def viewer_page_mode=(viewer_page_mode)
  unless [0, 1, 2, 3, 4, 5].include?(viewer_page_mode)
    raise ApiException.new('Allowed values for Page Mode: 0 (Use None), 1 (Use Outlines), 2 (Use Thumbs), 3 (Full Screen), 4 (Use OC), 5 (Use Attachments).'),
          'Allowed values for Page Mode: 0 (Use None), 1 (Use Outlines), 2 (Use Thumbs), 3 (Full Screen), 4 (Use OC), 5 (Use Attachments).'
  end

  @parameters['viewer_page_mode'] = viewer_page_mode
end

#web_elementsObject

Get the locations of certain web elements. This is retrieved if pdf_web_elements_selectors parameter is set and elements were found to match the selectors.

Returns:

  • List of web elements locations.


1687
1688
1689
1690
1691
1692
# File 'lib/selectpdf.rb', line 1687

def web_elements
  web_elements_client = WebElementsClient.new(@parameters['key'], @job_id)
  web_elements_client.api_endpoint = @api_web_elements_endpoint

  web_elements_client.web_elements
end

#web_page_height=(web_page_height) ⇒ Object

Set the height used by the converter's internal browser window in pixels. The default value is 0px and it means that the page height is automatically calculated by the converter.

Parameters:

  • web_page_height

    Browser window height in pixels. Set it to 0px to automatically calculate page height.


1123
1124
1125
# File 'lib/selectpdf.rb', line 1123

def web_page_height=(web_page_height)
  @parameters['web_page_height'] = web_page_height
end

#web_page_width=(web_page_width) ⇒ Object

Set the width used by the converter's internal browser window in pixels. The default value is 1024px.

Parameters:

  • web_page_width

    Browser window width in pixels.


1115
1116
1117
# File 'lib/selectpdf.rb', line 1115

def web_page_width=(web_page_width)
  @parameters['web_page_width'] = web_page_width
end