Class: Pdfcrowd::PdfToPdfClient

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

Overview

Conversion from PDF to PDF.

Instance Method Summary collapse

Constructor Details

#initialize(user_name, api_key) ⇒ PdfToPdfClient

Returns a new instance of PdfToPdfClient.



3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
# File 'lib/pdfcrowd.rb', line 3210

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

#addAttachment(attachment) ⇒ Object



3447
3448
3449
3450
3451
3452
3453
3454
3455
# File 'lib/pdfcrowd.rb', line 3447

def addAttachment(attachment)
    if (!(File.file?(attachment) && !File.zero?(attachment)))
        raise Error.new(Pdfcrowd.create_invalid_value_message(attachment, "addAttachment", "pdf-to-pdf", "The file must exist and not be empty.", "add_attachment"), 470);
    end
    
    @files['attachment_%s' % @file_id] = attachment
    @file_id += 1
    self
end

#addPdfFile(file_path) ⇒ Object



3253
3254
3255
3256
3257
3258
3259
3260
3261
# File 'lib/pdfcrowd.rb', line 3253

def addPdfFile(file_path)
    if (!(File.file?(file_path) && !File.zero?(file_path)))
        raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "addPdfFile", "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(data) ⇒ Object



3264
3265
3266
3267
3268
3269
3270
3271
3272
# File 'lib/pdfcrowd.rb', line 3264

def addPdfRawData(data)
    if (!(!data.nil? && data.length > 300 and data[0...4] == '%PDF'))
        raise Error.new(Pdfcrowd.create_invalid_value_message("raw PDF data", "addPdfRawData", "pdf-to-pdf", "The input data must be PDF content.", "add_pdf_raw_data"), 470);
    end
    
    @raw_data['f_%s' % @file_id] = data
    @file_id += 1
    self
end

#convertObject



3232
3233
3234
# File 'lib/pdfcrowd.rb', line 3232

def convert()
    @helper.post(@fields, @files, @raw_data)
end

#convertToFile(file_path) ⇒ Object



3242
3243
3244
3245
3246
3247
3248
3249
3250
# File 'lib/pdfcrowd.rb', line 3242

