Image

Creates a snapshot of a specific PDF page and saves it as a picture. For instance, this thumbnail can for instance be used as a preview on the web.

FeatureParameterResponseActionDescriptionLinks
createImagesCreateImagesCreateImagesResImageActionCreates a snapshot of a specific PDF page and saves it as a picture. Swagger
Sample
createThumbnailwidth,
pageNr,
imageFormat,
file
file streamProduces a thumbnail of the page referenced by the pageNr.
And be aware of the one-indexing of the page numbers.

Swagger
Sample
createThumbnailswidth, pageNrs, imageFormat, file[file stream]

Samples

CreateImages

  • curl
  • C#
  • Java
  • JavaScript
  • PHP
  • Python
  • Ruby
curl No Sample
// create createImages object
var createImages = new CreateImages()
{
    // document
    Document = new Document()
    {
        DocData = File.ReadAllBytes("myPdf.pdf"),
        Name = "myPdf.pdf",
    },
    // action
    ImageAction = new ImageAction()
    {
        ImageExtension = ImageActionImageExtension.Jpeg,
        WidthPixel = 4000,
        PageSelection = new PageSelection()
        {
            PageNrs = new System.Collections.Generic.HashSet() { 1, 2, 3 }
        }
    },
};

// create image
var res = await Pdf4meClient.Pdf4me.Instance.ImageClient.CreateImagesAsync(createImages);

// extract thumbnail and writing it to disk
foreach (var page in res.Document.Pages)
    File.WriteAllBytes("thumbnail_" + page.PageNumber + "+.jpg", page.Thumbnail);
// setup the imageClient
ImageClient imageClient = new ImageClient(pdf4meClient);

// create createImages object
CreateImages createImages = new CreateImages();
// document
Document document = new Document();
byte[] file = Files.readAllBytes(Paths.get("myPdf.pdf"));
document.setDocData(file);
createImages.setDocument(document);
// action
ImageAction imageAction = new ImageAction();
imageAction.setWidthPixel(4000);
imageAction.setPageSelection(new PageSelection().addPageNrsItem(1));
imageAction.setImageExtension(ImageExtensionEnum.JPEG);
createImages.setImageAction(imageAction);

// create image
CreateImagesRes res = imageClient.createImages(createImages);

// extracting the generated picture and writing it to disk
byte[] thumbnail = res.getDocument().getPages().get(0).getThumbnail();
FileUtils.writeByteArrayToFile(new File("thumbnail.jpg"), thumbnail);
// setup the pdf4meClient
const pdf4meClient = pdf4me.createClient('YOUR API KEY')

// create the createImages object
const createImagesReq = {
  // document
  document: {
    docData: fs.readFileSync(path.join(__dirname, 'myPdf.pdf')).toString('base64'),
  },
  // action
  imageAction: {
    pageSelection: {
      pageNrs: [1, 2, 3],
    },
    imageQuality: 99,
    widthPixel: 2000,
    heightPixel: 2000,
    imageExtension: 'Jpeg',
  },
}

// create images
pdf4meClient.createImages(createImagesReq)
  .then(createImagesRes => {
    // extract thumbnails and writing it to disk
    createImagesRes.document.pages.forEach((page, index) => {
      const image = Buffer.from(page.thumbnail, 'base64')
      fs.writeFileSync(path.join(__dirname, `thumbnail_${index + 1}.jpg`), image)
    })
  })
  .catch(error => {
    console.error(error)
  })
$res = $client->pdf4me()->createImages([
    // document
    "document" => [
        'docData' => $client->getFileData('myPdf.pdf')
    ],
    //action
    "imageAction" => [
        "widthPixel" => 4000,
        "pageSelection" => [
            "pageNrs" => [ 1, 2, 3 ]
        ],
        "imageExtension" => "Jpeg"
    ]
]);


foreach($res->document->pages as $page){
    // extract thumbnails and writing it to disk
    $image = base64_decode($page->thumbnail);
    file_put_contents( 'thumbnail_'.$page->pageNumber.'.jpg', $image);
}
# setup the image_client
image_client = ImageClient(pdf4me_client)

# create the create_images object
create_images = CreateImages(
    document=Document(
        doc_data=FileReader().get_file_data('myPdf.pdf')
    ),
    image_action=ImageAction(
        width_pixel=4000,
        page_selection=PageSelection(
            page_nrs=[1, 2, 3]
        ),
        image_extension='Jpeg'
    )
)

# image creation
res = image_client.create_images(create_images=create_images)

