- aspose-com-gists / convert-djvu-to-pdf.py
- angeloped / djvu2pdf.py
- Convert DJVU to PDF using Python language
- Transform DJVU to PDF using native Python language APIs and without need of any image editor or 3rd-party libraries.
- Aspose.Imaging for Python
- Overview
- How to Convert DJVU to PDF Using Python
- The system command line
- Steps to Convert DJVU to PDF via Python
- System Requirements
- Free App to Convert DJVU to PDF
- Convert DJVU to PDF — Python
- DJVU What is DJVU File Format
- PDF What is PDF File Format
- Other Supported Conversions
aspose-com-gists / convert-djvu-to-pdf.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
import aspose . pycore as aspycore |
from aspose . imaging import Image , IntRange |
from aspose . imaging . fileformats . djvu import DjvuImage |
from aspose . imaging . fileformats . pdf import PdfDocumentInfo |
from aspose . imaging . imageoptions import PdfOptions , DjvuMultiPageOptions |
import os |
if ‘TEMPLATE_DIR’ in os . environ : |
templates_folder = os . environ [ ‘TEMPLATE_DIR’ ] |
else : |
templates_folder = r»C:\Users\USER\Downloads\templates» |
delete_output = ‘SAVE_OUTPUT’ not in os . environ |
data_dir = templates_folder |
# Load a DjVu image |
with aspycore . as_of ( Image . load ( os . path . join ( data_dir , «template.djvu» )), DjvuImage ) as image : |
# Create an instance of PdfOptions and Initialize the metadata for Pdf document |
export_options = PdfOptions () |
export_options . pdf_document_info = PdfDocumentInfo () |
# Create an instance of IntRange and initialize it with the range of DjVu pages to be exported |
range_ = IntRange ( 0 , 1 ) |
# Initialize an instance of DjvuMultiPageOptions with range of DjVu pages to be exported and Save the result in PDF format |
export_options . multi_page_options = DjvuMultiPageOptions ( range_ ) |
image . save ( os . path . join ( data_dir , «result.pdf» ), export_options ) |
if delete_output : |
os . remove ( os . path . join ( data_dir , «result.pdf» )) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
import aspose . pycore as aspycore |
from aspose . imaging import Image |
from aspose . imaging . fileformats . djvu import DjvuImage |
from aspose . imaging . fileformats . tiff . enums import TiffExpectedFormat |
from aspose . imaging . imageoptions import TiffOptions , DjvuMultiPageOptions |
import os |
if ‘TEMPLATE_DIR’ in os . environ : |
templates_folder = os . environ [ ‘TEMPLATE_DIR’ ] |
else : |
templates_folder = r»C:\Users\USER\Downloads\templates» |
delete_output = ‘SAVE_OUTPUT’ not in os . environ |
data_dir = templates_folder |
# Load a DjVu image |
with aspycore . as_of ( Image . load ( os . path . join ( data_dir , «template.djvu» )), DjvuImage ) as image : |
# Create an instance of TiffOptions & use preset options for Black n While with Deflate compression |
export_options = TiffOptions ( TiffExpectedFormat . TIFF_DEFLATE_BW ) |
# Initialize the DjvuMultiPageOptions and Call Save method while passing instance of TiffOptions |
export_options . multi_page_options = DjvuMultiPageOptions () |
image . save ( os . path . join ( data_dir , «result.tiff» ), export_options ) |
if delete_output : |
os . remove ( os . path . join ( data_dir , «result.tiff» )) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
import aspose . pycore as aspycore |
from aspose . imaging import Image , IntRange |
from aspose . imaging . fileformats . djvu import DjvuImage |
from aspose . imaging . fileformats . tiff . enums import TiffExpectedFormat |
from aspose . imaging . imageoptions import TiffOptions , DjvuMultiPageOptions |
import os |
if ‘TEMPLATE_DIR’ in os . environ : |
templates_folder = os . environ [ ‘TEMPLATE_DIR’ ] |
else : |
templates_folder = r»C:\Users\USER\Downloads\templates» |
delete_output = ‘SAVE_OUTPUT’ not in os . environ |
data_dir = templates_folder |
# Load a DjVu image |
with aspycore . as_of ( Image . load ( os . path . join ( data_dir , «template.djvu» )), DjvuImage ) as image : |
# Create an instance of TiffOptions & use preset options for Black n While with Deflate compression |
export_options = TiffOptions ( TiffExpectedFormat . TIFF_DEFLATE_BW ) |
range_ = IntRange ( 0 , 1 ) |
# Initialize an instance of DjvuMultiPageOptions while passing instance of IntRange and Call Save method while passing instance of TiffOptions |
export_options . multi_page_options = DjvuMultiPageOptions ( range_ ) |
image . save ( os . path . join ( data_dir , «result.tiff» ), export_options ) |
if delete_output : |
os . remove ( os . path . join ( data_dir , «result.tiff» )) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
import aspose . pycore as aspycore |
from aspose . imaging import Image , IntRange , Rectangle |
from aspose . imaging . fileformats . png import PngColorType |
from aspose . imaging . fileformats . djvu import DjvuImage |
from aspose . imaging . imageoptions import PngOptions , DjvuMultiPageOptions |
import os |
if ‘TEMPLATE_DIR’ in os . environ : |
templates_folder = os . environ [ ‘TEMPLATE_DIR’ ] |
else : |
templates_folder = r»C:\Users\USER\Downloads\templates» |
delete_output = ‘SAVE_OUTPUT’ not in os . environ |
data_dir = templates_folder |
# Load a DjVu image |
with aspycore . as_of ( Image . load ( os . path . join ( data_dir , «template.djvu» )), DjvuImage ) as image : |
# Create an instance of PngOptions and Set ColorType to Grayscale |
export_options = PngOptions () |
export_options . color_type = PngColorType . GRAYSCALE |
# Create an instance of Rectangle and specify the portion on DjVu page |
export_area = Rectangle ( 0 , 0 , 500 , 500 ) |
# Specify the DjVu page index and Initialize an instance of DjvuMultiPageOptions while passing index of DjVu page index and instance of Rectangle covering the area to be exported |
export_page_index = 0 |
export_options . multi_page_options = DjvuMultiPageOptions ( export_page_index , export_area ) |
image . save ( os . path . join ( data_dir , «result.png» ), export_options ) |
if delete_output : |
os . remove ( os . path . join ( data_dir , «result.png» )) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
import aspose . pycore as aspycore |
from aspose . imaging import Image , LoadOptions |
from aspose . imaging . fileformats . djvu import DjvuImage |
from aspose . imaging . imageoptions import PngOptions |
import os |
if ‘TEMPLATE_DIR’ in os . environ : |
templates_folder = os . environ [ ‘TEMPLATE_DIR’ ] |
else : |
templates_folder = r»C:\Users\USER\Downloads\templates» |
delete_output = ‘SAVE_OUTPUT’ not in os . environ |
data_dir = templates_folder |
# Setting a memory limit of 50 megabytes for target loaded image |
obj_init = LoadOptions () |
obj_init . buffer_size_hint = 50 |
with aspycore . as_of ( Image . load ( os . path . join ( data_dir , «template.djvu» ), obj_init ), DjvuImage ) as image : |
page_num = 0 |
for page in image . pages : |
out_file = os . path . join ( data_dir , f»page < page_num >.png» ) |
page . save ( out_file , PngOptions ()) |
if delete_output : |
os . remove ( out_file ) |
page_num += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
import aspose . pycore as aspycore |
from aspose . imaging import Image |
from aspose . imaging . imageoptions import PngOptions |
import os |
import threading |
if ‘TEMPLATE_DIR’ in os . environ : |
templates_folder = os . environ [ ‘TEMPLATE_DIR’ ] |
else : |
templates_folder = r»C:\Users\USER\Downloads\templates» |
delete_output = ‘SAVE_OUTPUT’ not in os . environ |
data_dir = templates_folder |
num_threads = 5 |
def thread_func ( path , output_file ): |
try : |
with Image . load ( path ) as image : |
image . save ( output_file , PngOptions ()) |
finally : |
if delete_output : |
os . remove ( output_file ) |
input_file = os . path . join ( data_dir , «template.djvu» ) |
threads = [] |
for task_num in range ( num_threads ): |
output_file = os . path . join ( data_dir , f»result_task < task_num >.png» ) |
thread = threading . Thread ( target = thread_func , args = ( input_file , output_file )) |
threads . append ( thread ) |
thread . start () |
for thread in threads : |
thread . join () |
angeloped / djvu2pdf.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
#!/bin/python |
import os |
import sys |
import time |
import thread |
# author: ~/angeloped |
stat = [] |
def convrt ( fpath , fname ): |
print ( «converting \» / \» . » . format ( fpath , fname )) |
os . system ( «djvups \» / \» | ps2pdf — \» /pdfied/ \» » . format ( fpath , fname , fname . replace ( «.djvu» , «.pdf» ))) |
stat . pop () |
if __name__ == «__main__» : |
if len ( sys . argv ) == 1 : |
fpath = os . getcwd () |
elif len ( sys . argv ) |
buff_limit = int ( sys . argv [ 2 ]) if len ( sys . argv ) == 3 else 6 |
if os . path . exists ( sys . argv [ 1 ]): |
fpath = sys . argv [ 1 ] |
else : |
print ( «target path not found.. setting ‘./’ as cwd.» ) |
fpath = os . getcwd () |
else : |
print ( «simple usage: python djvu2pdf.py » ) |
if not os . path . exists ( «/pdfied» . format ( fpath )): |
os . mkdir ( «/pdfied» . format ( fpath )) |
for fname in os . listdir ( fpath ): |
while len ( stat ) == buff_limit : # process limiter |
time . sleep ( 1 ) |
if fname [ — 5 :] == «.djvu» : |
thread . start_new_thread ( convrt , ( fpath , fname ,)) |
stat . append ( «» ) |
while bool ( stat ): |
time . sleep ( 1 ) |
Convert DJVU to PDF using Python language
Transform DJVU to PDF using native Python language APIs and without need of any image editor or 3rd-party libraries.
Aspose.Imaging for Python
Overview
Download from PyPI
Easily get Aspose.Imaging for Python directly from PyPI using pip install aspose-imaging.
How to Convert DJVU to PDF Using Python
In order to convert DJVU to PDF, we’ll use Aspose.Imaging for Python via .NET API which is a feature-rich, powerful and easy to use image manipulation and conversion API for Python platform. You may install it using the following command from your system command.
The system command line
>> pip install aspose-imaging-python-net
Steps to Convert DJVU to PDF via Python
Developers can easily load & convert DJVU files to PDF in just a few lines of code.
- Load DJVU file with Image.load method
- Create & set the instance of required subclass of ImageOptionsBase (e.g. BmpOptions, PngOptions, etc.)
- Call the Image.save method
- Pass file path with PDF extension & object of ImageOptionsBase class
System Requirements
Before running the conversion example code, make sure that you have the following prerequisites.
Free App to Convert DJVU to PDF
- Select or drag and drop DJVU image
- Choose format and click Convert button
- Click Download button to download PDF image
Convert DJVU to PDF — Python
DJVU What is DJVU File Format
DjVu, pronounced as “déjà vu”, is a graphics file format intended for scanned documents and books especially those which contain the combination of text, drawings, images and photographs. It was developed by AT&T Labs. It uses multiple techniques like image layer separation of text and background images, progressive loading, arithmetic coding and lossy compression for bitonal images. Since DJVU file can contain compressed yet high-quality colour images, photographs, text, and drawings and can be saved in less space therefore, it’s used on web as eBooks, manuals, newspapers, ancient documents, etc.
PDF What is PDF File Format
Portable Document Format (PDF) is a type of document created by Adobe back in 1990s. The purpose of this file format was to introduce a standard for representation of documents and other reference material in a format that is independent of application software, hardware as well as Operating System. The PDF file format has full capability to contain information like text, images, hyperlinks, form-fields, rich media, digital signatures, attachments, metadata, Geospatial features and 3D objects in it that can become as part of source document.
Other Supported Conversions
Using Python, one can easily convert different formats including.