Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -119,13 +119,15 @@ def create_print_layout(data, title, date_str):
|
|
119 |
png_fig = plt.figure(figsize=(5.83, 8.27), dpi=300) # A5 竖向
|
120 |
png_ax_container = png_fig.add_subplot(111) # 创建一个容器轴,用于隐藏外部边框
|
121 |
png_ax_container.set_axis_off()
|
122 |
-
|
|
|
123 |
|
124 |
# --- 创建 PDF 图形 ---
|
125 |
pdf_fig = plt.figure(figsize=(5.83, 8.27), dpi=300) # A5 竖向
|
126 |
pdf_ax_container = pdf_fig.add_subplot(111)
|
127 |
pdf_ax_container.set_axis_off()
|
128 |
-
|
|
|
129 |
|
130 |
# --- 内部绘图函数 ---
|
131 |
def process_figure(fig, is_pdf=False):
|
@@ -139,7 +141,8 @@ def create_print_layout(data, title, date_str):
|
|
139 |
num_rows = math.ceil(total_items / num_cols)
|
140 |
|
141 |
# 创建网格 (在 figure 内部创建)
|
142 |
-
|
|
|
143 |
|
144 |
# 调整基础字体大小,避免过大或过小
|
145 |
# A5 宽度大约 1749 像素 @ 300dpi, 高度 2481
|
@@ -217,7 +220,8 @@ def create_print_layout(data, title, date_str):
|
|
217 |
|
218 |
# --- 保存 PNG ---
|
219 |
png_buffer = io.BytesIO()
|
220 |
-
|
|
|
221 |
png_buffer.seek(0)
|
222 |
png_base64 = base64.b64encode(png_buffer.getvalue()).decode()
|
223 |
plt.close(png_fig)
|
@@ -225,7 +229,8 @@ def create_print_layout(data, title, date_str):
|
|
225 |
# --- 保存 PDF ---
|
226 |
pdf_buffer = io.BytesIO()
|
227 |
with PdfPages(pdf_buffer) as pdf:
|
228 |
-
|
|
|
229 |
pdf_buffer.seek(0)
|
230 |
pdf_base64 = base64.b64encode(pdf_buffer.getvalue()).decode()
|
231 |
plt.close(pdf_fig)
|
@@ -245,7 +250,7 @@ def display_pdf(base64_pdf):
|
|
245 |
st.set_page_config(page_title="散厅时间快捷打印", layout="wide")
|
246 |
st.title("散厅时间快捷打印")
|
247 |
|
248 |
-
uploaded_file = st.file_uploader("上传【放映场次核对表.xls】文件", type=["xls"])
|
249 |
|
250 |
if uploaded_file:
|
251 |
part1, part2, date_str = process_schedule(uploaded_file)
|
|
|
119 |
png_fig = plt.figure(figsize=(5.83, 8.27), dpi=300) # A5 竖向
|
120 |
png_ax_container = png_fig.add_subplot(111) # 创建一个容器轴,用于隐藏外部边框
|
121 |
png_ax_container.set_axis_off()
|
122 |
+
# 减小边距,例如从 0.05 减小到 0.02
|
123 |
+
png_fig.subplots_adjust(left=0.02, right=0.98, top=0.98, bottom=0.02)
|
124 |
|
125 |
# --- 创建 PDF 图形 ---
|
126 |
pdf_fig = plt.figure(figsize=(5.83, 8.27), dpi=300) # A5 竖向
|
127 |
pdf_ax_container = pdf_fig.add_subplot(111)
|
128 |
pdf_ax_container.set_axis_off()
|
129 |
+
# 减小边距,例如从 0.05 减小到 0.02
|
130 |
+
pdf_fig.subplots_adjust(left=0.02, right=0.98, top=0.98, bottom=0.02)
|
131 |
|
132 |
# --- 内部绘图函数 ---
|
133 |
def process_figure(fig, is_pdf=False):
|
|
|
141 |
num_rows = math.ceil(total_items / num_cols)
|
142 |
|
143 |
# 创建网格 (在 figure 内部创建)
|
144 |
+
# 减小子图间距 hspace/wspace,减小日期行高度比例 height_ratios
|
145 |
+
gs = gridspec.GridSpec(num_rows + 1, num_cols, hspace=0.05, wspace=0.05, height_ratios=[0.1] + [1] * num_rows, figure=fig) # 将日期行放在顶部
|
146 |
|
147 |
# 调整基础字体大小,避免过大或过小
|
148 |
# A5 宽度大约 1749 像素 @ 300dpi, 高度 2481
|
|
|
220 |
|
221 |
# --- 保存 PNG ---
|
222 |
png_buffer = io.BytesIO()
|
223 |
+
# 可以尝试减小 pad_inches,甚至设为 0
|
224 |
+
png_fig.savefig(png_buffer, format='png', bbox_inches='tight', pad_inches=0.02)
|
225 |
png_buffer.seek(0)
|
226 |
png_base64 = base64.b64encode(png_buffer.getvalue()).decode()
|
227 |
plt.close(png_fig)
|
|
|
229 |
# --- 保存 PDF ---
|
230 |
pdf_buffer = io.BytesIO()
|
231 |
with PdfPages(pdf_buffer) as pdf:
|
232 |
+
# 可以尝试减小 pad_inches,甚至设为 0
|
233 |
+
pdf.savefig(pdf_fig, bbox_inches='tight', pad_inches=0.02)
|
234 |
pdf_buffer.seek(0)
|
235 |
pdf_base64 = base64.b64encode(pdf_buffer.getvalue()).decode()
|
236 |
plt.close(pdf_fig)
|
|
|
250 |
st.set_page_config(page_title="散厅时间快捷打印", layout="wide")
|
251 |
st.title("散厅时间快捷打印")
|
252 |
|
253 |
+
uploaded_file = st.file_uploader("上传【放映场次核对表.xls】文件", type=["xls", "xlsx"])
|
254 |
|
255 |
if uploaded_file:
|
256 |
part1, part2, date_str = process_schedule(uploaded_file)
|