Wednesday, 07 August 2024 00:58

Python: Delete Annotations from PDF Documents

Managing PDF documents often involves removing annotations. Whether you're preparing documents for a presentation, sharing the final files with clients when questions are settled down, or archiving important records, deleting annotations can be essential.

Spire.PDF for Python allows users to delete annotations from PDFs in Python efficiently. Follow the instructions below to clean up your PDF files seamlessly.

Install Spire.PDF for Python

This scenario requires Spire.PDF for Python and plum-dispatch v1.7.4. They can be easily installed in your Windows through the following pip command.

pip install Spire.PDF

If you are unsure how to install it, please refer to this tutorial: How to Install Spire.PDF for Python on Windows.

Delete Specified Annotations from PDF in Python

To delete a specified annotation from PDF documents, you need to target the annotation to be removed at first. Then you can remove it by calling the Page.AnnotationsWidget.RemoveAt() method offered by Spire.PDF for Python. This section will guide you through the whole process step by step.

Steps to remove an annotation from a page:

  • Create a new Document object.
  • Load a PDF document from files using Document.LoadFromFile() method.
  • Get the specific page of the PDF with Document.Pages.get_Item() method.
  • Delete the annotation from the page by calling Page.AnnotationsWidget.RemoveAt() method.
  • Save the resulting document using Document.SaveToFile() method.

Here's the code example for you to refer to:

  • Python
from spire.pdf.common import *
from spire.pdf import *

# Create a new PDF document
doc = PdfDocument()

# Open the PDF document to be modified from the disk
doc.LoadFromFile("sample1.pdf")

# Get the first page of the document
page = doc.Pages.get_Item(0)

# Remove the 2nd annotation from the page
page.AnnotationsWidget.RemoveAt(1)

# Save the PDF document
doc.SaveToFile("output/delete_2nd_annotation.pdf", FileFormat.PDF)

doc.Close()

Python: Delete Annotations from PDF Documents

Delete All Annotations from a PDF Page in Python

The Pages.AnnotationsWidget.Clear() method provided by Spire.PDF for Python helps you to complete the task of removing each annotation from a page. This part will demonstrate how to delete all annotations from a page in Python with a detailed guide and a code example.

Steps to delete all annotations from a page:

  • Create an instance of the Document class.
  • Read the PDF document from the disk by Document.LoadFromFile() method.
  • Remove annotations on the page using Pages.AnnotationsWidget.Clear() method.
  • Write the document to disk with Document.SaveToFile() method.

Below is the code example of deleting annotations from the first page:

  • Python
from spire.pdf.common import *
from spire.pdf import *


# Create a new PDF document
document = PdfDocument()

# Load the file from the disk
document.LoadFromFile("sample1.pdf")

# Remove all annotations from the first page
document.Pages[0].AnnotationsWidget.Clear()

# Save the document
document.SaveToFile("output/delete_annotations_page.pdf", FileFormat.PDF)

document.Close()

Python: Delete Annotations from PDF Documents

Delete All Annotations of PDF Documents in Python

Removing all annotations from a PDF document involves retrieving the annotations first, which means you need to loop through each page to ensure that every annotation is deleted. The section will introduce how to accomplish the task in Python, providing detailed steps and an example to assist in cleaning up PDF documents.

Steps to remove all annotations of the whole PDF document:

  • Instantiate a Document object.
  • Open the document from files using Document.LoadFromFile() method.
  • Loop through pages of the PDF document.
  • Get each page of the PDF document with Document.Pages.get_Item() method.
  • Remove all annotations from each page using Page.AnnotationsWidget.Clear() method.
  • Save the document to your local file with Document.SaveToFile() method.

Here is the example for reference:

  • Python
from spire.pdf.common import *
from spire.pdf import *


# Create an object of PDF class
document = PdfDocument()

# Load the file to be operated from the disk
document.LoadFromFile("sample1.pdf")

# Loop through all pages in the PDF document
for i in range(document.Pages.Count):
    # Get a specific page
    page = document.Pages.get_Item(i)
    # Remove all annotations from the page
    page.AnnotationsWidget.Clear()

# Save the resulting document
document.SaveToFile("output/delete_all_annotations.pdf", FileFormat.PDF)

document.Close()

Python: Delete Annotations from PDF Documents

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Tuesday, 06 August 2024 01:12

Python: Set Page Setup Options in Excel

Page setup in Excel refers to the various settings that control how an Excel worksheet will be printed or displayed in a print preview. These settings determine the appearance and layout of the printed document, ensuring that it meets the desired formatting and readability standards. Page setup options include page margins, orientation, paper size, print area, headers, footers, scaling, and other print-related settings. In this article, we will explain how to set page setup options in Excel in Python using Spire.XLS for Python.

Install Spire.XLS for Python

This scenario requires Spire.XLS for Python and plum-dispatch v1.7.4. They can be easily installed in your Windows through the following pip command.

pip install Spire.XLS

If you are unsure how to install, please refer to this tutorial: How to Install Spire.XLS for Python on Windows

Set Page Margins in Excel in Python

In Spire.XLS for Python, the PageSetup class is used to configure page setup options for Excel worksheets. You can access the PageSetup object of a worksheet through the Worksheet.PageSetup property. Then, you can use properties like PageSetup.TopMargin, PageSetup.BottomMargin, PageSetup.LeftMargin, PageSetup.RightMargin, PageSetup.HeaderMarginInch, and PageSetup.FooterMarginInch to set the respective margins for the worksheet. The detailed steps are as follows:

  • Create an object of the Workbook class.
  • Load an Excel file using Workbook.LoadFromFile() method.
  • Get a specific worksheet using Workbook.Worksheets[index] property.
  • Access the PageSetup object of the worksheet using Worksheet.PageSetup property.
  • Set the top, bottom, left, right, header, and footer margins using PageSetup.TopMargin, PageSetup.BottomMargin, PageSetup.LeftMargin, PageSetup.RightMargin, PageSetup.HeaderMarginInch, and PageSetup.FooterMarginInch properties.
  • Save the modified workbook to a new file using Workbook.SaveToFile() method.
  • Python
from spire.xls import *
from spire.xls.common import *

