Skip to content

Commit

Permalink
Moved pdf_burst to library
Browse files Browse the repository at this point in the history
  • Loading branch information
kthoden committed Mar 4, 2020
1 parent 3e2e66f commit 5a2d9c8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
26 changes: 3 additions & 23 deletions src/eoatex2imxml.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8; mode: python -*-
# Time-stamp: <2020-03-04 11:54:38 (kthoden)>
# Time-stamp: <2020-03-04 12:19:55 (kthoden)>

"""
Converts Latex files into a customized DocBook XML file.
Expand Down Expand Up @@ -331,26 +331,6 @@ def sanitize_bibentry(bibEntry):
# def sanitize_bibentry ends here


def pdf_burst(input_file, tmpDir):
"""Split PDF file into single pages"""
from PyPDF2 import PdfFileWriter, PdfFileReader

input1 = PdfFileReader(open(tmpDir / input_file, "rb"))
logging.debug("Input is %s and has %d pages." % (input_file, input1.getNumPages()))

for pageno in range(input1.getNumPages()):
output = PdfFileWriter()
output.addPage(input1.getPage(pageno))

output_filename = tmpDir / ("EOAformulas_%d.pdf" % (pageno + 1))
output_stream = open(output_filename, 'wb')
output.write(output_stream)
output_stream.close()
logging.debug("Wrote %s." % output_filename)

pageno += 1
# def pdf_burst ends here

def cleanup():
"""Remove support files"""
try:
Expand Down Expand Up @@ -804,7 +784,7 @@ def process_inline_equations( xmlChapters ):
Datei = open(TEMP_DIR / 'xelatex-run.log', 'w')
Ergebnis = subprocess.check_call(Argumente,cwd=formula_tmp_dir,stdout=Datei)
logging.info("Splitting all Inline Equations")
pdf_burst("EOAinline.pdf", formula_tmp_dir)
libeoaconvert.pdf_burst("EOAinline.pdf", formula_tmp_dir)
logging.info("Converting %s split pages into PNG-Images" % len(dictEOAineqs.keys()))
counter_dictEOAineqs = 1
for intRunningOrder in dictEOAineqs.keys():
Expand Down Expand Up @@ -890,7 +870,7 @@ def process_eoachem( xmlChapters ):
Datei = open(TEMP_DIR / 'xelatex-run.log', 'w')
Ergebnis = subprocess.check_call(Argumente,cwd=formula_tmp_dir,stdout=Datei)
logging.info("Splitting all Inline Chemical formulas")
pdf_burst("EOAchem.pdf", formula_tmp_dir)
libeoaconvert.pdf_burst("EOAchem.pdf", formula_tmp_dir)
logging.info("Converting %s split pages into PNG-Images" % len(dictEOAchems.keys()))
counter_dictEOAchems = 1
for intRunningOrder in dictEOAchems.keys():
Expand Down
21 changes: 21 additions & 0 deletions src/utils/libeoaconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,24 @@ def progress(count, total, status=''):
sys.stdout.write('[%s] %s%s ... %s\r' % (bar, percents, '%', status))
sys.stdout.flush()
# def progress ends here


def pdf_burst(input_file, tmpDir):
"""Split PDF file into single pages"""
from PyPDF2 import PdfFileWriter, PdfFileReader

input1 = PdfFileReader(open(tmpDir / input_file, "rb"))
logging.debug("Input is %s and has %d pages." % (input_file, input1.getNumPages()))

for pageno in range(input1.getNumPages()):
output = PdfFileWriter()
output.addPage(input1.getPage(pageno))

output_filename = tmpDir / ("EOAformulas_%d.pdf" % (pageno + 1))
output_stream = open(output_filename, 'wb')
output.write(output_stream)
output_stream.close()
logging.debug("Wrote %s." % output_filename)

pageno += 1
# def pdf_burst ends here

0 comments on commit 5a2d9c8

Please sign in to comment.