We're pleased to announce the release of Spire.Office for Python 9.12.1. In this version, the Spire.Doc for Python supports marking Word documents as 'final' and setting the gutter position in Word. Spire.PDF for Python supports digital signature functionality, and returning imageInfo[i].Image as a byte[] type. Spire.XLS for Python adds the workbook.Chartsheets property and the excelPicture.HyperLink property. Spire.Presentation for Python supports getting slides from section. Moreover, many known issues that occurred when converting, processing and saving Word/Excel/PDF/PowerPoint files have been successfully fixed. More details are listed below.
Click the link to download Spire.Office for Python 9.12.1:
Here is a list of changes made in this release
Spire.Doc for Python
| Category | ID | Description |
| New feature | SPIREDOC-10347 | Supports marking Word documents as 'final'.
from spire.doc import *
from spire.doc.common import *
document = Document()
document.LoadFromFile("in.docx")
customProperties = document.CustomDocumentProperties
customProperties.Add("_MarkAsFinal", Boolean(True))
document.SaveToFile("out.docx", FileFormat.Docx2013)
|
| New feature | SPIREDOC-10401 | Supports setting the gutter position in a Word document.
from spire.doc import *
from spire.doc.common import *
document = Document()
sec = None
for i in range(0, 10):
sec = document.AddSection()
sec.PageSetup.IsTopGutter = False
para = sec.AddParagraph()
txtRange = para.AppendText("Test")
sec.PageSetup.Gutter = 50 + i*10
document.SaveToFile(outputFile, FileFormat.Docx)
document.Close()
|
| New feature | SPIREDOC-10555 | Supports setting custom font folders.
from spire.doc import * from spire.doc.common import * document = Document() document.LoadFromFile(inputFile) document.SetCustomFontsFolders(document,"Angsana New") document.SaveToFile(outputFile, FileFormat.PDF) document.Close() |
| New feature | SPIREDOC-10817 | Supports setting authors for the revision.
from spire.doc import *
from spire.doc.common import *
document = Document()
#Load the file from disk.
document.LoadFromFile(inputFile)
for i in range(document.Sections.Count):
sec = document.Sections.get_Item(i)
#Iterate through the element under body in the section
for j in range(sec.Body.ChildObjects.Count):
docItem = sec.Body.ChildObjects.get_Item(j)
if isinstance(docItem, Paragraph):
para = docItem
if para.IsInsertRevision:
para.InsertRevision.Author="Spire.Doc Insert"
elif para.IsDeleteRevision:
para.DeleteRevision.Author="Spire.Doc Insert"
for k in range(para.ChildObjects.Count):
textRange = para.ChildObjects.get_Item(k)
if isinstance(textRange, TextRange):
if textRange.IsInsertRevision:
textRange.InsertRevision.Author="Spire.Doc Insert"
elif textRange.IsDeleteRevision:
textRange.DeleteRevision.Author="Spire.Doc Insert"
#Save to file.
document.SaveToFile(outputFile, FileFormat.Docx2013)
document.Close()
|
| Bug | SPIREDOC-10294 SPIREDOC-10863 |
Fixes the issue that the program threw "Arg_InvalidCastException" when adding a LaTeX formula. |
| Bug | SPIREDOC-10533 | Fixes the issue that the program threw "AttributeError" when using CustomDocumentProperties.Add() method. |
| Bug | SPIREDOC-10655 | Fixes the issue that the program threw "AttributeError" when setting PageSetup.GridType |
| Bug | SPIREDOC-10779 | Fixes the issue that incorrect returns occurred when using 'FixedLayoutPage.Section'. |
Spire.XLS for Python
| Category | ID | Description |
| New feature | SPIREXLS-5181 | Supports determining whether to retain the original page size when converting Excel to PDF.
book = Workbook() book.LoadFromFile(inputFile) # Retain the page size set book.ConverterSetting.SheetFitToPageRetainPaperSize = True book.SaveToFile(outputFile, FileFormat.PDF) |
| New feature | SPIREXLS-5319 | Adds the workbook.Chartsheets property. |
| New feature | SPIREXLS-5301 | Adds the excelPicture.HyperLink property. |
| Bug | SPIREXLS-5235 | Fixes the issue that hyperlinks were lost after converting Excel to PDF. |
| Bug | SPIREXLS-5236 | Fixes the issue that the page numbers were incorrect after converting Excel to PDF. |
| Bug | SPIREXLS-5266 | Fixes the issue that Chinese characters were garbled when converting Excel to PDF on cloud platform (pythonwhere). |
| Bug | SPIREXLS-5267 | Fixes the issue that an exception was thrown when using openpyxl to load the XLSX file generated by our product. |
| Bug | SPIREXLS-5303 | Fixes the issue that an exception was thrown when multiple protection types were set simultaneously in the sheet.Protect method. |
| Bug | SPIREXLS-5349 | Fixes the issue that the content was inconsistent after converting ChartSheet to SVG. |
| Bug | SPIREXLS-5475 | Fixes the issue that an exception was thrown when setting font styles on ubuntu22. |
| Bug | SPIREXLS-5552 | Fixes the issue that an exception was thrown when converting Excel to PDF. |
| Bug | SPIREXLS-5571 | Fixes the issue that the text position was incorrect after converting an Excel document to a PDF document. |
Spire.PDF for Python
| Category | ID | Description |
| New feature | SPIREPDF-6888 | Supports returning imageInfo[i].Image as a byte[] type.
byteResult = imageInfo[i].Image.ToArray()
fileName = outputFile_1 + "Bug_6888_{0:d}.png".format(i)
with open(fileName,'wb') as f:
f.write(byteResult)
|
| New feature | SPIREPDF-6902 | Synchronizes the PdfTextReplaceOptions class.
pdf=PdfDocument()
pdf.LoadFromFile(inputFile)
page = pdf.Pages[0]
textreplacer = PdfTextReplacer(page)
options = PdfTextReplaceOptions()
options.ReplaceType = ReplaceActionType.WholeWord
textreplacer.Options = options
textreplacer.ReplaceAllText("text", "text")
pdf.SaveToFile(outputFile)
|
| New feature | SPIREPDF-6903 | Synchronizes the TextStates property with the PdfTextFragment interface.
pdf = PdfDocument()
pdf.LoadFromFile(inputFile)
inder = PdfTextFinder(pdf.Pages[0])
fragments = finder.Find("PDF")
sb = []
for fragment in fragments:
sb.append(fragment.TextStates[0].FontName)
sb.append(fragment.TextStates[0].FontFamily)
sb.append(str(round(fragment.TextStates[0].FontSize,2)))
File.AppendAllText(outputFile,sb)
pdf.Close()
|
| New feature | SPIREPDF-6944 | Supports digital signature functionality.
# Load a Pdf document from disk
doc = PdfDocument()
doc.LoadFromFile(inputFile)
# Create a signature maker with the PDF document and PFX file
signatureMaker = PdfOrdinarySignatureMaker(doc, inputFile_pfx, "e-iceblue")
# Configure the signature properties
signature = signatureMaker.Signature
signature.Name = "Gary"
signature.ContactInfo = "028-81705109"
signature.Location = "Chengdu"
signature.Reason = "The certificate of this document"
# Create a signature appearance
appearance = PdfSignatureAppearance(signature)
appearance.NameLabel = "Signer: "
appearance.ContactInfoLabel = "ContactInfo: "
appearance.LocationLabel = "Location: "
appearance.ReasonLabel = "Reaseon: "
appearance.SignatureImage = PdfImage.FromFile(inputImage)
appearance.GraphicMode = GraphicMode.SignImageAndSignDetail
appearance.SignImageLayout = SignImageLayout.none
# Apply the signature to the PDF document
signatureMaker.MakeSignature("Signer:", doc.Pages.get_Item(0), 90.0, 550.0, 270.0, 90.0, appearance)
# Save the document
doc.SaveToFile(outputFile)
|
| New feature | SPIREPDF-6505 | Supports macOS system. |
| Bug | SPIREPDF-6877 | Fixes the issue that highlighting positions are inaccurate when searching and highlighting text. |
| Bug | SPIREPDF-7039 | Fixes the issue that the program threw "ffi_prep_cif_var failed" exception when extracting text on Ubuntu 22 systems. |
| Bug | SPIREXLS-5598 | Fixes the issue that an exception was thrown when Spire.XLS and Spire.PDF were used at the same time. |
Spire.Presentation for Python
| Category | ID | Description |
| New feature | SPIREPPT-2575 | Supports the functionality to get the slides from "section".
ppt = Presentation()
ppt.LoadFromFile(inputFile)
section=ppt.SectionList[0]
slides=section.GetSlides()
sb = [] i=0 for slide in slides:
sb.append("SlideID:"+str(slides[i].SlideID))
i=i+1
File.AppendAllText(outputFile, sb)
ppt.Dispose
|
| New feature | SPIREPPT-2605 | Supports the functionality to get the Left and Top values of SmartArt.
# Create a Presentation oject
presentation = Presentation()
# Load a PowerPoint document
presentation.LoadFromFile(inputFile)
sb = []
# Get custom document properties
for shape in presentation.Slides[0].Shapes:
if isinstance(shape, ISmartArt):
sa = shape if isinstance(shape, ISmartArt) else None
sb.append("left: " + str(sa.Left))
sb.append("top: " + str(sa.Top))
File.AppendAllText(outputFile, sb)
presentation.Dispose()
|
| New feature | SPIREPPT-2621 | Supports the DisplayFormat property.
# Create a Presentation oject
presentation = Presentation()
presentation.LoadFromFile(inputFile)
shape = presentation.Slides[0].Shapes[0]
textrange = shape.TextFrame.Paragraphs[0].TextRanges[0]
displayformat = textrange.DisplayFormat
sb = []
sb.append("text :" + str(textrange.Text))
sb.append("is bold :" + str(displayformat.IsBold))
sb.append("is italic :" + str(displayformat.IsItalic))
sb.append("latin_font FontName = :" + str(displayformat.LatinFont.FontName))
File.AppendAllText(outputFile, sb)
presentation.Dispose()
|
| Bug | SPIREPPT-2503 | Fixes the issue that errors occurred when using SlideCountPerPageForPrint and ContainingHiddenSlides methods. |
| Bug | SPIREPPT-2564 SPIREPPT-2566 |
Fixes the issue that there were incorrect layouts when converting PPT to PDF. |
| Bug | SPIREPPT-2618 | Optimized the time consumption issue of converting PPT to images. |
| Bug | SPIREPPT-2620 | Fixes the issue that the program threw "Microsoft PowerPoint 2007 file is corrpt" error when loading a PowerPoint document. |
| Bug | SPIREPPT-2660 | Fixes the issue that the program threw "ArgumentNullException" error when saving slides to pictures. |
| Bug | SPIREPPT-2662 | Fixes the issue that the size of pictures extracted from PowerPoint documents was incorrect. |
| Bug | SPIREPPT-2664 | Fixes the issue that the program threw "ArgumentNullException" error when saving shapes to images. |