Skip to content
Snippets Groups Projects
Commit 7ac8806a authored by tuhe's avatar tuhe
Browse files

fixed pdf file reader

parent 282d91b8
No related branches found
No related tags found
No related merge requests found
Pipeline #14231 failed
#!python
# The above makes the script executable.
import os
from slider import legacy_importer
from slider.legacy_importer import SVG_EDIT_RELPATH, SVG_TMP_RELPATH, move_template_files, DTU_beamer_base, svg_edit_to_importable
......@@ -24,7 +23,6 @@ def fix_handout(s):
def _get_osvg_labels():
pass
def set_svg_background_images(lecture_tex, verbose=False,
......@@ -50,9 +48,6 @@ def set_svg_background_images(lecture_tex, verbose=False,
force_fix_broken_osvg_files = [] if force_fix_broken_osvg_files is None else force_fix_broken_osvg_files
NO_SVG_TMP_DIR = SVG_TMP_DIR + "/no_svg_tmp"
# if not os.path.isdir(NO_SVG_TMP_DIR):
# os.mkdir(NO_SVG_TMP_DIR)
if os.path.isdir(NO_SVG_TMP_DIR):
for f in glob.glob(MAIN_TEX_DIR + "/*_NO_SVGS.*"):
shutil.move(f, MAIN_TEX_DIR + "/" + os.path.basename(f))
......@@ -84,11 +79,9 @@ def set_svg_background_images(lecture_tex, verbose=False,
ii = all_tex.find(s)
frame_start = all_tex.rfind("\\begin{frame}", 0, ii)
frame_end = all_tex.find("\\end{frame}", ii, len(all_tex))
cs = all_tex[frame_start:frame_end]
d = {"pdf_label": s, "svg_edit_file": MAIN_TEX_DIR + "/" + SVG_EDIT_RELPATH + "/" + s + ".svg", 'slide_tex': cs}
sinfo[s] = d
# print(d)
if not os.path.exists(MAIN_TEX_DIR + "/" + SVG_EDIT_RELPATH):
os.mkdir(MAIN_TEX_DIR + "/" + SVG_EDIT_RELPATH)
......@@ -101,7 +94,7 @@ def set_svg_background_images(lecture_tex, verbose=False,
# find and fix the import
dc2 = "\\input{"
j1 = s.find(dc2)+len(dc2)
j2 = s.find(dc2) + s.find("}", s.find(dc2))
j2 = s.find("}", s.find(dc2))
fhead = MAIN_TEX_DIR + "/" + s[j1:j2]+".tex"
with open(fhead, 'r') as f:
sh = f.read()
......@@ -138,7 +131,7 @@ def set_svg_background_images(lecture_tex, verbose=False,
# Make .png background images.
import PyPDF2 # Import PyPDF2 here. There is a strange issue (possibly bad package version?) which makes it inappropriate as a top-level import (CI/CD Breaks).
with open(lecture_tex_nosvg_pdf, 'rb') as f:
pdfdoc = PyPDF2.PdfFileReader(f)
pdfdoc = PyPDF2.PdfReader(f)
for i in range(pdfdoc.getNumPages()):
content = pdfdoc.getPage(i).extractText()
for osvg_name, d in sinfo.items(): #enumerate(sinfo):
......@@ -184,7 +177,6 @@ def set_svg_background_images(lecture_tex, verbose=False,
ANY_CHANGES = True
if ANY_CHANGES and recompile_on_change:
latexmk(lecture_tex)
if clean_temporary_files:
......@@ -204,20 +196,13 @@ def set_svg_background_images(lecture_tex, verbose=False,
for f in glob.glob(MAIN_TEX_DIR +"/*_NO_SVGS.*"):
shutil.move(f, NO_SVG_TMP_DIR +"/" + os.path.basename(f))
# if os.path.exists(DNE):
# for v in glob.glob(DNE + "/*"):
# if not v.endswith("png"):
# os.remove(v)
a = 234
def slide_no_by_text(pdf_file, text):
assert False
# Make .png background images.
if os.path.exists(pdf_file):
with open(pdf_file, 'rb') as f:
print(pdf_file)
pdfdoc = PyPDF2.PdfFileReader(f)
pdfdoc = PyPDF2.PdfReader(f)
for i in range(pdfdoc.getNumPages()):
content = pdfdoc.getPage(i).extractText()
# for j, d in enumerate(sinfo):
......@@ -302,4 +287,3 @@ def recursive_tex_collect(doc):
lines = gathersub(doc)
return "\n".join(lines)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment