Class: Pdfcrowd::PdfToPdfClient
- Inherits:
-
Object
- Object
- Pdfcrowd::PdfToPdfClient
- Defined in:
- lib/pdfcrowd.rb
Overview
Conversion from PDF to PDF.
Instance Method Summary collapse
-
#addPdfFile(file_path) ⇒ Object
Add a PDF file to the list of the input PDFs.
-
#addPdfRawData(pdf_raw_data) ⇒ Object
Add in-memory raw PDF data to the list of the input PDFs.Typical usage is for adding PDF created by another Pdfcrowd converter.
-
#convert ⇒ Object
Perform an action on the input files.
-
#convertToFile(file_path) ⇒ Object
Perform an action on the input files and write the output PDF to a file.
-
#convertToStream(out_stream) ⇒ Object
Perform an action on the input files and write the output PDF to an output stream.
-
#getConsumedCreditCount ⇒ Object
Get the number of credits consumed by the last conversion.
-
#getDebugLogUrl ⇒ Object
Get the URL of the debug log for the last conversion.
-
#getJobId ⇒ Object
Get the job id.
-
#getOutputSize ⇒ Object
Get the size of the output in bytes.
-
#getPageCount ⇒ Object
Get the total number of pages in the output document.
-
#getRemainingCreditCount ⇒ Object
Get the number of conversion credits available in your account.
-
#initialize(user_name, api_key) ⇒ PdfToPdfClient
constructor
Constructor for the Pdfcrowd API client.
-
#setAction(action) ⇒ Object
Specifies the action to be performed on the input PDFs.
-
#setDebugLog(debug_log) ⇒ Object
Turn on the debug logging.
-
#setProxy(host, port, user_name, password) ⇒ Object
Specifies an HTTP proxy that the API client library will use to connect to the internet.
-
#setRetryCount(retry_count) ⇒ Object
Specifies the number of retries when the 502 HTTP status code is received.
-
#setTag(tag) ⇒ Object
Tag the conversion with a custom value.
-
#setUseHttp(use_http) ⇒ Object
Specifies if the client communicates over HTTP or HTTPS with Pdfcrowd API.
-
#setUserAgent(user_agent) ⇒ Object
Set a custom user agent HTTP header.
Constructor Details
#initialize(user_name, api_key) ⇒ PdfToPdfClient
Constructor for the Pdfcrowd API client.
-
user_name
- Your username at Pdfcrowd. -
api_key
- Your API key.
2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 |
# File 'lib/pdfcrowd.rb', line 2916 def initialize(user_name, api_key) @helper = ConnectionHelper.new(user_name, api_key) @fields = { 'input_format'=>'pdf', 'output_format'=>'pdf' } @file_id = 1 @files = {} @raw_data = {} end |
Instance Method Details
#addPdfFile(file_path) ⇒ Object
Add a PDF file to the list of the input PDFs.
-
file_path
- The file path to a local PDF file. The file must exist and not be empty. -
Returns - The converter object.
2970 2971 2972 2973 2974 2975 2976 2977 2978 |
# File 'lib/pdfcrowd.rb', line 2970 def addPdfFile(file_path) if (!(File.file?(file_path) && !File.zero?(file_path))) raise Error.new(Pdfcrowd.(file_path, "file_path", "pdf-to-pdf", "The file must exist and not be empty.", "add_pdf_file"), 470); end @files['f_%s' % @file_id] = file_path @file_id += 1 self end |
#addPdfRawData(pdf_raw_data) ⇒ Object
Add in-memory raw PDF data to the list of the input PDFs.Typical usage is for adding PDF created by another Pdfcrowd converter. Example in PHP: $clientPdf2Pdf->addPdfRawData($clientHtml2Pdf->convertUrl(‘www.example.com’));
-
pdf_raw_data
- The raw PDF data. The input data must be PDF content. -
Returns - The converter object.
2984 2985 2986 2987 2988 2989 2990 2991 2992 |
# File 'lib/pdfcrowd.rb', line 2984 def addPdfRawData(pdf_raw_data) if (!(!pdf_raw_data.nil? && pdf_raw_data.length > 300 and pdf_raw_data[0...4] == '%PDF')) raise Error.new(Pdfcrowd.("raw PDF data", "pdf_raw_data", "pdf-to-pdf", "The input data must be PDF content.", "add_pdf_raw_data"), 470); end @raw_data['f_%s' % @file_id] = pdf_raw_data @file_id += 1 self end |
#convert ⇒ Object
Perform an action on the input files.
-
Returns - Byte array containing the output PDF.
2942 2943 2944 |
# File 'lib/pdfcrowd.rb', line 2942 def convert() @helper.post(@fields, @files, @raw_data) end |
#convertToFile(file_path) ⇒ Object
Perform an action on the input files and write the output PDF to a file.
-
file_path
- The output file path. The string must not be empty.
2956 2957 2958 2959 2960 2961 2962 2963 2964 |
# File 'lib/pdfcrowd.rb', line 2956 def convertToFile(file_path) if (!(!file_path.nil? && !file_path.empty?)) raise Error.new(Pdfcrowd.(file_path, "file_path", "pdf-to-pdf", "The string must not be empty.", "convert_to_file"), 470); end output_file = open(file_path, "wb") convertToStream(output_file) output_file.close() end |
#convertToStream(out_stream) ⇒ Object
Perform an action on the input files and write the output PDF to an output stream.
-
out_stream
- The output stream that will contain the output PDF.
2949 2950 2951 |
# File 'lib/pdfcrowd.rb', line 2949 def convertToStream(out_stream) @helper.post(@fields, @files, @raw_data, out_stream) end |
#getConsumedCreditCount ⇒ Object
Get the number of credits consumed by the last conversion.
-
Returns - The number of credits.
3020 3021 3022 |
# File 'lib/pdfcrowd.rb', line 3020 def getConsumedCreditCount() return @helper.getConsumedCreditCount() end |
#getDebugLogUrl ⇒ Object
Get the URL of the debug log for the last conversion.
-
Returns - The link to the debug log.
3005 3006 3007 |
# File 'lib/pdfcrowd.rb', line 3005 def getDebugLogUrl() return @helper.getDebugLogUrl() end |
#getJobId ⇒ Object
Get the job id.
-
Returns - The unique job identifier.
3026 3027 3028 |
# File 'lib/pdfcrowd.rb', line 3026 def getJobId() return @helper.getJobId() end |
#getOutputSize ⇒ Object
Get the size of the output in bytes.
-
Returns - The count of bytes.
3038 3039 3040 |
# File 'lib/pdfcrowd.rb', line 3038 def getOutputSize() return @helper.getOutputSize() end |
#getPageCount ⇒ Object
Get the total number of pages in the output document.
-
Returns - The page count.
3032 3033 3034 |
# File 'lib/pdfcrowd.rb', line 3032 def getPageCount() return @helper.getPageCount() end |
#getRemainingCreditCount ⇒ Object
Get the number of conversion credits available in your account. This method can only be called after a call to one of the convertXYZ methods. The returned value can differ from the actual count if you run parallel conversions. The special value 999999 is returned if the information is not available.
-
Returns - The number of credits.
3014 3015 3016 |
# File 'lib/pdfcrowd.rb', line 3014 def getRemainingCreditCount() return @helper.getRemainingCreditCount() end |
#setAction(action) ⇒ Object
Specifies the action to be performed on the input PDFs.
-
action
- Allowed values are join, shuffle. -
Returns - The converter object.
2931 2932 2933 2934 2935 2936 2937 2938 |
# File 'lib/pdfcrowd.rb', line 2931 def setAction(action) unless /(?i)^(join|shuffle)$/.match(action) raise Error.new(Pdfcrowd.(action, "action", "pdf-to-pdf", "Allowed values are join, shuffle.", "set_action"), 470); end @fields['action'] = action self end |
#setDebugLog(debug_log) ⇒ Object
Turn on the debug logging. Details about the conversion are stored in the debug log. The URL of the log can be obtained from the getDebugLogUrl method or available in conversion statistics.
-
debug_log
- Set to true to enable the debug logging. -
Returns - The converter object.
2998 2999 3000 3001 |
# File 'lib/pdfcrowd.rb', line 2998 def setDebugLog(debug_log) @fields['debug_log'] = debug_log self end |
#setProxy(host, port, user_name, password) ⇒ Object
Specifies an HTTP proxy that the API client library will use to connect to the internet.
-
host
- The proxy hostname. -
port
- The proxy port. -
user_name
- The username. -
password
- The password. -
Returns - The converter object.
3076 3077 3078 3079 |
# File 'lib/pdfcrowd.rb', line 3076 def setProxy(host, port, user_name, password) @helper.setProxy(host, port, user_name, password) self end |
#setRetryCount(retry_count) ⇒ Object
Specifies the number of retries when the 502 HTTP status code is received. The 502 status code indicates a temporary network issue. This feature can be disabled by setting to 0.
-
retry_count
- Number of retries wanted. -
Returns - The converter object.
3085 3086 3087 3088 |
# File 'lib/pdfcrowd.rb', line 3085 def setRetryCount(retry_count) @helper.setRetryCount(retry_count) self end |
#setTag(tag) ⇒ Object
Tag the conversion with a custom value. The tag is used in conversion statistics. A value longer than 32 characters is cut off.
-
tag
- A string with the custom tag. -
Returns - The converter object.
3046 3047 3048 3049 |
# File 'lib/pdfcrowd.rb', line 3046 def setTag(tag) @fields['tag'] = tag self end |
#setUseHttp(use_http) ⇒ Object
Specifies if the client communicates over HTTP or HTTPS with Pdfcrowd API.
-
use_http
- Set to true to use HTTP. -
Returns - The converter object.
3055 3056 3057 3058 |
# File 'lib/pdfcrowd.rb', line 3055 def setUseHttp(use_http) @helper.setUseHttp(use_http) self end |
#setUserAgent(user_agent) ⇒ Object
Set a custom user agent HTTP header. It can be usefull if you are behind some proxy or firewall.
-
user_agent
- The user agent string. -
Returns - The converter object.
3064 3065 3066 3067 |
# File 'lib/pdfcrowd.rb', line 3064 def setUserAgent(user_agent) @helper.setUserAgent(user_agent) self end |