Class: Pdfcrowd::Client

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

Overview

Pdfcrowd API client.

Instance Method Summary collapse

Constructor Details

#initialize(username, apikey, hostname = nil) ⇒ Client

Client constructor.

username – your username at Pdfcrowd apikey – your API key



108
109
110
111
112
113
114
115
116
117
# File 'lib/pdfcrowd.rb', line 108

def initialize(username, apikey, hostname=nil)
  useSSL(false)
  @fields  = {
    'username' => username,
    'key' => apikey,
    'html_zoom' => 200,
    'pdf_scaling_factor' => 1
  }
  @hostname = hostname || $api_hostname;
end

Instance Method Details

#convertFile(fpath, outstream = nil) ⇒ Object

Converts an html file.

fpath – a path to an html file outstream – an object having method ‘write(data)’; if nil then the

return value is a string containing the PDF.


148
149
150
# File 'lib/pdfcrowd.rb', line 148

def convertFile(fpath, outstream=nil)
    return post_multipart(fpath, outstream)
end

#convertHtml(content, outstream = nil) ⇒ Object

Converts an in-memory html document.

content – a string containing an html document outstream – an object having method ‘write(data)’; if nil then the

return value is a string containing the PDF.


137
138
139
# File 'lib/pdfcrowd.rb', line 137

def convertHtml(content, outstream=nil)
    return call_api_urlencoded('/api/pdf/convert/html/', content, outstream)
end

#convertURI(uri, outstream = nil) ⇒ Object

Converts a web page.

uri – a web page URL outstream – an object having method ‘write(data)’; if nil then the

return value is a string containing the PDF.


126
127
128
# File 'lib/pdfcrowd.rb', line 126

def convertURI(uri, outstream=nil)
    return call_api_urlencoded('/api/pdf/convert/uri/', uri, outstream)
end

#enableBackgrounds(value = true) ⇒ Object



240
241
242
# File 'lib/pdfcrowd.rb', line 240

def enableBackgrounds(value=true)
    @fields['no_backgrounds'] = (not value)
end


252
253
254
# File 'lib/pdfcrowd.rb', line 252

def enableHyperlinks(value=true)
    @fields['no_hyperlinks'] = (not value)
end

#enableImages(value = true) ⇒ Object



236
237
238
# File 'lib/pdfcrowd.rb', line 236

def enableImages(value=true)
    @fields['no_images'] = (not value)
end

#enableJavaScript(value = true) ⇒ Object



248
249
250
# File 'lib/pdfcrowd.rb', line 248

def enableJavaScript(value=true)
    @fields['no_javascript'] = (not value)
end

#enablePdfcrowdLogo(value = true) ⇒ Object



268
269
270
# File 'lib/pdfcrowd.rb', line 268

def (value=true)
    @fields['pdfcrowd_logo'] = value
end

#numTokensObject

Returns the number of available conversion tokens.



155
156
157
158
# File 'lib/pdfcrowd.rb', line 155

def numTokens()
  uri = '/api/user/%s/tokens/' % @fields['username']
  return Integer(call_api_urlencoded(uri))
end

#setApiKey(key) ⇒ Object



169
170
171
# File 'lib/pdfcrowd.rb', line 169

def setApiKey(key)
    @fields['key'] = key
end

#setAuthor(value) ⇒ Object



282
283
284
# File 'lib/pdfcrowd.rb', line 282

def setAuthor(value)
    @fields['author'] = value
end

#setDefaultTextEncoding(value) ⇒ Object



256
257
258
# File 'lib/pdfcrowd.rb', line 256

def setDefaultTextEncoding(value)
    @fields['text_encoding'] = value
end

#setEncrypted(val = true) ⇒ Object



197
198
199
# File 'lib/pdfcrowd.rb', line 197

def setEncrypted(val=true)
    @fields['encrypted'] = val
end

#setFailOnNon200(value) ⇒ Object



286
287
288
# File 'lib/pdfcrowd.rb', line 286

def setFailOnNon200(value)
    @fields['fail_on_non200'] = value
end

#setFooterHtml(value) ⇒ Object



294
295
296
# File 'lib/pdfcrowd.rb', line 294

def setFooterHtml(value)
    @fields['footer_html'] = value
end

#setFooterText(value) ⇒ Object



232
233
234
# File 'lib/pdfcrowd.rb', line 232

def setFooterText(value)
    @fields['footer_text'] = value
end

#setFooterUrl(value) ⇒ Object



298
299
300
# File 'lib/pdfcrowd.rb', line 298

def setFooterUrl(value)
    @fields['footer_url'] = value
end

#setHeaderFooterPageExcludeList(value) ⇒ Object



322
323
324
# File 'lib/pdfcrowd.rb', line 322

def setHeaderFooterPageExcludeList(value)
    @fields['header_footer_page_exclude_list'] = value
end

#setHeaderHtml(value) ⇒ Object



302
303
304
# File 'lib/pdfcrowd.rb', line 302

def setHeaderHtml(value)
    @fields['header_html'] = value
end

#setHeaderUrl(value) ⇒ Object



306
307
308
# File 'lib/pdfcrowd.rb', line 306

def setHeaderUrl(value)
    @fields['header_url'] = value
end

#setHorizontalMargin(value) ⇒ Object



181
182
183
# File 'lib/pdfcrowd.rb', line 181

def setHorizontalMargin(value)
    @fields['margin_right'] = @fields['margin_left'] = value.to_s()
end

#setHtmlZoom(value) ⇒ Object



244
245
246
# File 'lib/pdfcrowd.rb', line 244