# Create a Workbook object
workbook = Workbook()
# Load an Excel file
workbook.LoadFromFile("Sample.xlsx")

# Get the first worksheet
sheet = workbook.Worksheets[0]

# Get the PageSetup object of the worksheet
pageSetup = sheet.PageSetup

# Set top, bottom, left, and right page margins for the worksheet
# The measure of the unit is Inch (1 inch = 2.54 cm)
pageSetup.TopMargin = 1
pageSetup.BottomMargin = 1
pageSetup.LeftMargin = 1
pageSetup.RightMargin = 1
pageSetup.HeaderMarginInch= 1
pageSetup.FooterMarginInch= 1

# Save the modified workbook to a new file
workbook.SaveToFile("SetPageMargins.xlsx", ExcelVersion.Version2016)
workbook.Dispose()

Python: Set Page Setup Options in Excel

Set Page Orientation in Excel in Python

To set the page orientation for an Excel worksheet, you can use the PageSetup.Orientation property. The detailed steps are as follows.

  • Create an object of the Workbook class.
  • Load an Excel file using Workbook.LoadFromFile() method.
  • Get a specific worksheet using Workbook.Worksheets[index] property.
  • Access the PageSetup object of the worksheet using Worksheet.PageSetup property.
  • Set the page orientation using PageSetup.Orientation property.
  • Save the modified workbook to a new file using Workbook.SaveToFile() method.
  • Python
from spire.xls import *
from spire.xls.common import *

# Create a Workbook object
workbook = Workbook()
# Load an Excel file
workbook.LoadFromFile("Sample.xlsx")

# Get the first worksheet
sheet = workbook.Worksheets[0]

# Get the PageSetup object of the worksheet
pageSetup = sheet.PageSetup

# Set the page orientation for printing the worksheet to landscape mode
pageSetup.Orientation = PageOrientationType.Landscape

# Save the modified workbook to a new file
workbook.SaveToFile("SetPageOrientation.xlsx", ExcelVersion.Version2016)
workbook.Dispose()

Python: Set Page Setup Options in Excel

Set Paper Size in Excel in Python

You can set a wide range of paper sizes, such as A3, A4, A5, B4, B5, Letter, Legal, and Tabloid for printing an Excel worksheet using the PageSetup.PaperSize property. The detailed steps are as follows:

  • Create an object of the Workbook class.
  • Load an Excel file using Workbook.LoadFromFile() method.
  • Get a specific worksheet using Workbook.Worksheets[index] property.
  • Access the PageSetup object of the worksheet using Worksheet.PageSetup property.
  • Set the paper size using PageSetup.PaperSize property.
  • Save the modified workbook to a new file using Workbook.SaveToFile() method.
  • Python
from spire.xls import *
from spire.xls.common import *

# Create a Workbook object
workbook = Workbook()
# Load an Excel file
workbook.LoadFromFile("Sample.xlsx")

# Get the first worksheet
sheet = workbook.Worksheets[0]

# Get the PageSetup object of the worksheet
pageSetup = sheet.PageSetup

# Set the paper size to A4
pageSetup.PaperSize = PaperSizeType.PaperA4

# Save the modified workbook to a new file
workbook.SaveToFile("SetPaperSize.xlsx", ExcelVersion.Version2016)
workbook.Dispose()

Python: Set Page Setup Options in Excel

Set Print Area in Excel in Python

The print area of an Excel worksheet can be customized using the PageSetup.PringArea property. The detailed steps are as follows.

  • Create an object of the Workbook class.
  • Load an Excel file using Workbook.LoadFromFile() method.
  • Get a specific worksheet using Workbook.Worksheets[index] property.
  • Access the PageSetup object of the worksheet using Worksheet.PageSetup property.
  • Set the print area using PageSetup.PringArea property.
  • Save the modified workbook to a new file using Workbook.SaveToFile() method.
  • Python
from spire.xls import *
from spire.xls.common import *

# Create a Workbook object
workbook = Workbook()
# Load an Excel file
workbook.LoadFromFile("Sample.xlsx")

# Get the first worksheet
sheet = workbook.Worksheets[0]

# Get the PageSetup object of the worksheet
pageSetup = sheet.PageSetup

# Set the print area of the worksheet to "A1:E5"
pageSetup.PrintArea = "A1:E5"

# Save the modified workbook to a new file
workbook.SaveToFile("SetPrintArea.xlsx", ExcelVersion.Version2016)
workbook.Dispose()

Python: Set Page Setup Options in Excel

Set Scaling Factor in Excel in Python

You can scale the content of a worksheet to a specific percentage of its original size with the PageSetup.Zoom property. The detailed steps are as follows.

  • Create an object of the Workbook class.
  • Load an Excel file using Workbook.LoadFromFile() method.
  • Get a specific worksheet using Workbook.Worksheets[index] property.
  • Access the PageSetup object of the worksheet using Worksheet.PageSetup property.
  • Set the scaling factor using PageSetup.Zoom property.
  • Save the modified workbook to a new file using Workbook.SaveToFile() method.
  • Python
from spire.xls import *
from spire.xls.common import *

# Create a Workbook object
workbook = Workbook()
# Load an Excel file
workbook.LoadFromFile("Sample.xlsx")

# Get the first worksheet
sheet = workbook.Worksheets[0]

# Get the PageSetup object of the worksheet
pageSetup = sheet.PageSetup

# Set the scaling factor of the worksheet to 90%
pageSetup.Zoom = 90

# Save the modified workbook to a new file
workbook.SaveToFile("SetScalingFactor.xlsx", ExcelVersion.Version2016)
workbook.Dispose()

Python: Set Page Setup Options in Excel

Set FitToPages Options in Excel in Python

In addition to scaling the content of a worksheet to a specific percentage of its original size, you can also fit the content of a worksheet to a specific number of pages using PageSetup.FitToPagesTall and PageSetup.FitToPagesWide properties. The detailed steps are as follows.

  • Create an object of the Workbook class.
  • Load an Excel file using Workbook.LoadFromFile() method.
  • Get a specific worksheet using Workbook.Worksheets[index] property.
  • Access the PageSetup object of the worksheet using Worksheet.PageSetup property.
  • Fit the content of the worksheet to one page using PageSetup.FitToPagesTall and PageSetup.FitToPagesWide properties.
  • Save the modified workbook to a new file using Workbook.SaveToFile() method.
  • Python