for page in res['document']['pages']:
        
    # extracting the generated image
    image = base64.b64decode(page['thumbnail'])
    # writing it to disk
    with open('thumbnail_'+str(page['page_number'])+'.jpg', 'wb') as f:
        f.write(image)
file_path = 'myPdf.pdf'

action = Pdf4me::CreateImages.new(
    document: Pdf4me::Document.new(
      doc_data: Base64.encode64(File.open(file_path, 'rb', &:read))
    ),
    image_action: Pdf4me::ImageAction.new(
        page_selection: Pdf4me::PageSelection.new(
          page_nrs: [1, 2, 3]
        ),
        image_extension: 'Jpeg',
        center: true,
        fit_page: true,
        bits_per_pixel: 24,
        bilevel_threshold: 181,
        render_options: %w(noAntialiasing),
        rotate_mode: 'none',
        preserve_aspect_ratio: true,
        compression: 'raw'
   )
)
response = action.run

# saving the extracted thumbnail
File.open('./out/thumbnail.jpg', 'wb') do |f|
 f.write(Base64.decode64(response.document.pages.first.thumbnail))
end

CreateThumbnail

  • curl
  • C#
  • Java
  • JavaScript
  • PHP
  • Python
  • Ruby
curl https://api.pdf4me.com/Image/CreateThumbnail ^
    -H "Authorization: Basic DEV-KEY" ^
    -F pageNr=1 ^
    -F width=4000 ^
    -F imageFormat=jpg ^
    -F "file=@./myPdf.pdf" ^
    -o ./thumbnail.jpg
// thumbnail creation
var thumbnail = await Pdf4me.Instance.ImageClient.CreateThumbnailAsync(
    File.ReadAllBytes("myPdf.pdf"),
    4000, 
    "1", 
    ImageActionImageExtension.Jpg
    );
// and writing the generated picture to disk
File.WriteAllBytes("thumbnail.jpg", thumbnail);
// setup the imageClient
ImageClient imageClient = new ImageClient(pdf4meClient);

// thumbnail creation and writing the generated picture to disk
byte[] thumbnail = imageClient.createThumbnail(4000, "1", ImageExtensionEnum.JPEG, new File("myPdf.pdf"));
FileUtils.writeByteArrayToFile(new File("thumbnail.jpg"), thumbnail);
// create pdf4meClient
const p4mClient = pdf4me.createClient('YOUR API KEY')

// thumbnail creation
p4mClient.createThumbnail(4000, '1', 'jpg', fs.createReadStream(path.join(__dirname, 'myPdf.pdf')))
  .then(thumbnail => {
    // and writing the generated picture to disk
    fs.writeFileSync(path.join(__dirname, 'thumbnail.jpg'), thumbnail)
  })
  .catch(error => {
    console.error(error)
  })
$createThumbnail = $client->pdf4me()->createThumbnail(
    [
        "width" => 4000,
        "pageNr" => "1",
        "imageFormat" => "jpg"
        "file" => __DIR__.'/myPdf.pdf'
    ]
);

//writing it to file
file_put_contents('thumbnail.jpg', $createThumbnail);
# setup the image_client
image_client = ImageClient(pdf4me_client)

# image creation
image = image_client.create_thumbnail(
    width=4000,
    page_nr='1',
    image_format='jpg',
    file=FileReader().get_file_handler(path='myPdf.pdf')
)
# writing the generated image to disk
with open('thumbnail.jpg', 'wb') as f:
    f.write(image)
a = Pdf4me::CreateThumbnail.new(
      file: '/myPdf.pdf',
      page_number: 1,
      width: 4000,
      save_path: 'thumbnail.jpg'
    )
a.run

CreateThumbnails

  • curl
  • C#
  • Java
  • JavaScript
  • PHP
  • Python
  • Ruby
curl No Sample
// thumbnail creation
var thumbnails = await Pdf4me.Instance.ImageClient.CreateThumbnailsAsync(
    File.ReadAllBytes("myPdf.pdf"),
    2000, 
    "1,2,3", 
    ImageActionImageExtension.Png
    );
// and writing the generated picture to disk
for (var i = 0; i < thumbnails.Count(); i++)
    File.WriteAllBytes("thumbnail_" + i +".png", thumbnails[i]);
// setup the pdf4meClient
const pdf4meClient = pdf4me.createClient('YOUR API KEY')

