Unable to convert pdf to jpg/png

Do you want to: Suggest a feature / Report a bug / Ask a how-to question
For feature suggestions, describe the result you would like to achieve in detail:
For bug reports, provide the steps to reproduce and if possible a minimal demo of the problem:
Use this code:
builder.SetTmpFolder(".")
builder.OpenFile(“test.pdf”);
builder.SaveFile(“jpg”, “image.jpg”);
builder.CloseFile();

Actual result: error (save): file not opened!
Expected result: image.jpg file with first page of pdf.

DocumentBuilder version: 7.4.0
Installation method: installer (docbuilder_x64.exe).
OS: Win 10

可以使用中文描述吗?

I’am sorry, but i dont speak chinese.

Sorry, I thought what you posted was a response to my post

Hello @wolfox

This error usually means that the file wasn’t found. Please check the name of the file that you are opening and the directory that you are setting up a temp folder with SetTmpFolder method.

Also, check out this page to find out how to save the document into image formats:
https://api.onlyoffice.com/docbuilder/integrationapi/net/cdocbuilder/savefile

Update: Document Builder does not support opening of PDF since basically nothing can be done with it. Please use any other format, for instance, DOCX.

By the way, keep in mind that Document Builder does not serve as a conversion service hence cannot perform certain actions as a complete converter.

SaveFile doesn’t support jpg. Ghostscript can do the conversion.
See: ONLYOFFICE Api Documentation - ONLYOFFICE Document Builder integration API

Indeed, it does not allow you to save the document in JPG directly as in your initial code:

As a workaround, it is possible to get image as a thumbnail of the document as it is shown in the documentation:

.docbuilder

builder.SaveFile("image", "./thumbnail.png", "<m_oThumbnail><format>4</format><aspect>1</aspect><first>false</first><width>1000</width><height>1000</height></m_oThumbnail>");

The format parameter is responsible for resulting image format:

  • format - the image file format used to create a thumbnail (can be of the following values: 3 - for a JPG file, 4 - for a PNG file);

That said, since you are using .docbuilder scripting, here is example of script that will make a JPG image of the first page of the document:

builder.OpenFile("Sample.docx");
builder.SaveFile("image", "./Sample.jpg", "<m_oThumbnail><format>3</format><aspect>1</aspect><first>true</first><width>1000</width><height>1000</height></m_oThumbnail>");
builder.CloseFile();

By the way, both articles reference the same functionality but in different programming languages.

Let me know if misunderstand your request.

I solved it by converting online.
Let me know if you find easier decisions.