from spire.xls import *
from spire.xls.common import *

# Create a Workbook object
workbook = Workbook()
# Load an Excel file
workbook.LoadFromFile("Sample.xlsx")

# Get the first worksheet
sheet = workbook.Worksheets[0]

# Get the PageSetup object of the worksheet
pageSetup = sheet.PageSetup

# Fit the content of the worksheet within one page vertically (i.e., all rows will fit on a single page)
pageSetup.FitToPagesTall = 1
# Fit the content of the worksheet within one page horizontally (i.e., all columns will fit on a single page)
pageSetup.FitToPagesWide = 1

# Save the modified workbook to a new file
workbook.SaveToFile("FitToPages.xlsx", ExcelVersion.Version2016)
workbook.Dispose()

Python: Set Page Setup Options in Excel

Set Headers and Footers in Excel in Python

For setting headers and footers in Excel, please check this article: Python: Add Headers and Footers to Excel.

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Friday, 02 August 2024 08:51

C#: Merge or Split Tables in Word

Tables in Word documents allow users to organize data in a clear and structured manner. However, as documents grow in complexity, the need to adjust table structures often arises. Whether you need to combine multiple tables for a comprehensive view or divide a large table for better readability, mastering the art of merging and splitting tables in Word can significantly improve the presentation of your data.  In this article, you will learn how to merge or split tables in Word in C# using Spire.Doc for .NET.

Install Spire.Doc for .NET

To begin with, you need to add the DLL files included in the Spire.Doc for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Doc

Merge Tables in Word in C#

With Spire.Doc for .NET, you can combine two or more tables into one by copying all rows from other tables to the target table and then deleting the other tables. The following are the detailed steps.

  • Create a Document instance.
  • Load a Word document using Document.LoadFromFile() method.
  • Get a specified section using Document.Sections[] property.
  • Get two tables in the section using section.Tables[] property.
  • Iterate through all rows in the second table and copy them using Table.Rows[].Clone() method.
  • Add the rows of the second table to the first table using Table.Rows.Add() method.
  • Save the result document using Document.SaveToFile() method.
  • C#
using Spire.Doc;

namespace CombineTables
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Document instance
            Document doc = new Document();

            //Load a Word document
            doc.LoadFromFile("Cost.docx");

            //Get the first section
            Section section = doc.Sections[0];

            //Get the first and second table in the section
            Table table1 = section.Tables[0] as Table;
            Table table2 = section.Tables[1] as Table;

            //Add the rows of table2 to table1
            for (int i = 0; i < table2.Rows.Count; i++)
            {
                table1.Rows.Add(table2.Rows[i].Clone());
            }

            //Remove the table2
            section.Tables.Remove(table2);

            //Save the result document
            doc.SaveToFile("CombineTables.docx", FileFormat.Docx);
        }
    }
}

C#: Merge or Split Tables in Word

Split Tables in Word in C#

To split a table into two or more tables, you need to create a new table, then copy the specified rows from the original table to the new table, and then delete those rows from the original table. The following are the detailed steps.

  • Create a Document instance.
  • Load a Word document using Document.LoadFromFile() method.
  • Get a specified section using Document.Sections[] property.
  • Get a specified table in the section using section.Tables[] property.
  • Specify the row index where the table will be split.
  • Create a new instance of the Table class.
  • Iterate through the specified rows in the original table and copy them using Table.Rows[].Clone() method.
  • Add the specified rows to the new table using Table.Rows.Add() method.
  • Iterate through the copied rows and remove each row from the original table using Table.Rows.RemoveAt() method.
  • Add the new table to the section using Section.Tables.Add() method.
  • Save the result document using Document.SaveToFile() method.
  • C#
using Spire.Doc;

namespace SplitWordTable
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Document instance
            Document doc = new Document();

            //Load a Word document
            doc.LoadFromFile("CombineTables.docx");

            //Get the first section
            Section section = doc.Sections[0];

            //Get the first table in the section
            Table table = section.Tables[0] as Table;

            //Specify to split the table from the fifth row
            int splitIndex = 4;

            //Create a new table
            Table newTable = new Table(section.Document);

            //Adds rows (from the 5th to the last row) to the new table
            for (int i = splitIndex; i < table.Rows.Count; i++)
            {
                newTable.Rows.Add(table.Rows[i].Clone());
            }

            //Delete rows from the original table
            for (int i = table.Rows.Count - 1; i >= splitIndex; i--)
            {
                table.Rows.RemoveAt(i);
            }

            //Add the new table to the section
            section.Tables.Add(newTable);

            //Save the result document
            doc.SaveToFile("SplitTable.docx", FileFormat.Docx);
        }
    }
}

C#: Merge or Split Tables in Word

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Thursday, 01 August 2024 02:55

Spire.Office for Java 9.7.0 is released

We're pleased to announce the release of Spire.Office for Java 9.7.0. This version contains many new features, such as Spire.Doc for Java supports embedding CSS and images when converting Word documents to HTML files in HTML Fixed format; Spire.Presentation for Java supports adding comments to specified text in PowerPoint; Spire.Barcode for Java supports obtaining barcode information, including barcode type, data value and vertex position information. In addition, many known issues have also been successfully fixed in this version. More details are listed below.

Click the link to download Spire.Office for Java 9.7.0:

Here is a list of changes made in this release

Spire.Doc for Java