// thumbnail creation
pdf4meClient.createThumbnails(2000, '1,2,3', 'png', fs.createReadStream(path.join(__dirname, 'myPdf.pdf')))
  .then(thumbnails => {
    // and writing the generated picture to disk
    thumbnails.forEach((thumbnail, index) => {
      fs.writeFileSync(path.join(__dirname, `thumbnail_${index + 1}.png`), thumbnail)
    })
  })
  .catch(error => {
    console.error(error)
  })
 // thumbnail creation
 $res = $client->pdf4me()->createThumbnails(
        [
            "pageNrs"=> "1,2",
            "width" => 1000,
            "imageFormat" => "png",
            "file" => 'PDF_10pages.pdf'
        ]);

$count = 1;
// extracting thumbnails
foreach($res as $page){
    $page_base = base64_decode($page);
    // and writing the resulting PDFs to disk
    file_put_contents($page_base, 'thumbnail_'.$count.'.jpg');
    $count = $count + 1;
}    
# setup the image_client
image_client = ImageClient(pdf4me_client)

# image creation
thumbnails = image_client.create_thumbnails(
    width=2000,
    page_nrs='1,2,3',
    image_format='jpg',
    file=FileReader().get_file_handler(path='PDF_10pages.pdf')
)

# extracting the generated image
count = 0
for thumbnail in thumbnails:
        
    # writing it to disk
    with open('thumbnail_'+str(count)+'.jpg', 'wb') as f:
        f.write(thumbnail)

    count = count+1

Models

Image

Name Type Description Notes
document Document
imageAction ImageAction
jobId String [optional]
jobIdExtern String [optional]
integrations [String] [optional]

ImageAction

Name Type Notes Description
pageNrs [integer] [optional] The numbers of the pages the action is applied to. PageNrs overruels PageIds and PageSequence.
pageIds [String] [optional] The Ids of the pages the action is applied to. PageIds overrules the PageSequence.
pageSequence String "all", "first", "last", "odd", "even", "notFirst", "notLast"
[optional]
Specifies what pages the action is applied to.
center boolean Default: false
[optional]
Center mode.
- true: the document is horizontally and vertically centered on the page.
- false: the document is printed to the upper left corner of the page.
fitPage boolean [optional] Fit page mode.
- true: the page is scaled to fit the image (in either width or height).
- false: the page is rendered with its true size.
bitsPerPixel integer bi-tonal: 1,
gray scale: 8,
RGB true color: 24,
CMYK: 32
Default: 24
[optional]
Color depth.
bilevelThreshold integer [0, 255]
Default: 181
[optional]
Threshold for converting from gray to bi-tonal when dithering is set to "none"
heightPixel integer [optional] Height [pixel]
widthPixel integer [optional] Width [pixel]
widthPoint integer [optional] Width[points]
heightPoint integer [optional] Height [points]
renderOptions [String] "noAntialiasing", "noInterpolation", "noLowPassFilter", "noHinting",
"printingMode", "noBPC", "fitPaths", "useBoxFilter"[optional]
Rendering options.
rotateMode String "none"
"attribute" : set the rotation to the viewing rotation attribute of the PDF page, i.e. rendering the page with the same rotation as it is displayed in a PDF viewer.
"portrait"
"landscape" [optional]
Rotation mode of the page.
preserveAspectRatio boolean Default: true
[optional]
Aspect Ratio Preservation.
- true: a uniform up- or down-scaling is applied, i.e. the output image has the same ratio of width to height as the input file and its size will fit into the defined dimensions.
imageQuality integer Default: 80
[1,100]
[optional]
Quality index of lossy compression types. It is applied to JPEG and JPEG2000 compression. For JPEG2000, a quality index of 100 means lossless compression. JPEG compression is always lossy.
cmsEngine String Default: "lcms"
"none": the algorithms specified in the PDF reference are used. This results in the maximum possible contrast.
"neugebauer": efficiently converts CMYK to RGB. It does not need any color profiles. The results, however, look similar to conversion using color profiles.
"lcms": uses ICC color profiles.
"customCMS": a configurable version of the Neugebauer algorithm is applied. The coefficients can be defined in the customCMSConfig.
[optional]
customCMSConfig CustomCMSConfig Custom Management System (CMS) Engine for Neugebauer algorithm. In order for the customCMSConfig to be used, set the cmsEngine to "customCMS".
dithering String Default: "floydSteinberg"
"none", "floydSteinberg", "halftone", "pattern", "g3Optimized", "g4Optimized", "atkinson"
[optional]
Dithering algorithm. Dithering refers to the procedure of simulating colors or grayscales. This is mainly useful for low color depth (e.g. black and white or indexed) images.
dpi integer
[optional]
Resolution of the image in DPI (dots per inch). The x- and y-axis are set to the same value.
fillOrder String Default: "mSB"
"mSB": most significant bit. "lSB": least significant bit.
[optional]
Bit fill order.
filterRatio integer Default: "1"
1,2,3
[optional]
This property is used to enable and parameterize super-sampling, a technique to initially render the image at a higher resolution and then sample it down to the target resolution.
As a result of that process the final image appears smoother, i.e. anti-aliased. Applying super-sampling improves the image quality when rendering at low target resolutions (72 DPI or less); the higher the target resolution the less the visual impact.
This property requires memory and CPU time quadratically to the ratio, therefore only small values, such as 2 or 3 should be used. If a too high value (in combination with the original image size) is set, it is ignored.
imageExtension String "jpg", "jpeg", "bmp", "gif", "jb2", "jp2", "jpf", "jpx", "png", "tif", "tiff" Output type for image file.
colorSpace String Default: "RGB"
"RGB", "RGBA", "Gray", "GrayA", "CMYK", "YCbCr", "YCbCrK", "Palette", "LAB", "CMYK_Konly", "CMYKA"
[optional]
Color space of the output image. For black white bi-tonal images, a gray color space must be selected.
compression String Default: "LZW"
"raw", "jPEG", "flate", "LZW", "group3", "group3_2D", "group4", "jBIG2", "jPEG2000", "tIFFJPEG"
[optional]
Get or set the compression type of TIFF images. For any other image format, the compression is automatically defined by the file extension.

