Convert from PDF

Convert your PDF document to Word, Excel, PowerPoint, and eBook formats. API provides an OCR option to produce searchable PDFs with copiable text from scanned documents as well.

Offers conversion with below output options:

  • Microsoft Word
  • Microsoft Excel
  • Microsoft PowerPoint
  • PDF with OCR
  • ePUB
  • MOBI

Depending on the need Quality type can be set as Draft or High. High quality implements advanced OCR and costs 2 API calls per page.

Code Samples

Try the API in the language you prefer

  • C#
  • Java
  • JavaScript
  • PHP
  • Python
  • Ruby
// setup convertFromPdf object
var convertFromPdf = new ConvertFromPdf()
{
    // document
    Document = new Document()
    {
        DocData = File.ReadAllBytes("myPdf.pdf"),
        Name = "myPdf.pdf",
    },
    // action
    ConvertFromPdfAction = new ConvertFromPdfAction()
    {
        OutputFormat = ConvertFromPdfActionOutputFormat.PdfOcr,
        QualityType = ConvertFromPdfActionQualityType.High
    },
};

// conversion
var res = await Pdf4meClient.Pdf4me.Instance.ConvertFromPdfClient.ConvertFromPdfAsync(convertFromPdf);

// extract the generated PDF and write it to disk
byte[] generatedPdf = res.Document.DocData;
File.WriteAllBytes("generatedPdf.pdf", generatedPdf);
import fs from 'fs'
import pdf4me from 'pdf4me-js'

async function callpdf4me() {
  const pdf4meClient = pdf4me.createClient('api-key')

  // setup convertFromPdf object
  const convertReq = {
    // document
    document: {
      docData: fs.readFileSync('myPdf.pdf').toString('base64'),
      name: 'myPdf.pdf',
    },
    // action
    convertFromPdfAction: {
      outputFormat: 'pdfOcr',
      qualityType: 'high',
    },
  }
  // conversion
  const convertFromPdfRes = await pdf4meClient.convertFromPdf(convertReq)

  // extract the generated PDF and write it to disk
  fs.writeFileSync(
    convertFromPdfRes.document.name,
    Buffer.from(convertFromPdfRes.document.docData, 'base64')
  )
}

callpdf4me()
import base64
import datetime
import os
from pdf4me.client.pdf4me_client import Pdf4meClient
from pdf4me.client.convert_client import  ConvertClient
from pdf4me.model import ConvertFromPdf, Document, ConvertFromPdfAction
from pdf4me.helper.file_reader import FileReader

""" Pass token as argument """
pdf4me_client = Pdf4meClient(token='')

# setup the convert_client
convert_client = ConvertClient(pdf4me_client)

# create the convert_to_pdf object
convert_from_pdf = ConvertFromPdf(
    document=Document(
        doc_data=FileReader().get_file_data('myPdf.pdf'),
        name='myPdf.pdf'
        ),
    convert_from_pdf_action=ConvertFromPdfAction(
        output_format='pdfOcr',
        quality_type='high'
        )
    )

# conversion
res = convert_client.convert_from_pdf(convert_from_pdf=convert_from_pdf)

# extracting the generated PDF
generated_pdf = base64.b64decode(res['document']['doc_data'])
# writing it to disk
with open('pdfOcr.pdf', 'wb') as f:
    f.write(generated_pdf)

Important links

Swagger: Convert from PDF