Category ID Description
New feature SPIREDOC-10687 Supports embedding CSS and images when converting Word documents to HTML files in HTML Fixed format.
String inputFile = "1.docx";
String outputFile ="1.html";
Document doc = new Document();
doc.loadFromFile(inputFile);
doc.getHtmlExportOptions().setCssStyleSheetType(CssStyleSheetType.Internal);
doc.getHtmlExportOptions().setImageEmbedded(true);
doc.saveToFile(outputFile, FileFormat.HtmlFixed);
doc.dispose();
Bug SPIREDOC-9829
SPIREDOC-10609
Fixes the issue that the orientation of added images was incorrect.
Bug SPIREDOC-10006
SPIREDOC-10636
SPIREDOC-10692
Fixes the issue that the size of OFD documents converted from Docx documents becomes bigger.
Bug SPIREDOC-10327 Fixes the issue that watermarks in HTML documents converted from Docx documents were lost.
Bug SPIREDOC-10379
SPIREDOC-10509
SPIREDOC-10531
SPIREDOC-10650
Fixes an issue that content was lost after converting a Docx document to a PDF document.
Bug SPIREDOC-10591 Fixes an issue that the editing area was lost after converting an XML document to a Doc document.
Bug SPIREDOC-10615 Fixes the issue that the program threw an exception when converting Word to PDF under multi-threading.
Bug SPIREDOC-10623 Fixes the issue that page numbers were formatted incorrectly after converting Docx documents to PDF documents.
Bug SPIREDOC-10627 Fixes the issue that the program threw "The authentication or decryption has failed." error when converting Docx documents to PDF documents.
Bug SPIREDOC-10634
SPIREDOC-10701
Fixes the issue that the program threw an exception when converting Word to OFD under multi-threading.
Bug SPIREDOC-10670 Fixes the issue that the text orientation changed after converting Docx documents to PDF documents.
Bug SPIREDOC-10685
SPIREDOC-10697
Fixes the issue that the page numbers of requests after the second time were lost after adding a table of contents in a Web project.
Bug SPIREDOC-10713 Fixes the issue that font embedding failed when converting Docx documents to PDF documents.

Spire.PDF for Java

Category ID Description
Bug SPIREPDF-6804 Fixes the error occurred when opening compressed PDF files.
Bug SPIREPDF-6831 Fixed the issue that the effect of the PdfInkAnnotation added to PDF was incorrect.
Bug SPIREPDF-6856 Fixes the issue that the program threw "NullPointerException" when obtaining the PDF JavaScript.
Bug SPIREPDF-6865 Fixes the issue that the program threw "java.lang.NoClassDefFoundError" when compressing images with the "ImageQuality.Medium" setting.
Bug SPIREPDF-6870 Fixed the issue that the size of PDF documents was not reduced after splitting.
Bug SPIREPDF-6879 Fixes the issue of creating a PdfActionAnnotation but retrieving its type as PdfTextWebLinkAnnotationWidget.
Bug SPIREPDF-6886 Fixes the issue that the program threw "NullPointerException" when replacing text in PDF.

Spire.Presentation for Java

Category ID Description
New feature SPIREPPT-2559 Supports adding comments to specified text in PowerPoint.
Presentation ppt = new Presentation();
ISlide slide = ppt.getSlides().get(0);
IAutoShape shape = ppt.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Double(100, 250, 350, 200));
ppt.getSlides().get(0).getShapes().get(0).getLine().getFillFormat().getSolidFillColor().setColor(Color.white);
shape.getFill().setFillType(FillFormatType.SOLID);
shape.getFill().getSolidColor().setColor(Color.GRAY);
ParagraphEx paragraphEx = shape.getTextFrame().getTextRange().getParagraph();
PortionEx ex = new PortionEx("TextTextmdTextText\ttmdTextTextmdText\ttmdTextTextmdtEXT\ttTextmd");
paragraphEx.getTextRanges().append(ex);
ICommentAuthor commentAuthor = ppt.getCommentAuthors().addAuthor("test","12");
paragraphEx.addComment(commentAuthor,slide,shape,ex,"123");
String result = "result.pptx";
ppt.saveToFile(result, FileFormat.PPTX_2013);

Presentation ppt = new Presentation();
ppt.loadFromFile(inputFile);
ISlide slide = ppt.getSlides().get(0);
IAutoShape shape = (IAutoShape) slide.getShapes().get(0);
ParagraphEx paragraphEx = shape.getTextFrame().getTextRange().getParagraph();
PortionEx portionEx = paragraphEx.getTextRanges().get(0);
ICommentAuthor commentAuthor = ppt.getCommentAuthors().addAuthor("test","18");
paragraphEx.addComment(commentAuthor,slide,shape,portionEx,"123456789");
String result = "result.pptx";
ppt.saveToFile(result, FileFormat.PPTX_2013);
Bug SPIREPPT-2550 Fixes the issue that the shape height was incorrect after adding content to the shape.
Bug SPIREPPT-2560 Fixes the issue that the effect of modifying the shape position was incorrect.
Bug SPIREPPT-2561 Fixes the issue that the greater-than and less-than symbols in Latex formulas were parsed incorrectly.

Spire.Barcode for Java

Category ID Description
New feature SPIREBARCODE-258 The BarcodeScanner class supports obtaining barcode information, including barcode type, data value and vertex position information.
BarcodeInfo[] infos = BarcodeScanner.scanInfo("barcode.png");
Point[] loaction = infos[0].getVertexes();
BarCodeReadType barCodeReadType = infos[0].getReadType();
String dataString =  infos[0].getDataString();
New feature - The BarcodeScanner class supports scanning Aztec type.
String[] s = BarcodeScanner.scan("AZTEC.png",BarCodeType.Aztec);
New feature - The BarcodeScanner class supports scanning with more overload settings.
Public static String[] scan(BufferedImage bitmap, java.awt.Rectangle rect, BarCodeType barcodeType, boolean IncludeCheckSum)
Public static String[] scan(String fileName, BarCodeType barcodeType, boolean IncludeCheckSum)
Public static String scanOne(String fileName, BarCodeType barcodeType, boolean IncludeCheckSum)
Public static String scanOne(InputStream stream, BarCodeType barcodeType, boolean IncludeCheckSum)
New feature - Adds external use enumerations.
com.spire.barcode.publics.drawing.FontStyle
com.spire.barcode.publics.drawing.GraphicsUnit
com.spire.barcode.publics.drawing.StringAlignment
New feature - Adjustments to the IBarCodeSettings interface.

Recycled:

public java.awt.Font getTopTextFont()
public java.awt.Font getBottomTextFont()
public java.awt.Font getTextFont()

Modified:

public void setBottomTextFont(java.awt.Font value)->public void setBottomTextFont(String familyName, float fontSize)
public void setTopTextFont(java.awt.Font value)->public void setTopTextFont(String familyName, float fontSize)
public boolean showBottomText->public boolean isShowBottomText()
public void setShowBottomText(boolean value) -> public void isShowBottomText(boolean value)
public com.spire.barcode.GraphicsUnit getUnit() -> public com.spire.barcode.publics.drawing.GraphicsUnit getUnit()
public void setUnit(com.spire.barcode.GraphicsUnit value) -> public void setUnit(com.spire.barcode.publics.drawing.GraphicsUnit value)
public void setTextFont(java.awt.Font value) -> public void setTextFont(String familyName, float fontSize)
public float getLeftMargin() ->The default value adjusted from 5 to 4. 

Newly Added:

public float getTopTextMargin()  
public void setTopTextMargin(float value)
public int getAztecErrorCorrection()
public void setAztecErrorCorrection(int value)
public int getAztecLayers()
public void setAztecLayers(int value)
public DataMatrixSymbolShape getDataMatrixSymbolShape()
public void setDataMatrixSymbolShape(DataMatrixSymbolShape value)
public ITF14BorderType getITF14BearerBars() 
public void setITF14BearerBars(ITF14BorderType value)
public void setTextFont(String familyName, float fontSize, com.spire.barcode.publics.drawing.FontStyle style)
public boolean isShowStartCharAndStopChar()
public void isShowStartCharAndStopChar(boolean value)
New feature - Adjustments to the BarcodeSettings class interfaces.

Recycled:

public java.awt.Font getTextFont()
public java.awt.Font getTopTextFont() 
public java.awt.Font getBottomTextFont()

Modified:

public void setTextFont(java.awt.Font value) -> public void setTextFont(String familyName, float sizePoints)
public com.spire.barcode.GraphicsUnit getUnit() -> public com.spire.barcode.publics.drawing.GraphicsUnit getUnit()
public void setUnit(com.spire.barcode.GraphicsUnit value) -> public void setUnit(com.spire.barcode.publics.drawing.GraphicsUnit value)
public com.spire.barcode.StringAlignment getTextAlignment() -> public com.spire.barcode.publics.drawing.StringAlignment getTextAlignment()
public void setTextAlignment(com.spire.barcode.StringAlignment value) -> public void setTextAlignment(com.spire.barcode.publics.drawing.StringAlignment value)
public com.spire.barcode.StringAlignment getTopTextAligment() -> public com.spire.barcode.publics.drawing.StringAlignment getTopTextAligment()
public void setTopTextAligment(com.spire.barcode.StringAlignment value) -> public void setTopTextAligment(com.spire.barcode.publics.drawing.StringAlignment value)
public void setBottomTextFont(java.awt.Font value) -> public void setBottomTextFont(String familyName, float fontSize)
public void setTopTextFont(java.awt.Font value) -> public void setTopTextFont(String familyName, float fontSize)
public boolean showBottomText->public boolean isShowBottomText()
public void setShowBottomText(boolean value) -> public void isShowBottomText(boolean value)
public com.spire.barcode.StringAlignment getBottomTextAlignment() -> public com.spire.barcode.publics.drawing.StringAlignment getBottomTextAlignment()
public void setBottomTextAlignment(com.spire.barcode.StringAlignment value) -> public void setBottomTextAlignment(com.spire.barcode.publics.drawing.StringAlignment value)
public float getLeftMargin() ->The default value adjusted from 5 to 4. 

Newly Added:

public float getTopTextMargin()
public void setTopTextMargin(float value)
public void setTextFont(String familyName, float sizePoints, com.spire.barcode.publics.drawing.FontStyle style)
public void setTopTextFont(String familyName, float fontSize, com.spire.barcode.publics.drawing.FontStyle style)
public void setITF14BearerBars(ITF14BorderType value)
public boolean isShowStartCharAndStopChar()
public void isShowStartCharAndStopChar(boolean value)
public int getAztecLayers()
public void setAztecLayers(int value)
public int getAztecErrorCorrection()
public void setAztecErrorCorrection(int value)
public DataMatrixSymbolShape getDataMatrixSymbolShape()
public void setDataMatrixSymbolShape(DataMatrixSymbolShape value)
public void setBottomTextFont(String familyName, float fontSize, com.spire.barcode.publics.drawing.FontStyle style)

Spire.OCR for Java

Category ID Description
New feature - Adds the ConfigureOptions class and new method ConfigureDependencies(ConfigureOptions configureOptions), which supports configuring OCR models, languages, and dependency libraries.
import com.spire.ocr.*;
import java.awt.geom.Rectangle2D;

public class OCRTest {
    public static void main(String[] args) throws Exception{
        OcrScanner scanner = new OcrScanner();
        ConfigureOptions configureOptions = new ConfigureOptions("D:\\LanguageModel", "English");
        String dependencies = "dependencies/";
        configureOptions.setLibPath(dependencies);
        scanner.ConfigureDependencies(configureOptions);
        String imageFile = "Sample.png";
        scanner. scan(imageFile);
        String scannedText=scanner.getText().toString();

        StringBuilder stringBuilder=new StringBuilder();
        for(IOCRTextBlock blockItem :scanner.getText().getBlocks()){
            Rectangle2D rectangle2D=blockItem.getBox();
            stringBuilder.append(blockItem.getText() +","+ "X"+ rectangle2D.getX()+"; Y:"+rectangle2D.getY()+ "; Width:"+ rectangle2D.getWidth()+ "; Height:"+ rectangle2D.getHeight());
        }
    }
}

We are delighted to announce the release of Spire.Doc for Java 12.7.17. This version supports embedding CSS and images when converting Word documents to HTML files in HTML Fixed format. Besides, it also enhances the conversion from DOCX to OFD, HTML, and PDF. Moreover, a lot of known issues are fixed successfully in this version, such as the issue that the orientation of the added image was not correct. More details are listed below.

Here is a list of changes made in this release