def convertToFile(file_path)
    if (!(!file_path.nil? && !file_path.empty?))
        raise Error.new(Pdfcrowd.create_invalid_value_message(file_path, "convertToFile", "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



3237
3238
3239
# File 'lib/pdfcrowd.rb', line 3237

def convertToStream(out_stream)
    @helper.post(@fields, @files, @raw_data, out_stream)
end

#getConsumedCreditCountObject



3566
3567
3568
# File 'lib/pdfcrowd.rb', line 3566

def getConsumedCreditCount()
    return @helper.getConsumedCreditCount()
end

#getDebugLogUrlObject



3556
3557
3558
# File 'lib/pdfcrowd.rb', line 3556

def getDebugLogUrl()
    return @helper.getDebugLogUrl()
end

#getJobIdObject



3571
3572
3573
# File 'lib/pdfcrowd.rb', line 3571

def getJobId()
    return @helper.getJobId()
end

#getOutputSizeObject



3581
3582
3583
# File 'lib/pdfcrowd.rb', line 3581

def getOutputSize()
    return @helper.getOutputSize()
end

#getPageCountObject



3576
3577
3578
# File 'lib/pdfcrowd.rb', line 3576

def getPageCount()
    return @helper.getPageCount()
end

#getRemainingCreditCountObject



3561
3562
3563
# File 'lib/pdfcrowd.rb', line 3561

def getRemainingCreditCount()
    return @helper.getRemainingCreditCount()
end

#getVersionObject



3586
3587
3588
# File 'lib/pdfcrowd.rb', line 3586

def getVersion()
    return "client " + CLIENT_VERSION + ", API v2, converter " + @helper.getConverterVersion()
end

#setAction(action) ⇒ Object



3222
3223
3224
3225
3226
3227
3228
3229
# File 'lib/pdfcrowd.rb', line 3222

def setAction(action)
    unless /(?i)^(join|shuffle|extract|delete)$/.match(action)
        raise Error.new(Pdfcrowd.create_invalid_value_message(action, "setAction", "pdf-to-pdf", "Allowed values are join, shuffle, extract, delete.", "set_action"), 470);
    end
    
    @fields['action'] = action
    self
end

#setAuthor(author) ⇒ Object



3425
3426
3427
3428
# File 'lib/pdfcrowd.rb', line 3425

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

#setCenterWindow(value) ⇒ Object



3532
3533
3534
3535
# File 'lib/pdfcrowd.rb', line 3532

def setCenterWindow(value)
    @fields['center_window'] = value
    self
end

#setClientUserAgent(agent) ⇒ Object



3613
3614
3615
3616
# File 'lib/pdfcrowd.rb', line 3613

def setClientUserAgent(agent)
    @helper.setUserAgent(agent)
    self
end

#setConverterVersion(version) ⇒ Object



3597
3598
3599
3600
3601
3602
3603
3604
# File 'lib/pdfcrowd.rb', line 3597

def setConverterVersion(version)
    unless /(?i)^(24.04|20.10|18.10|latest)$/.match(version)
        raise Error.new(Pdfcrowd.create_invalid_value_message(version, "setConverterVersion", "pdf-to-pdf", "Allowed values are 24.04, 20.10, 18.10, latest.", "set_converter_version"), 470);
    end
    
    @helper.setConverterVersion(version)
    self
end

#setDebugLog(value) ⇒ Object



3550
3551
3552
3553
# File 'lib/pdfcrowd.rb', line 3550

def setDebugLog(value)
    @fields['debug_log'] = value
    self
end

#setDisplayTitle(value) ⇒ Object



3538
3539
3540
3541
# File 'lib/pdfcrowd.rb', line 3538

def setDisplayTitle(value)
    @fields['display_title'] = value
    self
end

#setEncrypt(value) ⇒ Object



3377
3378
3379
3380
# File 'lib/pdfcrowd.rb', line 3377

def setEncrypt(value)
    @fields['encrypt'] = value
    self
end

#setFitWindow(value) ⇒ Object



3526
3527
3528
3529
# File 'lib/pdfcrowd.rb', line 3526

def setFitWindow(value)
    @fields['fit_window'] = value
    self
end

#setHideMenubar(value) ⇒ Object



3514
3515
3516
3517
# File 'lib/pdfcrowd.rb', line 3514

def setHideMenubar(value)
    @fields['hide_menubar'] = value
    self
end

#setHideToolbar(value) ⇒ Object



3508
3509
3510
3511
# File 'lib/pdfcrowd.rb', line 3508

def setHideToolbar(value)
    @fields['hide_toolbar'] = value
    self
end

#setHideWindowUi(value) ⇒ Object



3520
3521
3522
3523
# File 'lib/pdfcrowd.rb', line 3520

def setHideWindowUi(value)
    @fields['hide_window_ui'] = value
    self
end

#setInitialPage(page) ⇒ Object



3488
3489
3490
3491
3492
3493
3494
3495
# File 'lib/pdfcrowd.rb', line 3488

def setInitialPage(page)
    if (!(Integer(page) > 0))
        raise Error.new(Pdfcrowd.create_invalid_value_message(page, "setInitialPage", "pdf-to-pdf", "Must be a positive integer.", "set_initial_page"), 470);
    end
    
    @fields['initial_page'] = page
    self
end

#setInitialZoom(zoom) ⇒ Object



3498
3499
3500
3501
3502
3503
3504
3505
# File 'lib/pdfcrowd.rb', line 3498

def setInitialZoom(zoom)
    if (!(Integer(zoom) > 0))
        raise Error.new(Pdfcrowd.create_invalid_value_message(zoom, "setInitialZoom", "pdf-to-pdf", "Must be a positive integer.", "set_initial_zoom"), 470);
    end
    
    @fields['initial_zoom'] = zoom
    self
end

#setInitialZoomType(zoom_type) ⇒ Object



3478
3479
3480
3481
3482
3483
3484
3485
# File 'lib/pdfcrowd.rb', line 3478

def setInitialZoomType(zoom_type)
    unless /(?i)^(fit-width|fit-height|fit-page)$/.match(zoom_type)
        raise Error.new(Pdfcrowd.create_invalid_value_message(zoom_type, "setInitialZoomType", "pdf-to-pdf", "Allowed values are fit-width, fit-height, fit-page.", "set_initial_zoom_type"), 470);
    end
    
    @fields['initial_zoom_type'] = zoom_type
    self
end

#setInputPdfPassword(password) ⇒ Object



3275
3276
3277
3278
# File 'lib/pdfcrowd.rb', line 3275

def setInputPdfPassword(password)
    @fields['input_pdf_password'] = password
    self
end

#setKeywords(keywords) ⇒ Object



3431
3432
3433
3434
# File 'lib/pdfcrowd.rb', line 3431

def setKeywords(keywords)
    @fields['keywords'] = keywords
    self
end

#setLinearize(value) ⇒ Object



3371
3372
3373
3374
# File 'lib/pdfcrowd.rb', line 3371

def setLinearize(value)
    @fields['linearize'] = value
    self
end

#setMultipageBackground(background) ⇒ Object



3351
3352
3353
3354
3355
3356
3357
3358
# File 'lib/pdfcrowd.rb', line 3351

def setMultipageBackground(background)
    if (!(File.file?(background) && !File.zero?(background)))
        raise Error.new(Pdfcrowd.create_invalid_value_message(background, "setMultipageBackground", "pdf-to-pdf", "The file must exist and not be empty.", "set_multipage_background"), 470);
    end
    
    @files['multipage_background'] = background
    self
end

#setMultipageBackgroundUrl(url) ⇒ Object



3361
3362
3363
3364
3365
3366
3367
3368
# File 'lib/pdfcrowd.rb', line 3361

def setMultipageBackgroundUrl(url)
    unless /(?i)^https?:\/\/.*$/.match(url)
        raise Error.new(Pdfcrowd.create_invalid_value_message(url, "setMultipageBackgroundUrl", "pdf-to-pdf", "Supported protocols are http:// and https://.", "set_multipage_background_url"), 470);
    end
    
    @fields['multipage_background_url'] = url
    self
end

#setMultipageWatermark(watermark) ⇒ Object



3311
3312
3313
3314
3315
3316
3317
3318
# File 'lib/pdfcrowd.rb', line 3311

def setMultipageWatermark(watermark)
    if (!(File.file?(watermark) && !File.zero?(watermark)))
        raise Error.new(Pdfcrowd.create_invalid_value_message(watermark, "setMultipageWatermark", "pdf-to-pdf", "The file must exist and not be empty.", "set_multipage_watermark"), 470);
    end
    
    @files['multipage_watermark'] = watermark
    self
end

#setMultipageWatermarkUrl(url) ⇒ Object



3321
3322
3323
3324
3325
3326
3327
3328
# File 'lib/pdfcrowd.rb', line 3321

def setMultipageWatermarkUrl(url)
    unless /(?i)^https?:\/\/.*$/.match(url)
        raise Error.new(Pdfcrowd.create_invalid_value_message(url, "setMultipageWatermarkUrl", "pdf-to-pdf", "Supported protocols are http:// and https://.", "set_multipage_watermark_url"), 470);
    end
    
    @fields['multipage_watermark_url'] = url
    self
end

#setNoCopy(value) ⇒ Object



3407
3408
3409
3410
# File 'lib/pdfcrowd.rb', line 3407

def setNoCopy(value)
    @fields['no_copy'] = value
    self
end

#setNoModify(value) ⇒ Object



3401
3402
3403
3404
# File 'lib/pdfcrowd.rb', line 3401

def setNoModify(value)
    @fields['no_modify'] = value
    self
end

#setNoPrint(value) ⇒ Object



3395
3396
3397
3398
# File 'lib/pdfcrowd.rb', line 3395

def setNoPrint(value)
    @fields['no_print'] = value
    self
end

#setOwnerPassword(password) ⇒ Object



3389
3390
3391
3392
# File 'lib/pdfcrowd.rb', line 3389

def setOwnerPassword(password)
    @fields['owner_password'] = password
    self
end

#setPageBackground(background) ⇒ Object



3331
3332
3333
3334
3335
3336
3337
3338
# File 'lib/pdfcrowd.rb', line 3331

def setPageBackground(background)
    if (!(File.file?(background) && !File.zero?(background)))
        raise Error.new(Pdfcrowd.create_invalid_value_message(background, "setPageBackground", "pdf-to-pdf", "The file must exist and not be empty.", "set_page_background"), 470);
    end
    
    @files['page_background'] = background
    self
end

#setPageBackgroundUrl(url) ⇒ Object



3341
3342
3343
3344
3345
3346
3347
3348
# File 'lib/pdfcrowd.rb', line 3341

def setPageBackgroundUrl(url)
    unless /(?i)^https?:\/\/.*$/.match(url)
        raise Error.new(Pdfcrowd.create_invalid_value_message(url, "setPageBackgroundUrl", "pdf-to-pdf", "Supported protocols are http:// and https://.", "set_page_background_url"), 470);
    end
    
    @fields['page_background_url'] = url
    self
end

#setPageLayout(layout) ⇒ Object



3458
3459
3460
3461
3462
3463
3464
3465
# File 'lib/pdfcrowd.rb', line 3458

def setPageLayout(layout)
    unless /(?i)^(single-page|one-column|two-column-left|two-column-right)$/.match(layout)
        raise Error.new(Pdfcrowd.create_invalid_value_message(layout, "setPageLayout", "pdf-to-pdf", "Allowed values are single-page, one-column, two-column-left, two-column-right.", "set_page_layout"), 470);
    end
    
    @fields['page_layout'] = layout
    self
end

#setPageMode(mode) ⇒ Object



3468
3469
3470
3471
3472
3473
3474
3475
# File 'lib/pdfcrowd.rb', line 3468

def setPageMode(mode)
    unless /(?i)^(full-screen|thumbnails|outlines)$/.match(mode)
        raise Error.new(Pdfcrowd.create_invalid_value_message(mode, "setPageMode", "pdf-to-pdf", "Allowed values are full-screen, thumbnails, outlines.", "set_page_mode"), 470);
    end
    
    @fields['page_mode'] = mode
    self
end

#setPageRange(pages) ⇒ Object



3281
3282
3283
3284
3285
3286
3287
3288
# File 'lib/pdfcrowd.rb', line 3281

def setPageRange(pages)
    unless /^(?:\s*(?:\d+|(?:\d*\s*\-\s*\d+)|(?:\d+\s*\-\s*\d*))\s*,\s*)*\s*(?:\d+|(?:\d*\s*\-\s*\d+)|(?:\d+\s*\-\s*\d*))\s*$/.match(pages)
        raise Error.new(Pdfcrowd.create_invalid_value_message(pages, "setPageRange", "pdf-to-pdf", "A comma separated list of page numbers or ranges.", "set_page_range"), 470);
    end
    
    @fields['page_range'] = pages
    self
end

#setPageWatermark(watermark) ⇒ Object



3291
3292
3293
3294
3295
3296
3297
3298
# File 'lib/pdfcrowd.rb', line 3291

def setPageWatermark(watermark)
    if (!(File.file?(watermark) && !File.zero?(watermark)))
        raise Error.new(Pdfcrowd.create_invalid_value_message(watermark, "setPageWatermark", "pdf-to-pdf", "The file must exist and not be empty.", "set_page_watermark"), 470);
    end
    
    @files['page_watermark'] = watermark
    self
end

#setPageWatermarkUrl(url) ⇒ Object



3301
3302
3303
3304
3305
3306
3307
3308
# File 'lib/pdfcrowd.rb', line 3301

def setPageWatermarkUrl(url)
    unless /(?i)^https?:\/\/.*$/.match(url)
        raise Error.new(Pdfcrowd.create_invalid_value_message(url, "setPageWatermarkUrl", "pdf-to-pdf", "Supported protocols are http:// and https://.", "set_page_watermark_url"), 470);
    end
    
    @fields['page_watermark_url'] = url
    self
end

#setProxy(host, port, user_name, password) ⇒ Object



3625
3626
3627
3628
# File 'lib/pdfcrowd.rb', line 3625

def setProxy(host, port, user_name, password)
    @helper.setProxy(host, port, user_name, password)
    self
end

#setRetryCount(count) ⇒ Object



3631
3632
3633
3634
# File 'lib/pdfcrowd.rb', line 3631

def setRetryCount(count)
    @helper.setRetryCount(count)
    self
end

#setRightToLeft(value) ⇒ Object



3544
3545
3546
3547
# File 'lib/pdfcrowd.rb', line 3544

def setRightToLeft(value)
    @fields['right_to_left'] = value
    self
end

#setSubject(subject) ⇒ Object



3419
3420
3421
3422
# File 'lib/pdfcrowd.rb', line 3419

def setSubject(subject)
    @fields['subject'] = subject
    self
end

#setTag(tag) ⇒ Object



3591
3592
3593
3594
# File 'lib/pdfcrowd.rb', line 3591

def setTag(tag)
    @fields['tag'] = tag
    self
end

#setTitle(title) ⇒ Object



3413
3414
3415
3416
# File 'lib/pdfcrowd.rb', line 3413

def setTitle(title)
    @fields['title'] = title
    self
end

#setUseHttp(value) ⇒ Object



3607
3608
3609
3610
# File 'lib/pdfcrowd.rb', line 3607

def setUseHttp(value)
    @helper.setUseHttp(value)
    self
end

#setUseMetadataFrom(index) ⇒ Object



3437
3438
3439
3440
3441
3442
3443
3444
# File 'lib/pdfcrowd.rb', line 3437

def setUseMetadataFrom(index)
    if (!(Integer(index) >= 0))
        raise Error.new(Pdfcrowd.create_invalid_value_message(index, "setUseMetadataFrom", "pdf-to-pdf", "Must be a positive integer or 0.", "set_use_metadata_from"), 470);
    end
    
    @fields['use_metadata_from'] = index
    self
end

#setUserAgent(agent) ⇒ Object



3619
3620
3621
3622
# File 'lib/pdfcrowd.rb', line 3619

def setUserAgent(agent)
    @helper.setUserAgent(agent)
    self
end

#setUserPassword(password) ⇒ Object



3383
3384
3385
3386
# File 'lib/pdfcrowd.rb', line 3383

def setUserPassword(password)
    @fields['user_password'] = password
    self
end