python pdf to png code example

Example 1: python pdf to image

#The pdf2image library can be used
#You can install it simply using,

pip install pdf2image
#Once installed you can use following code to get images.

from pdf2image import convert_from_path
pages = convert_from_path('pdf_file', 500)

#Saving pages in jpeg format

for page in pages:
    page.save('out.jpg', 'JPEG')

Example 2: png to pdf

$images = array("your-file.png"); //You can use a URL as well

$pdf = new Imagick($images);
$pdf->setImageFormat('pdf');
$pdf->writeImages('output-file.pdf', true); //The file name

//When ran, it will save in the same directory as the php file/script

Example 3: Python convert dcm to png

med2image -i SAG-anon/0001-1.3.12.2.1107.5.2.19.45152.2013030808110258929186035.dcm \
          -d dicom-results/tags                        \
          -o %PatientName%PatientID%ProtocolName.jpg   \
          -s m

Tags:

Php Example