Category ID Description
New feature SPIREDOC-10687 Supports embedding CSS and images when converting Word documents to HTML files in HTML Fixed format.
String inputFile = "1.docx";
String outputFile ="1.html";
Document doc = new Document();
doc.loadFromFile(inputFile);
doc.getHtmlExportOptions().setCssStyleSheetType(CssStyleSheetType.Internal);
doc.getHtmlExportOptions().setImageEmbedded(true);
doc.saveToFile(outputFile, FileFormat.HtmlFixed);
doc.dispose();
Bug SPIREDOC-9829
SPIREDOC-10609
Fixes the issue that the orientation of added images was incorrect.
Bug SPIREDOC-10006
SPIREDOC-10636
SPIREDOC-10692
Fixes the issue that the size of OFD documents converted from Docx documents becomes bigger.
Bug SPIREDOC-10327 Fixes the issue that watermarks in HTML documents converted from Docx documents were lost.
Bug SPIREDOC-10379
SPIREDOC-10509
SPIREDOC-10531
SPIREDOC-10650
Fixes an issue that content was lost after converting a Docx document to a PDF document.
Bug SPIREDOC-10591 Fixes an issue that the editing area was lost after converting an XML document to a Doc document.
Bug SPIREDOC-10615 Fixes the issue that the program threw an exception when converting Word to PDF under multi-threading.
Bug SPIREDOC-10623 Fixes the issue that page numbers were formatted incorrectly after converting Docx documents to PDF documents.
Bug SPIREDOC-10627 Fixes the issue that the program threw "The authentication or decryption has failed." error when converting Docx documents to PDF documents.
Bug SPIREDOC-10634
SPIREDOC-10701
Fixes the issue that the program threw an exception when converting Word to OFD under multi-threading.
Bug SPIREDOC-10670 Fixes the issue that the text orientation changed after converting Docx documents to PDF documents.
Bug SPIREDOC-10685
SPIREDOC-10697
Fixes the issue that the page numbers of requests after the second time were lost after adding a table of contents in a Web project.
Bug SPIREDOC-10713 Fixes the issue that font embedding failed when converting Docx documents to PDF documents.
Click the link below to download Spire.Doc for Java 12.7.17:

We are pleased to announce the release of Spire.Presentation for Java 9.7.6. This version supports adding comments to specified text in PowerPoint, and also fixes some known issues, such as the incorrect shape height after adding content to the shape. More details are listed below.

Here is a list of changes made in this release

Category ID Description
New feature SPIREPPT-2559 Supports adding comments to specified text in PowerPoint.
Presentation ppt = new Presentation();
ISlide slide = ppt.getSlides().get(0);
IAutoShape shape = ppt.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Double(100, 250, 350, 200));
ppt.getSlides().get(0).getShapes().get(0).getLine().getFillFormat().getSolidFillColor().setColor(Color.white);
shape.getFill().setFillType(FillFormatType.SOLID);
shape.getFill().getSolidColor().setColor(Color.GRAY);
ParagraphEx paragraphEx = shape.getTextFrame().getTextRange().getParagraph();
PortionEx ex = new PortionEx("TextTextmdTextText\ttmdTextTextmdText\ttmdTextTextmdtEXT\ttTextmd");
paragraphEx.getTextRanges().append(ex);
ICommentAuthor commentAuthor = ppt.getCommentAuthors().addAuthor("test","12");
paragraphEx.addComment(commentAuthor,slide,shape,ex,"123");
String result = "result.pptx";
ppt.saveToFile(result, FileFormat.PPTX_2013);

Presentation ppt = new Presentation();
ppt.loadFromFile(inputFile);
ISlide slide = ppt.getSlides().get(0);
IAutoShape shape = (IAutoShape) slide.getShapes().get(0);
ParagraphEx paragraphEx = shape.getTextFrame().getTextRange().getParagraph();
PortionEx portionEx = paragraphEx.getTextRanges().get(0);
ICommentAuthor commentAuthor = ppt.getCommentAuthors().addAuthor("test","18");
paragraphEx.addComment(commentAuthor,slide,shape,portionEx,"123456789");
String result = "result.pptx";
ppt.saveToFile(result, FileFormat.PPTX_2013);
Bug SPIREPPT-2550 Fixes the issue that the shape height was incorrect after adding content to the shape.
Bug SPIREPPT-2560 Fixes the issue that the effect of modifying the shape position was incorrect.
Bug SPIREPPT-2561 Fixes the issue that the greater-than and less-than symbols in Latex formulas were parsed incorrectly.
Click the link below to download Spire.Presentation for Java 9.7.6:

Removing images from slides and slide masters can be essential for many reasons, such as decluttering slides, maintaining uniformity, preparing templates, or modifying a template.  Using Python, you can easily handle this task in seconds.

This guide will demonstrate removing images from slides and slide masters in PowerPoint documents in Python with Spire.Presentation for Python. Check this page and make a clean presentation.

Install Spire.Presentation for Python

This scenario requires Spire.Presentation for Python and plum-dispatch v1.7.4. They can be easily installed in your Windows through the following pip command.

pip install Spire.Presentation

If you are unsure how to install it, please refer to this tutorial: How to Install Spire. Presentation for Python on Windows.

Remove Images from Slides of PowerPoint in Python

Removing images from PowerPoint slides can be efficiently managed using Python. The Presentation.Shapes.RemoveAt() method published by Spire. Presentation for Python allows users to delete pictures from a PowerPoint presentation without effort. The following instructions will guide you through the whole process.

Steps to remove images from a slide:

  1. Create an object for the Presentation class.
  2. Load the target PowerPoint document to be operated with the Presentation.LoadFromFile() method.
  3. Get the slide that you want to modify using the Presentation.Slides[] property.
  4. Loop through shapes on the slide.
  5. Determine if these shapes are images.
  6. Remove images from the slide using the Presentation.Shapes.RemoveAt() method.
  7. Save the resulting PowerPoint document with the Presentation.SaveToFile() method.

Here's the code example for reference:

  • Python
from spire.presentation.common import *
from spire.presentation import *


# Create a Presentation object
ppt = Presentation()
# Load the PowerPoint document to be modified from the disk
ppt.LoadFromFile("sample.pptx")

# Get the fifth slide
slide = ppt.Slides[4]

# Loop through shapes on the slide
for i in range(slide.Shapes.Count - 1, -1, -1):
    # Check if those shapes are images
    if isinstance(slide.Shapes[i], SlidePicture):
        # Remove pictures on the fifth slide
        slide.Shapes.RemoveAt(i)


# Save to file
ppt.SaveToFile("removepic_slide.pptx", FileFormat.Pptx2013)

