Convert PDF files (RUBY REST)

Skip to end of metadata
Go to start of metadata
This example allows you to convert a PDF file to any supported format using Saaspose.Pdf REST API in your RUBY applications.
In case of PDF to HTML, Saaspose service returns the output as a ZIP file because there can be multiple supporting files in the output.
We're referring to the following common methods to perform general operations:


Convert PDF to HTML


begin
require_relative 'saaspose_common'

productURI = 'http://api.saaspose.com/v1.0'
Common::Product.setBaseProductUri(productURI)

appSID = '77*************************'
appKey = '89************************'

Common::SaasposeApp.new(appSID,appKey)

filePath = 'C:/Sample.pdf'
fileName = File.basename(filePath)

# Upload input Word document
urlFile = 'http://api.saaspose.com/v1.0/storage/file/' + fileName
signedURI = Common::Utils.sign(urlFile)
#RestClient.put( signedURI,File.new(filePath, 'rb'))

p 'Input PDF document uploaded successfully'
		
#build URI to convert to TIFF
strURI = 'http://api.saaspose.com/v1.0/pdf/' + fileName + '?format=html' 
			
#sign URI
signedURI = Common::Utils.sign(strURI)

#Download and save output TIFF
responseStream = RestClient.get(signedURI, :accept => 'application/json')
Common::Utils.saveFile(responseStream, "C:/Output.zip")

p 'File converted'
rescue Exception=>e
print e
end

gets()

Convert PDF to any supported format excluding HTML

begin
require_relative 'saaspose_common'

productURI = 'http://api.saaspose.com/v1.0'
Common::Product.setBaseProductUri(productURI)

appSID = '77**********************'
appKey = '89********************'

Common::SaasposeApp.new(appSID,appKey)

filePath = 'C:/Sample.pdf'
fileName = File.basename(filePath)

# Upload input Word document
urlFile = 'http://api.saaspose.com/v1.0/storage/file/' + fileName
signedURI = Common::Utils.sign(urlFile)
RestClient.put( signedURI,File.new(filePath, 'rb'))

p 'Input PDF document uploaded successfully'
		
#build URI to convert to TIFF
strURI = 'http://api.saaspose.com/v1.0/pdf/' + fileName + '?format=tiff' 
			
#sign URI
signedURI = Common::Utils.sign(strURI)

#Download and save output TIFF
responseStream = RestClient.get(signedURI, :accept => 'application/json')
Common::Utils.saveFile(responseStream, "C:/Output.tiff")

p 'File converted'
rescue Exception=>e
print e
end

gets()
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.