Docx to jpg python

DOCX to JPG Python API

Convert DOCX files to JPG images using our Python DOCX to JPG API.

Why PSPDFKit API?

SOC 2 Compliant

Build the workflows you need without worrying about security. We don’t store any document data, and our API endpoints are served through encrypted connections.

Easy Integration

Get up and running in hours, not weeks. Access well-documented APIs and code samples that make integrating with your existing workflows a snap.

One Document, Endless Actions

With access to more than 30 tools, you can process one document in multiple ways by combining API actions. Convert, OCR, rotate, and watermark with one API call.

Simple and Transparent Pricing

Pay only for the number of documents you process. You won’t need to consider file size, datasets being merged, or different API actions being called.

Try It Out

This example will convert your uploaded DOCX file to a JPG image.

Use Your Free API Calls

Sign up to process 100 documents per month for free, or log in to automatically add your API key to sample code.

Add a File

Add a DOCX file named document.docx to your project folder. You can also use our sample file.

The file name is case sensitive. Make sure the file name matches the file name in the sample code. The file name is case sensitive. Make sure the file name matches the file name in the sample code.

Run the Code

Copy the code and run it from the same folder you added the files to. For more information, see our language-specific getting started guides.

View the Results

Open image.jpg in your project folder to view the results.

curl -X POST https://api.pspdfkit.com/build \ -H "Authorization: Bearer your_api_key_here" \ -o image.jpg \ --fail \ -F document=@document.docx \ -F instructions=' < "parts": [ < "file": "document" >], "output": < "type": "image", "format": "jpg", "dpi": 500 >>' 
curl -X POST https://api.pspdfkit.com/build ^ -H "Authorization: Bearer your_api_key_here" ^ -o image.jpg ^ --fail ^ -F document=@document.docx ^ -F instructions="], \"output\": >" 
package com.example.pspdfkit; import java.io.File; import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import org.json.JSONArray; import org.json.JSONObject; import okhttp3.MediaType; import okhttp3.MultipartBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; public final class PspdfkitApiExample < public static void main(final String[] args) throws IOException < final RequestBody body = new MultipartBody.Builder() .setType(MultipartBody.FORM) .addFormDataPart( "document", "document.docx", RequestBody.create( new File("document.docx"), MediaType.parse("application/vnd.openxmlformats-officedocument.wordprocessingml.document") ) ) .addFormDataPart( "instructions", new JSONObject() .put("parts", new JSONArray() .put(new JSONObject() .put("file", "document") ) ) .put("output", new JSONObject() .put("type", "image") .put("format", "jpg") .put("dpi", 500) ).toString() ) .build(); final Request request = new Request.Builder() .url("https://api.pspdfkit.com/build") .method("POST", body) .addHeader("Authorization", "Bearer your_api_key_here") .build(); final OkHttpClient client = new OkHttpClient() .newBuilder() .build(); final Response response = client.newCall(request).execute(); if (response.isSuccessful()) < Files.copy( response.body().byteStream(), FileSystems.getDefault().getPath("image.jpg"), StandardCopyOption.REPLACE_EXISTING ); >else < // Handle the error throw new IOException(response.body().string()); >> > 
using System; using System.IO; using System.Net; using RestSharp; namespace PspdfkitApiDemo < class Program < static void Main(string[] args) < var client = new RestClient("https://api.pspdfkit.com/build"); var request = new RestRequest(Method.POST) .AddHeader("Authorization", "Bearer your_api_key_here") .AddFile("document", "document.docx") .AddParameter("instructions", new JsonObject < ["parts"] = new JsonArray < new JsonObject < ["file"] = "document" >>, ["output"] = new JsonObject < ["type"] = "image", ["format"] = "jpg", ["dpi"] = 500 >>.ToString()); request.AdvancedResponseWriter = (responseStream, response) => < if (response.StatusCode == HttpStatusCode.OK) < using (responseStream) < using var outputFileWriter = File.OpenWrite("image.jpg"); responseStream.CopyTo(outputFileWriter); >> else < var responseStreamReader = new StreamReader(responseStream); Console.Write(responseStreamReader.ReadToEnd()); >>; client.Execute(request); > > > 
// This code requires Node.js. Do not run this code directly in a web browser. const axios = require('axios') const FormData = require('form-data') const fs = require('fs') const formData = new FormData() formData.append('instructions', JSON.stringify( < parts: [ < file: "document" >], output: < type: "image", format: "jpg", dpi: 500 >>)) formData.append('document', fs.createReadStream('document.docx')) ;(async () => < try < const response = await axios.post('https://api.pspdfkit.com/build', formData, < headers: formData.getHeaders(< 'Authorization': 'Bearer your_api_key_here' >), responseType: "stream" >) response.data.pipe(fs.createWriteStream("image.jpg")) > catch (e) < const errorString = await streamToString(e.response.data) console.log(errorString) >>)() function streamToString(stream) < const chunks = [] return new Promise((resolve, reject) => < stream.on("data", (chunk) =>chunks.push(Buffer.from(chunk))) stream.on("error", (err) => reject(err)) stream.on("end", () => resolve(Buffer.concat(chunks).toString("utf8"))) >) > 
import requests import json instructions = < 'parts': [ < 'file': 'document' >], 'output': < 'type': 'image', 'format': 'jpg', 'dpi': 500 >> response = requests.request( 'POST', 'https://api.pspdfkit.com/build', headers = < 'Authorization': 'Bearer your_api_key_here' >, files = < 'document': open('document.docx', 'rb') >, data = < 'instructions': json.dumps(instructions) >, stream = True ) if response.ok: with open('image.jpg', 'wb') as fd: for chunk in response.iter_content(chunk_size=8096): fd.write(chunk) else: print(response.text) exit() 
 ], "output": < "type": "image", "format": "jpg", "dpi": 500 >>'; curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.pspdfkit.com/build', CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_POSTFIELDS => array( 'instructions' => $instructions, 'document' => new CURLFILE('document.docx') ), CURLOPT_HTTPHEADER => array( 'Authorization: Bearer your_api_key_here' ), CURLOPT_FILE => $FileHandle, )); $response = curl_exec($curl); curl_close($curl); fclose($FileHandle); 

