Convert to PDF

Convert any of your digital document or Image formats to PDF.

For example, take your MS Word document (Doc or DOCX) and call this API to convert it to PDF. The API feature offers easy conversion of common work documents like Word, Excel, or Powerpoint to PDF.

You can easily convert the following Non-PDF documents:

  • MS Word, Excel, PowerPoint
  • Open Office, Libre Office
  • Email (MSG, EML, MIME)
  • Plain Text (ASCII, UNICODE), WordPerfect
  • Image Formats: BMP, GIF, JPEG, PNG, TIFF, JB2, JP2, JPX, PBM

Documents with additional settings like Macros, merge fields or interactive forms may not be converted properly.

Depending on the type of filename, the source file type is recognized and converted to PDF.

Code Samples

Try the API in the language you prefer

  • Curl
  • C#
  • Java
  • JavaScript
  • PHP
  • Python
  • Ruby
// setup convertToPdf object
var convertToPdf = new ConvertToPdf()
{
    // document
    Document = new Document()
    {
        DocData = File.ReadAllBytes("myWordDoc.docx"),
        Name = "myWordDoc.docx",
    },
    // action
    ConvertToPdfAction = new ConvertToPdfAction()
};

// conversion
var res = await Pdf4meClient.Pdf4me.Instance.ConvertClient.ConvertToPdfAsync(convertToPdf);

// extract the generated PDF and write it to disk
byte[] generatedPdf = res.Document.DocData;
File.WriteAllBytes("generatedPdf.pdf", generatedPdf);
// setup the convertClient
ConvertClient convertClient = new ConvertClient(pdf4meClient);

// setup convertToPdf object
ConvertToPdf convertToPdf = new ConvertToPdf();
// document
Document document = new Document();
document.setDocData(Files.readAllBytes(Paths.get("myWordDoc.docx")));
document.setName("myWordDoc.docx");
convertToPdf.setDocument(document);
// action
convertToPdf.setConvertToPdfAction(new ConvertToPdfAction());

// conversion
ConvertToPdfRes res = convertClient.convertToPdf(convertToPdf);

// extracting the generated PDF and writing it to disk
byte[] generatedPdf = res.getDocument().getDocData();
FileUtils.writeByteArrayToFile(new File("generatedPdf.pdf"), generatedPdf);
// create pdf4meClient
const pdf4meClient = pdf4me.createClient('YOUR API KEY')

// create convertToPdf object
const convertToPdfReq = {
  // document
  document: {
    docData: fs.readFileSync(path.join(__dirname, 'myWordDoc.docx')).toString('base64'),
    name: 'myWordDoc.docx',
  },
  // action
  convertToPdfAction: {
    pdfConformance: 'pdfA1',
    conversionMode: 'fast',
  },
}

// conversion
pdf4meClient.convertToPdf(convertToPdfReq)
  .then(function(convertToPdfRes) {
    // extract the generated PDF and write it to disk
    const pdfDocument = Buffer.from(convertToPdfRes.document.docData, 'base64')
    fs.writeFileSync(path.join(__dirname, 'generatedPdf.pdf'), pdfDocument)
  })
  .catch(err => {
    console.log(err)
  })
# setup the convert_client
convert_client = ConvertClient(pdf4me_client)

# create the convert_to_pdf object
convert_to_pdf = ConvertToPdf(
    document=Document(
        doc_data=FileReader().get_file_data('myWordDoc.docx'),
        name='myWordDoc.docx'
    ),
    convert_to_pdf_action=ConvertToPdfAction()
)

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

# extracting the generated PDF
generated_pdf = base64.b64decode(res['document']['doc_data'])
# writing it to disk
with open('generatedPdf.pdf', 'wb') as f:
    f.write(generated_pdf)
// setup the convert_client
$client = new pdf4meAPI($token);

// conversion
$res = $client->pdf4me()->convertToPdf([
        // document
        "document"=> [
            "name"=> "myWordDoc.docx",
            "docData" => $client->getFileData('myWordDoc.docx')
        ],
        //action
        "convertAction"=>[]
    ]);

// extract the generated PDF and write it to disk
$generatedPdf = base64_decode($res->document->docData);
file_put_contents('generatedPdf.pdf', $generatedPdf);
file = '/path/to/file/myWordDoc.docx'

a = Pdf4me::ConvertToPdf.new(
    document: Pdf4me::Document.new(
      doc_data: Base64.encode64(File.open(file, 'rb', &:read)),
      name: "myWordDoc.docx"
    ),
    convert_to_pdf_action: Pdf4me::ConvertToPdfAction.new
  )
response = a.run

File.open('generatedPdf.pdf', 'wb') do |f|
       f.write(Base64.decode64(response.document.doc_data))
end

Important Links

Swagger

ConvertToPdf
NameTypeDescriptionNotes
document

Document

convertToPdfAction

ConvertToPdfAction

jobId

String

[optional]

Document
NameTypeDescriptionNotes
jobId

string

JobId of Documents Working set

documentId

string

Document Id

name

string

Filename including filetype.

docData

byte[]

File data