def setHtmlZoom(value)
    @fields['html_zoom'] = value
end

#setInitialPdfExactZoom(value) ⇒ Object



277
278
279
280
# File 'lib/pdfcrowd.rb', line 277

def setInitialPdfExactZoom(value)
    @fields['initial_pdf_zoom_type'] = 4
    @fields['initial_pdf_zoom'] = value
end

#setInitialPdfZoomType(value) ⇒ Object



272
273
274
275
# File 'lib/pdfcrowd.rb', line 272

def setInitialPdfZoomType(value)
    assert_pdfcrowd { value>0 and value<=3 }
    @fields['initial_pdf_zoom_type'] = value
end

#setMaxPages(value) ⇒ Object



264
265
266
# File 'lib/pdfcrowd.rb', line 264

def setMaxPages(value)
    @fields['max_pages'] = value
end

#setNoCopy(val = true) ⇒ Object



217
218
219
# File 'lib/pdfcrowd.rb', line 217

def setNoCopy(val=true)
    @fields['no_copy'] = val
end

#setNoModify(val = true) ⇒ Object



213
214
215
# File 'lib/pdfcrowd.rb', line 213

def setNoModify(val=true)
    @fields['no_modify'] = val
end

#setNoPrint(val = true) ⇒ Object



209
210
211
# File 'lib/pdfcrowd.rb', line 209

def setNoPrint(val=true)
    @fields['no_print'] = val
end

#setOwnerPassword(pwd) ⇒ Object



205
206
207
# File 'lib/pdfcrowd.rb', line 205

def setOwnerPassword(pwd)
    @fields['owner_pwd'] = pwd
end

#setPageBackgroundColor(value) ⇒ Object



310
311
312
# File 'lib/pdfcrowd.rb', line 310

def setPageBackgroundColor(value)
    @fields['page_background_color'] = value
end

#setPageHeight(value) ⇒ Object



177
178
179
# File 'lib/pdfcrowd.rb', line 177

def setPageHeight(value)
    @fields['height'] = value
end

#setPageLayout(value) ⇒ Object



221
222
223
224
# File 'lib/pdfcrowd.rb', line 221

def setPageLayout(value)
    assert_pdfcrowd { value > 0 and value <= 3 }
    @fields['page_layout'] = value
end

#setPageMargins(top, right, bottom, left) ⇒ Object



189
190
191
192
193
194
# File 'lib/pdfcrowd.rb', line 189

def setPageMargins(top, right, bottom, left)
    @fields['margin_top'] = top.to_s()
    @fields['margin_right'] = right.to_s()
    @fields['margin_bottom'] = bottom.to_s()
    @fields['margin_left'] = left.to_s()
end

#setPageMode(value) ⇒ Object



226
227
228
229
# File 'lib/pdfcrowd.rb', line 226

def setPageMode(value)
    assert_pdfcrowd { value > 0 and value <= 3 }
    @fields['page_mode'] = value
end

#setPageNumberingOffset(value) ⇒ Object



318
319
320
# File 'lib/pdfcrowd.rb', line 318

def setPageNumberingOffset(value)
    @fields['page_numbering_offset'] = value
end

#setPageWidth(value) ⇒ Object



173
174
175
# File 'lib/pdfcrowd.rb', line 173

def setPageWidth(value)
    @fields['width'] = value
end

#setPdfScalingFactor(value) ⇒ Object



290
291
292
# File 'lib/pdfcrowd.rb', line 290

def setPdfScalingFactor(value)
    @fields['pdf_scaling_factor'] = value
end

#setTransparentBackground(value = true) ⇒ Object



314
315
316
# File 'lib/pdfcrowd.rb', line 314

def setTransparentBackground(value=true)
    @fields['transparent_background'] = value
end

#setUsername(username) ⇒ Object



165
166
167
# File 'lib/pdfcrowd.rb', line 165

def setUsername(username)
    @fields['username'] = username
end

#setUserPassword(pwd) ⇒ Object



201
202
203
# File 'lib/pdfcrowd.rb', line 201

def setUserPassword(pwd)
    @fields['user_pwd'] = pwd
end

#setVerticalMargin(value) ⇒ Object



185
186
187
# File 'lib/pdfcrowd.rb', line 185

def setVerticalMargin(value)
    @fields['margin_top'] = @fields['margin_bottom'] = value.to_s()
end

#setWatermark(url, offset_x = 0, offset_y = 0) ⇒ Object



326
327
328
329
330
# File 'lib/pdfcrowd.rb', line 326

def setWatermark(url, offset_x=0, offset_y=0)
    @fields["watermark_url"] = url
    @fields["watermark_offset_x"] = offset_x
    @fields["watermark_offset_y"] = offset_y
end

#setWatermarkInBackground(val = True) ⇒ Object



336
337
338
# File 'lib/pdfcrowd.rb', line 336

def setWatermarkInBackground(val=True)
    @fields["watermark_in_background"] = val
end

#setWatermarkRotation(angle) ⇒ Object



332
333
334
# File 'lib/pdfcrowd.rb', line 332

def setWatermarkRotation(angle)
    @fields["watermark_rotation"] = angle
end

#usePrintMedia(value = true) ⇒ Object



260
261
262
# File 'lib/pdfcrowd.rb', line 260

def usePrintMedia(value=true)
    @fields['use_print_media'] = value
end

#useSSL(use_ssl) ⇒ Object



160
161
162
163
# File 'lib/pdfcrowd.rb', line 160

def useSSL(use_ssl)
    @use_ssl = use_ssl
    @api_uri = use_ssl ? HTTPS_API_URI : HTTP_API_URI
end