Using Postman? Download our official collection and start using the API with a single click. Read more →

Читайте также:  Абсолютный адрес

Your API Key

Get access to your API key when you create an account. Once your account has been created, you’ll be able to process 100 documents per month for free using any of our API tools.

Your API key has automatically been inserted into the API example code. Run the sample code in your terminal to execute the API call.

Источник

Convert Word to JPEG, PNG, or GIF Image File in Python

Convert Word to JPEG, PNG, or GIF Image File in Python

Word is one of the popular formats for sharing and printing documents. We often need to convert word documents to different image formats. It is better to use already developed specialized tools that provide an easily maintainable, flexible conversion solution to your needs. In this article, we will learn how to convert word to JPEG, PNG, or GIF image file in Python.

The following topics shall be covered in this article:

Word to Images Conversion REST API — Python SDK#

For converting JPG, PNG and GIF images in Python, we will be using the Ruby SDK of GroupDocs.Conversion Cloud API. Python SDK of GroupDocs.Conversion provides the best way to convert Word DOCX to JPG, PNG and GIF files in seconds. It is 100% free, secure and easy to use Python SDK for files conversion. It allows converting documents of supported formats to image programmatically on the cloud. You can install it using the following command in the console:

pip install groupdocs_conversion_cloud 

Firstly, get your Client ID and Secret from the dashboard before following the below mentioned steps. Once you have your ID and secret, add below code in your application as shown below:

Читайте также:  Язык программирования java статьи

How to Convert Word to JPEG using REST API in Python#

You can convert Word to JPEG format programmatically by following the steps given below:

  • Firstly, create an instance of the ConvertApi
  • Next, create an instance of the ConvertSettings
  • Then, set the storage name and word file path
  • Set resultant image file format as “jpeg”
  • Create an instance of the DocxLoadOptions
  • Set the word file password and load_options
  • Create an instance of the JpegConvertOptions
  • Define the grayscale, from_page, pages_count, quality, rotate_angle and use_pdf etc
  • Set convertOptions to settings
  • Now, provide the output file path
  • After that, create ConvertDocumentRequest with ConvertSettings as argument
  • Finally, call the ConvertApi.convert_document() method with ConvertDocumentRequest to save the converted file

The following example code demonstrate how to convert word documents to JPEG image format using REST API in Python:

The above code sample will save the converted JPEG file on the cloud.

Convert DOC/DOCX to PNG in Python using REST API#

