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) ⇒ Client

Client constructor.

username – your username at Pdfcrowd apikey – your API key



68
69
70
71
72
73
74
# File 'lib/pdfcrowd.rb', line 68

def initialize(username, apikey)
  useSSL(false)
  @fields  = {  
    'username' => username,
    'key' => apikey 
  }
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.


105
106
107
# File 'lib/pdfcrowd.rb', line 105

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.


94
95
96
# File 'lib/pdfcrowd.rb', line 94

def convertHtml(content, outstream=nil)
    return convert(outstream, 'html', content)
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.


83
84
85
# File 'lib/pdfcrowd.rb', line 83

def convertURI(uri, outstream=nil)
    return convert(outstream, 'uri', uri)
end

#enableBackgrounds(value = true) ⇒ Object



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

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


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

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

#enableImages(value = true) ⇒ Object



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

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

#enableJavaScript(value = true) ⇒ Object



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

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

#enablePdfcrowdLogo(value = true) ⇒ Object



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

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

#numTokensObject

Returns the number of available conversion tokens.



112
113
114
115
116
# File 'lib/pdfcrowd.rb', line 112

def numTokens()
  uri = @api_uri + 'user/%s/tokens/' % @fields['username']
  response = call_api(uri, nil)
  return Integer(response)
end

#setApiKey(key) ⇒ Object



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

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

#setDefaultTextEncoding(value) ⇒ Object



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

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

#setEncrypted(val = true) ⇒ Object



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

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

#setFooterHtml(value) ⇒ Object



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

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

#setFooterText(value) ⇒ Object



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

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

#setFooterUrl(value) ⇒ Object



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

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

#setHeaderHtml(value) ⇒ Object



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

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

#setHeaderUrl(value) ⇒ Object



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

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

#setHorizontalMargin(value) ⇒ Object



139
140
141
# File 'lib/pdfcrowd.rb', line 139

def setHorizontalMargin(value)
    @fields['hmargin'] = value
end

#setHtmlZoom(value) ⇒ Object



194
195
196
# File 'lib/pdfcrowd.rb', line 194

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

#setInitialPdfExactZoom(value) ⇒ Object



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

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

#setInitialPdfZoomType(value) ⇒ Object



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

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

#setMaxPages(value) ⇒ Object



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

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

#setNoCopy(val = true) ⇒ Object



167
168
169
# File 'lib/pdfcrowd.rb', line 167

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

#setNoModify(val = true) ⇒ Object



163
164
165
# File 'lib/pdfcrowd.rb', line 163

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

#setNoPrint(val = true) ⇒ Object



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

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

#setOwnerPassword(pwd) ⇒ Object



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

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

#setPageHeight(value) ⇒ Object



135
136
137
# File 'lib/pdfcrowd.rb', line 135

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

#setPageLayout(value) ⇒ Object



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

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

#setPageMode(value) ⇒ Object



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

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

#setPageWidth(value) ⇒ Object



131
132
133
# File 'lib/pdfcrowd.rb', line 131

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

#setPdfScalingFactor(value) ⇒ Object



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

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

#setUsername(username) ⇒ Object



123
124
125
# File 'lib/pdfcrowd.rb', line 123

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

#setUserPassword(pwd) ⇒ Object



151
152
153
# File 'lib/pdfcrowd.rb', line 151

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

#setVerticalMargin(value) ⇒ Object



143
144
145
# File 'lib/pdfcrowd.rb', line 143

def setVerticalMargin(value)
    @fields['vmargin'] = value
end

#usePrintMedia(value = true) ⇒ Object



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

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

#useSSL(use_ssl) ⇒ Object



118
119
120
121
# File 'lib/pdfcrowd.rb', line 118

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