Ethscriptions commited on
Commit
4845952
·
verified ·
1 Parent(s): 156968c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -18
app.py CHANGED
@@ -88,17 +88,17 @@ def create_print_layout(data, date_str):
88
  if data is None or data.empty:
89
  return None
90
 
91
- # 创建PNG图像
92
  png_fig = plt.figure(figsize=(8.27, 11.69), dpi=300)
93
  png_ax = png_fig.add_subplot(111)
94
  png_ax.set_axis_off()
 
 
95
 
96
- # 创建PDF图像 - 使用A4纸张大小 (210mm x 297mm)
97
- # 增加图形大小以最大化利用A4纸张空间
98
  pdf_fig = plt.figure(figsize=(8.27, 11.69), dpi=300)
99
  pdf_ax = pdf_fig.add_subplot(111)
100
  pdf_ax.set_axis_off()
101
-
102
  # 为PDF设置更小的边距
103
  pdf_fig.subplots_adjust(left=0.02, right=0.98, top=0.98, bottom=0.02)
104
 
@@ -106,8 +106,8 @@ def create_print_layout(data, date_str):
106
  def process_figure(fig, ax, is_pdf=False):
107
  # Pre-load fonts
108
  date_font = get_font(12)
109
- # PDF版本使用稍大的字体
110
- font_size_multiplier = 1.1 if is_pdf else 1.0
111
  movie_font_size = 14 * font_size_multiplier
112
  hall_font_size = movie_font_size * 0.8
113
  hall_font = get_font(hall_font_size)
@@ -119,7 +119,7 @@ def create_print_layout(data, date_str):
119
  halls = sorted(data['Hall'].unique(), key=lambda h: int(h.replace('号','')) if h else 0)
120
 
121
  total_lines = sum(len(data[data['Hall'] == hall]) for hall in halls) + (len(halls) - 1)
122
- available_height = 0.98 - 0.05
123
  line_spacing = available_height / total_lines if total_lines > 0 else 0.04
124
  y_position = 0.98
125
 
@@ -167,9 +167,9 @@ def create_print_layout(data, date_str):
167
  # 处理PDF图形
168
  process_figure(pdf_fig, pdf_ax, is_pdf=True)
169
 
170
- # 保存PNG图像
171
  png_buffer = io.BytesIO()
172
- png_fig.savefig(png_buffer, format='png', bbox_inches='tight', pad_inches=0.1)
173
  png_buffer.seek(0)
174
  image_base64 = base64.b64encode(png_buffer.getvalue()).decode()
175
  plt.close(png_fig)
@@ -194,15 +194,10 @@ def display_pdf(base64_pdf):
194
  """
195
  return pdf_display
196
 
197
- def get_download_link(base64_data, file_type, filename):
198
- # 创建下载链接
199
- href = f'<a href="{base64_data}" download="{filename}">下载{file_type}文件</a>'
200
- return href
201
-
202
  st.set_page_config(page_title="LED 屏幕时间表打印", layout="wide")
203
  st.title("LED 屏幕时间表打印")
204
 
205
- uploaded_file = st.file_uploader("选择打开【放映时间核对表.xls】文件", type=["xls", "xlsx"])
206
 
207
  if uploaded_file:
208
  with st.spinner("正在处理中,请稍候..."):
@@ -215,13 +210,10 @@ if uploaded_file:
215
 
216
  with tab1:
217
  st.image(output['png'], use_container_width=True)
218
- st.markdown(get_download_link(output['png'], "PNG", f"LED屏幕时间表_{date_str}.png"), unsafe_allow_html=True)
219
 
220
  with tab2:
221
  st.markdown(display_pdf(output['pdf']), unsafe_allow_html=True)
222
- st.markdown(get_download_link(output['pdf'], "PDF", f"LED屏幕时间表_{date_str}.pdf"), unsafe_allow_html=True)
223
  else:
224
  st.error("无法处理文件,请检查文件格式或内容是否正确。")
225
 
226
-
227
 
 
88
  if data is None or data.empty:
89
  return None
90
 
91
+ # 创建PNG图像 - 使用A4纸张大小并最大化内容
92
  png_fig = plt.figure(figsize=(8.27, 11.69), dpi=300)
93
  png_ax = png_fig.add_subplot(111)
94
  png_ax.set_axis_off()
95
+ # 为PNG设置更小的边距以最大化内容
96
+ png_fig.subplots_adjust(left=0.02, right=0.98, top=0.98, bottom=0.02)
97
 
98
+ # 创建PDF图像 - 使用A4纸张大小
 
99
  pdf_fig = plt.figure(figsize=(8.27, 11.69), dpi=300)
100
  pdf_ax = pdf_fig.add_subplot(111)
101
  pdf_ax.set_axis_off()
 
102
  # 为PDF设置更小的边距
103
  pdf_fig.subplots_adjust(left=0.02, right=0.98, top=0.98, bottom=0.02)
104
 
 
106
  def process_figure(fig, ax, is_pdf=False):
107
  # Pre-load fonts
108
  date_font = get_font(12)
109
+ # 使用更大的字体以最大化利用纸张空间
110
+ font_size_multiplier = 1.2
111
  movie_font_size = 14 * font_size_multiplier
112
  hall_font_size = movie_font_size * 0.8
113
  hall_font = get_font(hall_font_size)
 
119
  halls = sorted(data['Hall'].unique(), key=lambda h: int(h.replace('号','')) if h else 0)
120
 
121
  total_lines = sum(len(data[data['Hall'] == hall]) for hall in halls) + (len(halls) - 1)
122
+ available_height = 0.98 - 0.02 # 增加可用高度
123
  line_spacing = available_height / total_lines if total_lines > 0 else 0.04
124
  y_position = 0.98
125
 
 
167
  # 处理PDF图形
168
  process_figure(pdf_fig, pdf_ax, is_pdf=True)
169
 
170
+ # 保存PNG图像 - 使用最小边距以最大化内容
171
  png_buffer = io.BytesIO()
172
+ png_fig.savefig(png_buffer, format='png', bbox_inches='tight', pad_inches=0.05)
173
  png_buffer.seek(0)
174
  image_base64 = base64.b64encode(png_buffer.getvalue()).decode()
175
  plt.close(png_fig)
 
194
  """
195
  return pdf_display
196
 
 
 
 
 
 
197
  st.set_page_config(page_title="LED 屏幕时间表打印", layout="wide")
198
  st.title("LED 屏幕时间表打印")
199
 
200
+ uploaded_file = st.file_uploader("选择打开【放映时间核对表.xls】文件", accept_multiple_files=False, type=["xls"])
201
 
202
  if uploaded_file:
203
  with st.spinner("正在处理中,请稍候..."):
 
210
 
211
  with tab1:
212
  st.image(output['png'], use_container_width=True)
 
213
 
214
  with tab2:
215
  st.markdown(display_pdf(output['pdf']), unsafe_allow_html=True)
 
216
  else:
217
  st.error("无法处理文件,请检查文件格式或内容是否正确。")
218
 
 
219