You can also convert Word Doc/Docx to PNG file format programmatically by following the steps given below:

  • Create an instance of the ConvertApi
  • Next, create an instance of the ConvertSettings
  • Then, set the storage name and word file path
  • Also, set “png” as output image format
  • Create an instance of the DocxLoadOptions
  • Set the word file password and load_options
  • Create an instance of the PngConvertOptions
  • Define the grayscale, from_page, pages_count, quality, rotate_angle and use_pdf values
  • Set convertOptions to settings
  • Now, provide the output file path
  • After that, create ConvertDocumentRequest with ConvertSettings as argument
  • Finally, call the ConvertApi.convert_document() method with ConvertDocumentRequest to save the converted file

The following example code shows how to convert word to PNG format using REST API in Python:

Convert Word DOC/DOCX to GIF in Python using REST API#

You can convert Word Docx to JPG programmatically by following the steps given below:

  • Create an instance of the ConvertApi
  • Next, create an instance of the ConvertSettings
  • Then, set the storage name and word file path
  • Now, provide “gif” as output image format
  • Create an instance of the DocxLoadOptions
  • Set the word file password and load_options
  • Create an instance of the GifConvertOptions
  • Define the grayscale, from_page, pages_count, quality, rotate_angle and use_pdf etc.
  • Set convertOptions to settings
  • Next, provide the output file path
  • After that, create ConvertDocumentRequest with ConvertSettings as argument.
  • Finally, call the ConvertApi.convert_document() method with ConvertDocumentRequest to save the converted file.

The following code sample shows how to convert word Doc/Docx to GIF image file format using REST API in Python:

Online Word to Image Converter for Free#

Please try the following free online JPG, PNG and GIF conversion tool, which is developed using the above API.

Conclusion#

In this article, we have learned how to convert word to image formats on the cloud. Now you know:

  • how to convert word documents to jpeg/jpg in Python;
  • how to convert word doc/docx to png image format using Python;
  • how to convert word doc/docx to gif file format in Python;
Читайте также:  Удаление всех пробелов java

You can learn more about GroupDocs.Conversion Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser.

Ask a question#

If you have any questions about word docx to image converter, please feel free to ask us on the Free Support Forum.

See Also#

Источник

Convert Word Documents to PNG, JPEG, or BMP in Python

Word to PNG JPEG BMP using Python

The conversion of MS Word files to image formats lets you embed the document’s pages into your web or desktop applications. In order to perform this conversion from within the Python applications, this article covers how to convert Word DOCX or DOC files to PNG, JPEG, or BMP images using Python. Moreover, you will learn how to control the Word to image conversion using different options.

Python API for Word to Image Conversion#

To convert Word documents to PNG. JPEG, or BMP images, we will use Aspose.Words for Python. It is a powerful Python library to create, process, and convert MS Word documents. Aspose.Words for Python is available on PyPI and you can install it using the following pip command.

Convert a Word Document to PNG, JPEG, or BMP in Python#

It is quite easier to convert a Word document to popular images formats using Aspose.Words for Python. You can opt for the desired output image format from PNG, JPEG, and BMP. The following are the steps to convert a Word document to a PNG image using Python.

  • Load the Word document using Document class.
  • Specify the output image format using ImageSaveOptions class.
  • Loop through the page count in the document.
  • Convert each page in Word document to PNG image using Document.save(string, ImageSaveOptions) method.

The following code sample shows how to convert a Word document to PNG images in Python.

Control Word to Image Conversion in Python#

You can also control the Word to image conversion using different options. For example, you can set horizontal resolution, vertical resolution, overall resolution, scale, pixel format, brightness, color mode, contrast, and paper color. The following are the steps to use the above-mentioned features in Word to image conversion using Python.

  • Load the Word document using Document class.
  • Specify the output image format using ImageSaveOptions class.
  • Set desired options such as ImageSaveOptions.image_brightness, ImageSaveOptions.image_brightness, etc.
  • Loop through the page count in the document.
  • Convert each page to image using Document.save(string, ImageSaveOptions) method.

The following code sample shows how to control Word to JPEG image conversion using different options.

Get a Free API License#

You can get a temporary license in order to use Aspose.Words for Python without evaluation limitations.

Conclusion#

In this article, you have learned how to convert Word documents to PNG, JPEG, or BMP images using Python. Moreover, you have seen how to control Word to image conversion using different options. Apart from that, you can explore other features offered by Aspose.Words for Python using the documentation. Also, you can post your questions on our forum.

See Also#

Info: You may be interested in another Python API (Aspose.Slides for Python via NET) that allows you to convert presentations to images and import images into presentations.

Источник

Оцените статью