# Release the resources
ppt.Dispose()

Python: Remove Images from Slides and Slide Masters in PowerPoint

Remove Images from Slide Masters of PowerPoint Using Python

Removing images from slide masters is basically the same as doing that from a slide. To apply this action, you can use Presentation.Shapes.RemoveAt() method provided by Spire.Presentation for Python. Check out the steps below and make a nice and clean presentation.

Steps to remove images from Slide Masters:

  1. Instantiate a Presentation object.
  2. Read the PowerPoint document from disk using the Presentation.LoadFromFile() method.
  3. Get the second Slide Master with the Presentation.Masters[] property.
  4. Iterate through images on the second Slide Master.
  5. Confirm whether these shapes are images.
  6. Remove images from the second Slide Master using the Shapes.RemoveAt() method.
  7. Save the modified document with the Presentation.SaveToFile() method.

Here's the code example:

  • Python
from spire.presentation.common import *
from spire.presentation import *


# Create an instance of the Presentation class
pre = Presentation()
# Open the sample PowerPoint document from the disk
pre.LoadFromFile("sample.pptx")

# Retrieve the first Slide Master
master = pre.Masters[0]

# Loop through shapes on the slide master
for i in range(master.Shapes.Count - 1, -1, -1):
    # Check whether these shapes are images
    if isinstance(master.Shapes[i], SlidePicture):
        # Remove images on the first slide master
        master.Shapes.RemoveAt(i)


# Save the generated file
pre.SaveToFile("removepic_slidemaster.pptx", FileFormat.Pptx2013)

# Release the resources
pre.Dispose()

Python: Remove Images from Slides and Slide Masters in PowerPoint

Delete Specified Images from Slides with Python

When working with PowerPoint presentations, you may need to remove specific images from your slides to refine your content. The guide below will walk you through targeting and removing specified images from a slide.

Steps to delete specified images:

  • Instantiate an object of the Presentation class.
  • Load the target file from the disk with the Presentation.LoadFromFile() method.
  • Create a list to store image indexes.
  • Get the 5th slide using the Presentation.Slides[] property.
  • Loop through shapes on the slide.
  • Verify whether these shapes are images.
  • Find the 1st and 3rd pictures.
  • Delete these two pictures by the Shapes.RemoveAt() method.
  • Save the generated presentation using the Presentation.SaveToFile() method.

Below is the code example to refer to:

  • Python
from spire.presentation.common import *
from spire.presentation import *


# Create a Presentation object
ppt = Presentation()
# Load the PowerPoint document from the disk
ppt.LoadFromFile("sample1.pptx")

# Create a list to keep track of image indexes to delete
indexes = []

# Get the fifth slide
slide = ppt.Slides[4]

# Iterate through shapes on the slide
image_index = 0
for i in range(slide.Shapes.Count - 1, -1, -1):
    # Check if shapes are pictures
    if isinstance(slide.Shapes[i], SlidePicture):
        image_index += 1
        # Record indexes of the first and third images
        if image_index in (1, 3):
            indexes.append(i)


# Remove the first and third images
for index in indexes:
    slide.Shapes.RemoveAt(index)

# Save to file
ppt.SaveToFile("removepic_first_and_third.pptx", FileFormat.Pptx2013)

# Release the resources
ppt.Dispose()

Python: Remove Images from Slides and Slide Masters in PowerPoint

Delete Specified Images from Slide Masters in Python

Shapes.RemoveAt() method also supports removing a specified image from a slide master. To complete the task, you need to target the picture to be deleted. Refer to the detailed steps and a code example to finish the process.

Steps to remove a specified picture from a slide master:

  • Create a new object for the Presentation class.
  • Read the document from the disk using the Presentation.LoadFromFlie() method.
  • Retrieve the 1st slide master by the Presentation.Masters[] property.
  • Iterate through shapes on the slide master.
  • Check if these shapes are images.
  • Remove the 2nd picture with the Shapes.RemoveAt() method.
  • Save the resulting presentation to the disk using the Presentation.SaveToFile() method.

Here is the code example:

  • Python
from spire.presentation.common import *
from spire.presentation import *

# Create an instance of the Presentation class
pre = Presentation()
# Open the sample PowerPoint document from the disk
pre.LoadFromFile("sample1.pptx")

# Retrieve the first Slide Master
master = pre.Masters[0]

# Loop through the shapes in reverse order
for i in range(master.Shapes.Count - 1, -1, -1):
    # Check whether shapes are images
    if isinstance(master.Shapes[i], SlidePicture):
        # Remove the second image from the slide master
        if i == 1:
            master.Shapes.RemoveAt(i)
            break  


# Save the generated file
pre.SaveToFile("removepic_2nd.pptx", FileFormat.Pptx2013)

# Release the resources
pre.Dispose()

Python: Remove Images from Slides and Slide Masters in PowerPoint

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

We're pleased to announce the release of Spire.XLS for Python 14.7.3. This version fixes the issue that an exception was thrown when using some features of Spire.XLS on Ubuntu 22. More details are listed below.

Here is a list of changes made in this release

Category ID Description
Bug - Fix the issue that errors are reported when running on Ubuntu22.
Click the link to download Spire.XLS for Python 14.7.3:

We are excited to announce the release of Spire.Office for Python 9.7.0. In this version, Spire.PDF for Python supports converting PDF to PPTX and adds new interfaces for encrypting and decrypting PDF documents. Moreover, many known issues are fixed successfully in this version. More details are listed below.

Click the following link to download Spire.Office for Python 9.7.0:

Here is a list of changes made in this release

Spire.PDF for Python

Category ID Description
New feature SPIREPDF-6830 Adds new encryption and decryption interfaces for PDF documents.
# Encryption 
pdfDocument = PdfDocument()
securityPolicy = PdfPasswordSecurityPolicy("123456789", "M123456789")
securityPolicy.EncryptionAlgorithm = PdfEncryptionAlgorithm.AES_128
securityPolicy.DocumentPrivilege = PdfDocumentPrivilege.ForbidAll()
securityPolicy.DocumentPrivilege.AllowPrint = True
pdfDocument.Encrypt(securityPolicy)

