Skip to content

Commit 9e2a6a8

Browse files
NotYuShengclaude
andcommitted
refactor: Remove PDF preview feature from translate page
Removed the PDF preview (iframe) to improve page performance, while keeping the download button functionality. The PDF is still fetched server-side with session cookies to avoid authorization issues, but the base64 encoding and iframe rendering are removed. Changes: - Removed base64 import - Removed PDF preview expander with iframe - Kept download button with server-side fetch for authentication 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 49aa364 commit 9e2a6a8

1 file changed

Lines changed: 2 additions & 15 deletions

File tree

frontend/my_pages/6_translate_UI.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import asyncio
44
import httpx
55
import os
6-
import base64
76
from httpx import Cookies
87

98
PDF_PROCESSOR_URL = os.environ["PDF_PROCESSOR_URL"]
@@ -81,17 +80,13 @@ def display_translation_info(translation_data: dict):
8180

8281

8382
def display_rendered_pdf(doc_id: str, filename: str, runner: asyncio.Runner, client: httpx.AsyncClient):
84-
"""Display rendered PDF with download and preview options."""
83+
"""Display download button for rendered PDF."""
8584
# Server-side URL for fetching PDF (internal service communication)
8685
server_pdf_url = f"{PDF_PROCESSOR_URL}/renderer/{doc_id}/rendered.pdf"
8786

88-
# Client-side URL for browser downloads (through nginx gateway)
89-
client_pdf_url = f"/pdf_processor/renderer/{doc_id}/rendered.pdf"
90-
9187
try:
9288
pdf_response = runner.run(client.get(server_pdf_url))
9389
if pdf_response.status_code == 200:
94-
# Download button at the top
9590
st.download_button(
9691
label="📥 Download Translated PDF",
9792
data=pdf_response.content,
@@ -100,19 +95,11 @@ def display_rendered_pdf(doc_id: str, filename: str, runner: asyncio.Runner, cli
10095
key=f"download_{doc_id}",
10196
use_container_width=True
10297
)
103-
104-
# Preview section
105-
with st.expander("👁️ Preview PDF", expanded=False):
106-
base64_pdf = base64.b64encode(pdf_response.content).decode('utf-8')
107-
pdf_display = f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="100%" height="600px" type="application/pdf"></iframe>'
108-
st.markdown(pdf_display, unsafe_allow_html=True)
10998
else:
11099
st.error(f"Failed to load PDF (HTTP {pdf_response.status_code})")
111-
st.markdown(f"[Try direct download]({client_pdf_url})")
112100
except Exception as e:
113101
logger.error(f"Error fetching rendered PDF: {e}")
114-
st.error("Error loading PDF. Try the download link below:")
115-
st.markdown(f"[Download Translated PDF]({client_pdf_url})")
102+
st.error(f"Error loading PDF: {e}")
116103

117104

118105
def display_renderer_section(doc_id: str, filename: str, renderer_data: dict, runner: asyncio.Runner, client: httpx.AsyncClient):

0 commit comments

Comments
 (0)