CreateImagesRes

Name Type Description Notes
document Document PDF with embedded images.  

Document

Name Type Description Notes
jobId String JobId of Documents WorkingSet.
documentId String Document Id
name String Filename inlcuding filetype.
docStatus String Status of the Document, e.g. Stamped.
pages Page Description of pages.
docData [byte] Document bytes.
docMetadata DocMetadata Document metadata such as title, pageCount et al.
docLogs DocLog Logging information about the request, e.g. timestamp.

Page

Name Type Description Notes
documentId String Globally unique Id.
pageId String Globally unique Id.
pageNumber Integer PageNumber, starting with 1.
rotate double By how much the page was rotated from its original orientation.
thumbnail byte Thumbnail representing this particular page.
sourceDocumentId String Id of the document it was created from, e.g. in case of an extraction, the result's sourceDocumentId is the Id of the PDF the pages have been extracted from.
sourcePageNumber Integer Page number of the original page in the original document, e.g. let's assume document B consists of page number 4 of document A (extraction).
Thus, document B's only page's sourcePageNumber is number 4.

DocMetadata

Name Type Description Notes
title String Title of document.
subject String Subject of document.
pageCount long Number of pages.
size long Number bytes of the document.
isEncrypted boolean If the document is Encrypted
pdfCompliance String Pdf Compliance, e.g. PDF/A.
isSigned boolean If the document is Encrypted
uploadedMimeType String Uploaded MimeType, e.g. application/bson.
uploadedFileSize long Uploaded file size.

DocLog

Name Type Description Notes
messageType String MessageType, e.g. PdfALog.
message String Message itself, e.g. a warning.
timestamp dateTime Timestamp.
docLogLevel String Type of message. Supported Values :
"verbose", "info", "warning", "error", "timing"
durationMilliseconds long Timing for requested log information [ms].

CustomCMSConfig

Name Type Description Notes
white RGBSet 0.996078, 0.996078, 0.996078
c RGBSet 0.000000, 0.686275, 0.937255
m RGBSet 0.925490, 0.149020, 0.560784
y RGBSet 1.000000, 0.949020, 0.066667
k RGBSet 0.215686, 0.203922, 0.207843
cm RGBSet 0.243137, 0.247059, 0.584314
cy RGBSet 0.000000, 0.658824, 0.349020
ck RGBSet 0.066667, 0.176471, 0.215686
my RGBSet 0.929412, 0.196078, 0.215686
mk RGBSet 0.215686, 0.101961, 0.141176
yk RGBSet 0.200000, 0.196078, 0.125490
cmy RGBSet 0.266667, 0.266667, 0.274510
cmk RGBSet 0.133333, 0.098039, 0.160784
cyk RGBSet 0.074510, 0.180392, 0.133333
myk RGBSet 0.215686, 0.121569, 0.113725
cmyk RGBSet 0.125490, 0.121569, 0.121569

RGBSet

Name Type Description Notes
red integer
blue integer
green integer

How can we help?