pdfMargin = PdfMargins()
unitCvtr = PdfUnitConvertor()
pdfMargin.Left = unitCvtr.ConvertUnits(0, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point)
pdfMargin.Right = unitCvtr.ConvertUnits(0,PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point)
pdfMargin.Top = unitCvtr.ConvertUnits(0, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point)
pdfMargin.Bottom = unitCvtr.ConvertUnits(0, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point)
pageSize = PdfPageSize.A4()

spirePage = pdfDocument.Pages.Add(pageSize, pdfMargin)
pdfDocument.SaveToFile("1.pdf", FileFormat.PDF)
pdfDocument.Dispose()

# Decryption
pdfDocument = PdfDocument()
pdfDocument.LoadFromFile("input.pdf","123456789")
pdfDocument.Decrypt("M123456789")
pdfDocument.SaveToFile("output.pdf", FileFormat.PDF)
pdfDocument.Dispose()
New feature SPIREPDF-6853 Adds a method to delete images.
pdf = PdfDocument()
pdf.LoadFromFile(inputfile)
page = pdf.Pages[0]
imageHelper = PdfImageHelper()
imageInfos = imageHelper.GetImagesInfo(page)
imageHelper.DeleteImage(imageInfos[0])
pdf.SaveToFile(outputFile, FileFormat.PDF)
pdf.Close()
New feature SPIREPDF-6861 Supports converting PDF documents to PPTX documents.
pdfDocument = PdfDocument()
pdfDocument.LoadFromFile("Sample.pdf")
pdfDocument.SaveToFile("ConvertPDFtoPowerPoint.pptx", FileFormat.PPTX)
Bug SPIREPDF-6511 Fixes the issue that the application threw "Cannot find table 'loca' in the font file" when loading SVG files.
Bug SPIREPDF-6737 Fixes the issue that the hyperlinks became inactive after converting PDF documents to PDF/A documents.
Bug SPIREPDF-6817 Fixes the issue that the red annotations were lost after converting PDF documents to HTML documents.

Spire.Doc for Python

Category ID Description
Bug SPIREDOC-10388
SPIREDOC-10512
SPIREDOC-10552
SPIREDOC-10645
Fixes the issue that "ffi_prep_cif_var failed" exception was thrown when using some features of Spire.Doc on Ubuntu 22.

Spire.Presentation for Python

Category ID Description
Bug SPIREPPT-2433 Fixes the issue that the position of shapes changed after ungrouping them.
Bug SPIREPPT-2444 Fixes the issue that getting custom properties of a document failed.
Bug SPIREPPT-2446 Fixes the issue that added custom properties were displayed incorrectly.

Spire.XLS for Python

Category ID Description
Bug - Fix the issue that errors are reported when running on Ubuntu22.

Converting XLS files to various formats is necessary for data management and presentation. ODS, XPS, PostScript, and PDF/A-1b offer unique advantages and are suitable for different scenarios.

ODS is widely used for compatibility with many office suites. XPS preserves document fidelity and is ideal for sharing and archiving. PostScript is a versatile page description language often used for printing and graphic design. PDF/A-1b ensures long-term archiving by complying with strict preservation standards.

This guide will illustrate how to convert Excel to ODS, XPS, PostScript, and PDF/A-1b with Python using Spire.XLS for Python, leveraging their specific strengths to meet diverse needs.

Install Spire.XLS for Python

This scenario requires Spire.XLS for Python and plum-dispatch v1.7.4. They can be easily installed in your Windows through the following pip command.

pip install Spire.XLS

If you are unsure how to install it, please refer to this tutorial: How to Install Spire.XLS for Python on Windows.

Convert Excel to ODS, XPS, and PostScript with Python

To convert Excel to ODS, XPS, and PostScript documents, you can utilize Workbook.SaveToFile() method. It supports converting CSV to Excel and PDF, Excel to PDF and XLSX, etc. By using this method provided by Spire.XLS for Python, you can seamlessly transform your documents into these formats while maintaining accuracy without data loss. Read the following steps to learn more:

Steps to convert Excel to ODS, XPS, and PostScript:

  1. Create a new Workbook object.
  2. Import the file to be converted from the disk using Workbook.LoadFromFile() method.
  3. Convert it to ODS, XPS, or PostScript with Workbook.SaveToFile() method.

Here is the code example for reference:

  • Python
from spire.xls import *
from spire.xls.common import *

# Create a Workbook object
workbook = Workbook()

# Load the file from the disk
workbook.LoadFromFile("sample.xlsx")

# Save the document to an ODS file
workbook.SaveToFile("to_ods.ods", FileFormat.ODS)
# Save the document as an XPS file
workbook.SaveToFile("to_xps.xps", FileFormat.XPS)
# Save the document as a PostScript file
workbook.SaveToFile("to_postscript.ps", FileFormat.PostScript)

workbook.Dispose()

Python: Convert Excel to ODS, XPS, PostScript and PDF/A-1b

Note: Images 1, 2, and 3 show the results of converting Excel files to ODS, XPS, and PostScript formats, respectively.

How to Convert Excel Documents to PDF/A-1b Format

If you need to convert Excel to PDF/A-1b Format with Python, call Workbook.SaveToFile will help you. The steps to transform Excel documents to PDF/A-1b are similar to those above, except the former involves an additional step. This tutorial will guide you through the process with detailed steps and a code example.

Steps to convert Excel to PDF/A-1b

  1. Instantiate a new Workbook object.
  2. Read the Excel document from the disk using Workbook.LoadFromFile() method.
  3. Set the PDF conformance level to PDF/A-1b.
  4. Save the generated document as PDF with Workbook.SaveToFile() method.

Here is the code example for you:

  • Python
from spire.xls import *
from spire.xls.common import *

# Create a Workbook object
workbook = Workbook()

# Open the file from the disk
workbook.LoadFromFile("sample.xlsx")

# Set the PDF conformance to PDF/A-1b
workbook.ConverterSetting.PdfConformanceLevel = PdfConformanceLevel.Pdf_A1B
# Convert the Excel document to PDF/A-1b
workbook.SaveToFile("to_pdfa1b", FileFormat.PDF)

workbook.Dispose()

Python: Convert Excel to ODS, XPS, PostScript and PDF/A-1b

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Page 5 of 239