Package: pagexml-slim
The py-pagexml python package is a library of functions that eases working with
omni:us Pages Format XML files (referred to as OPF XML files). It allows you
from python to read an OPF file, extract information contained within, modify or
add content, create an OPF from scratch, crop parts for page images, etc.By default OPF XML files are validated against the XSD schema when reading,
saving, or on request by calling a function. The documentation the XSD schema
and the schema itself included in py-pagexml can be found at:XSD schema documentation.pagecontent_omnius.xsd.The official online documentation of py-pagexml is available athttps://omni-us.github.io/pagexml/py-pagexml.The py-pagexml package can be built with two modes: normal and slim. As the name
implies, the slim build is smaller but more importantly it has less library
dependencies. This also means that there are some features which are not
available, namely: functions related to images, e.g.PageXML.crop; and functions that perform intersections of polygons, e.g.PageXML.selectByOverlap.Software dependenciesThe core of py-pagexml is a compiled C++ library that links with a few
libraries, so it requires installation of dependencies that cannot be
automatically obtained from pypi servers.There aredocker images available at docker hubwhich include both the
runtime and the build dependencies already installed. In particular the runtime
docker images are intended to be used as base images for applications that use
pagexml. The specific list of dependencies both for runtime and building are
listed below.Runtime dependenciesSlim:python3Normal (in addition to the previous):libopencv-imgcodecs (Ubuntu 18.04/20.04) | libopencv-highgui (Ubuntu 16.04)libopencv-imgproclibopencv-corelibgdalBuilding dependenciesSlim:python3-setuptoolspython3-pkgconfigpython3-wheelpython3-devswigNormal (in addition to the previous):libopencv-devlibgdal-devlibboost-all-devInstallation from wheel binary fileIf you have configured a pypi server that includes pagexml, installation is as
simple as:pip3installpagexmlThe slim build has a different name, thus the install comand would be:pip3installpagexml_slimOtherwise you can install it from a githubrelease. Each release includes multiple
wheel files. One for python 3.5 which is built for Ubuntu 16.04, another for
python 3.6 built for Ubuntu 18.04 and another for python 3.8 built for Ubuntu
20.04. Once you have located the appropriate wheel file, copy the link and run
as follows replacing the URL with the one you copied:pip3installhttps://github.com/omni-us/pagexml/releases/download/20*/pagexml-20*-linux_x86_64.whlBuilding the wheel file from sourceClone the github repositoryhttps://github.com/omni-us/pagexml.git, go to
the py-pagexml directory and then run:pip3install--editable.[dev]./setup.pybdist_wheelTo build the slim package, give the--slimcommand line option, e.g.:./setup.pybdist_wheel--slimSimple usage examplesCreate a new Page XML adding regions, text and propertiesimportpagexmlpxml=pagexml.PageXML()# Create a new page xmlfile='example_image.jpg'width=400height=200pxml.newXml('name-and-version-of-tool',file,width,height)# Add a text region to the Pagepage=pxml.selectNth('//_:Page',0)reg=pxml.addTextRegion(page)# Set text region bounding box with a confidencepxml.setCoordsBBox(reg,10,20,80,60,0.8)# Set the text for the text region with a confidencepxml.setTextEquiv(reg,'lorem ipsum',0.9)# Add property to text regionpxml.setProperty(reg,'key','value')# Add a second page with a text region and specific idpage=pxml.addPage('example_image_2.jpg',300,300)reg=pxml.addTextRegion(page,'regA')pxml.setCoordsBBox(reg,15,12,76,128)# Write XML to filepxml.write('example_image.xml')Modify an existing Page XML# Load an existing XMLimportpagexmlpxml=pagexml.PageXML('example_image.xml')# Add content to loaded XMLpxml.setProperty(pxml.selectNth('//_:Page',0),'key','value')# Write XML to filepxml.write('example_image_2.xml')Crop an element and save image to disk# Load an existing XMLimportpagexmlpxml=pagexml.PageXML('examples/lorem.xml')# Crop element with specific IDcropped=pxml.crop('//*[@id="r1_l1"]/_:Coords')[0]# Save image to diskpagexml.imwrite(cropped.name+'.png',cropped.image)