diff --git a/pdfmajor/__init__.py b/pdfmajor/__init__.py
index 403231f..96fc528 100644
--- a/pdfmajor/__init__.py
+++ b/pdfmajor/__init__.py
@@ -75,7 +75,7 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
-__version__ = (1, 0, 4)
+__version__ = (1, 0, 6)
if __name__ == '__main__':
print(
diff --git a/pdfmajor/converters/PDFConverter.py b/pdfmajor/converters/PDFConverter.py
index 080cff1..c9c6955 100644
--- a/pdfmajor/converters/PDFConverter.py
+++ b/pdfmajor/converters/PDFConverter.py
@@ -28,13 +28,17 @@ class PDFConverter(PDFLayoutAnalyzer):
caching: bool = True,
check_extractable: bool = True,
pagenos: List[int] = None,
+ dont_export_images: bool = False,
debug: bool = False,
) -> TextIOWrapper:
if debug:
log.setLevel(logging.DEBUG)
- if image_folder_path is None:
+ if dont_export_images:
+ image_folder_path = None
+
+ if not dont_export_images and image_folder_path is None and output_file.name is not None:
image_folder_path = os.path.dirname(output_file.name)
log.debug("Creating resources....")
@@ -50,6 +54,7 @@ class PDFConverter(PDFLayoutAnalyzer):
log.debug("Reading pages....")
pages = PDFPage.get_pages(input_file, pagenos=pagenos, maxpages=maxpages, password=password, caching=caching, check_extractable=check_extractable)
for idx, page in enumerate(pages):
+ log.debug(f"Reading page #{idx}")
interpreter.process_page(page)
device.close()
return output_file
diff --git a/pdfmajor/converters/XMLConverter.py b/pdfmajor/converters/XMLConverter.py
index a9a0da7..5dd29db 100644
--- a/pdfmajor/converters/XMLConverter.py
+++ b/pdfmajor/converters/XMLConverter.py
@@ -42,8 +42,8 @@ class XMLConverter(PDFConverter):
self.__levels_deep = 0
self.write_header()
- def write(self, text: str):
- text = " "*self.__levels_deep + text + '\n'
+ def write(self, text: str, lineend: str = '\n', deep_space: str = ' '):
+ text = deep_space*self.__levels_deep + text + lineend
self.write_raw(text)
def write_raw(self, text):
@@ -64,16 +64,21 @@ class XMLConverter(PDFConverter):
self.write('')
@contextmanager
- def place_elm_with_child(self, tag_name: str, attr_dict: Dict[str, str] = {}):
+ def place_elm_with_child(self, tag_name: str, attr_dict: Dict[str, str] = {}, no_additional_char = False):
+ lineend = '\n'
+ deep_space = ' '
+ if no_additional_char:
+ lineend = ''
+ deep_space = ''
attrs = " ".join([
f'{name}="{value}"'
for name, value in attr_dict.items()
])
- self.write(f"<{tag_name} {attrs}>")
+ self.write(f"<{tag_name} {attrs}>", lineend=lineend)
self.__levels_deep += 1
yield
self.__levels_deep -= 1
- self.write(f"{tag_name}>")
+ self.write(f"{tag_name}>", deep_space=deep_space)
def place_elm_close(self, tag_name: str, attr_dict: Dict[str, str] = {}, as_childless = True):
attrs = " ".join([
@@ -117,8 +122,8 @@ class XMLConverter(PDFConverter):
"y1": char.y1,
"stroke-color": get_color(char.graphicstate.scolor),
"fill-color": get_color(char.graphicstate.ncolor),
- }):
- self.write(char.get_text())
+ }, no_additional_char=True):
+ self.write(char.get_text(), lineend='', deep_space="")
def render_curve(self, item: LTCurve):
attr = {
diff --git a/pdfmajor/imagewriter/__init__.py b/pdfmajor/imagewriter/__init__.py
index 6386d9d..78b1bbd 100644
--- a/pdfmajor/imagewriter/__init__.py
+++ b/pdfmajor/imagewriter/__init__.py
@@ -60,13 +60,19 @@ class BMPWriter(object):
##
class ImageWriter(object):
- def __init__(self, outdir: str):
- self.outdir = outdir
- if not os.path.exists(self.outdir):
- os.makedirs(self.outdir)
- return
+ def __init__(self, outdir: str = None):
+ if outdir is None:
+ self.inactive = True
+ else:
+ self.inactive = False
+ self.outdir = outdir
+ if not os.path.exists(self.outdir):
+ os.makedirs(self.outdir)
- def export_image(self, image: LTImage):
+ def export_image(self, image: LTImage) -> str:
+ if self.inactive:
+ return "N/A"
+
stream = image.stream
filters = stream.get_filters()
(width, height) = image.srcsize
diff --git a/samples/output/html/bar-charts.html b/samples/output/html/bar-charts.html
deleted file mode 100644
index 62124a7..0000000
--- a/samples/output/html/bar-charts.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