Python'da üst düzey, platformdan bağımsız yazılım geliştirmek için Belge Optimizasyonu API'mizi kullanın. Bu, Python kullanarak belge ve görüntü boyutunu küçültmek için güçlü bir çözümdür.
Kalite kaybı olmadan büyük dosyaları küçültün. Gereksiz ve kullanılmayan verileri silin. Python içindeki Word ve HTML dosyalarının boyutunu küçültün. Python kitaplığımız, geliştiricilere çeşitli biçimlerdeki belgeleri optimize etmek için entegre bir API sağlar.
Bu Python kitaplığı bağımsız bir çözümdür ve herhangi bir üçüncü taraf yazılımının yüklenmesini gerektirmez.
Maksimum etki, yüksek çözünürlüklü görüntülerin yanı sıra bu tür görüntüleri içeren belgeler optimize edilerek elde edilebilir. Python kitaplığımız DOCX, DOC, RTF, ODT, EPUB, HTML, JPG, PNG dosyalarını sıkıştırmanıza yardımcı olacaktır.
'Aspose.Words for Python via .NET' ile kalite kaybı olmadan belgelerin optimizasyonu kolaylaştı. Aşağıdaki örnek, Python içindeki bir Word belgesinin boyutunun nasıl küçültüleceğini gösterir:
pip install aspose-words
Kopyala
import aspose.words as aw
doc = aw.Document("Input.docx")
doc.cleanup()
shapes = [node.as_shape() for node in doc.get_child_nodes(aw.NodeType.SHAPE, True)]
for shape in shapes:
if shape.isImage:
# Görüntü sıkıştırma için kitaplığı seçmek geliştiriciye kalmıştır.
image = Image.open(shape.image_data.to_stream())
# ...
# Görüntüyü sıkıştırın ve şekle geri ayarlayın.
shape.image_data.set_image("yourCompressedImage")
save_options = aw.saving.OoxmlSaveOptions
save_options.compression_level = aw.saving.CompressionLevel.MAXIMUM
doc.save("Output.docx", save_options)
import aspose.words as aw
doc = aw.Document("Input.docx")
doc.cleanup()
shapes = [node.as_shape() for node in doc.get_child_nodes(aw.NodeType.SHAPE, True)]
for shape in shapes:
if shape.isImage:
# Görüntü sıkıştırma için kitaplığı seçmek geliştiriciye kalmıştır.
image = Image.open(shape.image_data.to_stream())
# ...
# Görüntüyü sıkıştırın ve şekle geri ayarlayın.
shape.image_data.set_image("yourCompressedImage")
save_options = aw.saving.PdfSaveOptions
save_options.cache_background_graphics = true
doc.save("Output.docx", save_options)
import aspose.words as aw
doc = aw.Document("Input.docx")
doc.cleanup()
shapes = [node.as_shape() for node in doc.get_child_nodes(aw.NodeType.SHAPE, True)]
for shape in shapes:
if shape.isImage:
# Görüntü sıkıştırma için kitaplığı seçmek geliştiriciye kalmıştır.
image = Image.open(shape.image_data.to_stream())
# ...
# Resmi sıkıştırın ve şekle geri ayarlayın.
shape.image_data.set_image("yourCompressedImage")
doc.save("Output.docx")
import aspose.words as aw
doc = aw.Document("Input.docx")
doc.cleanup()
shapes = [node.as_shape() for node in doc.get_child_nodes(aw.NodeType.SHAPE, True)]
for shape in shapes:
if shape.isImage:
# Görüntü sıkıştırma için kitaplığı seçmek geliştiriciye kalmıştır.
image = Image.open(shape.image_data.to_stream())
# ...
# Görüntüyü sıkıştırın ve şekle geri ayarlayın.
shape.image_data.set_image("yourCompressedImage")
save_options = aw.saving.OoxmlSaveOptions
save_options.compression_level = aw.saving.CompressionLevel.MAXIMUM
doc.save("Output.docx", save_options)
import aspose.words as aw
doc = aw.Document()
builder = aw.DocumentBuilder(doc)
shape = builder.InsertImage("Input.docx")
save_options = aw.saving.ImageSaveOptions(aw.SaveFormat.DOCX)
shape.get_shape_renderer().save("Output.docx", save_options)
import aspose.words as aw
renderer = aw.pdf2word.fixedformats.PdfFixedRenderer()
pdf_read_options = aw.pdf2word.fixedformats.PdfFixedOptions()
pdf_read_options.image_format = aw.pdf2word.fixedformats.FixedImageFormat.JPEG
pdf_read_options.jpeg_quality = 50
with open ("Input.docx", 'rb') as pdf_stream:
pages_stream = renderer.save_pdf_as_images(pdf_stream, pdf_read_options);
builder = aw.DocumentBuilder()
for i in range(0, len(pages_stream)):
# Geçerli sayfa görüntüsü ölçeklemesinden kaçınmak için maksimum sayfa boyutunu ayarlayın.
max_page_dimension = 1584
page_setup = builder.page_setup
set_page_size(page_setup, max_page_dimension, max_page_dimension)
page_image = builder.insert_image(pages_stream[i])
set_page_size(page_setup, page_image.width, page_image.height)
page_setup.top_margin = 0
page_setup.left_margin = 0
page_setup.bottom_margin = 0
page_setup.right_margin = 0
if i != len(pages_stream) - 1:
builder.insert_break(aw.BreakType.SECTION_BREAK_NEW_PAGE)
save_options = aw.saving.PdfSaveOptions()
save_options.cache_background_graphics = true
builder.document.save("Output.docx", save_options)
def set_page_size(page_setup, width, height):
page_setup.page_width = width;
page_setup.page_height = height;
Python paketlerimizi PyPi depolarında barındırıyoruz. "Aspose.Words for Python via .NET" geliştirici ortamınıza nasıl kuracağınızla ilgili adım adım talimatları izleyin.
Bu paket Python ≥3.5 ve <3.12 ile uyumludur. Linux için yazılım geliştiriyorsanız, lütfen Ürün Belgelerinde gcc ve libpython için ek gereksinimlere bakın.