- Я хочу, чтобы PDF-файл открывался на определенной (параметризуемой) странице
- Я хочу, чтобы PDF-файл открывался с уже выделенной определенной (параметризуемой) цитатой/текстом
- Я хочу, чтобы PDF-файл можно было прокручивать в средстве просмотра/iframe
Я урезал свое приложениеstreamlit до следующего минимального файла app.py
code>, который включает всего три кнопки/ссылки, которые безуспешно пытаются отобразить средство просмотра PDF-файлов в соответствии с моими требованиями:
Код: Выделить всё
import streamlit as st
import streamlit.components.v1 as components
import urllib
def main():
st.title("Hello from streamlit-n-pdfjs!")
# Locations of my (public) r2 bucket and the document in it I want to view
BUCKET_URL = "https://pub-ec8aa50844b34a22a2e6132f8251f8b5.r2.dev"
DOCUMENT_NAME = "FINAL_REPORT.pdf"
# "Media stored in the folder ./static/ relative to the running app file is served at path app/static/[filename]"
# ^ https://docs.streamlit.io/develop/concepts/configuration/serving-static-files
local_pdfjs_path = "./app/static/pdfjs-4-9-155-dist/web/viewer.html"
# Attempt to link to the doc using the pdf.js viewer
PAGENUM = 100
HIGHLIGHT_QUOTE = 'exited the stage'
ENCODED_QUOTE = urllib.parse.quote(HIGHLIGHT_QUOTE)
FULL_DOC_URL = f"{BUCKET_URL}/{DOCUMENT_NAME}#page={PAGENUM}&search={ENCODED_QUOTE}"
pdfjs_viewer = f"{local_pdfjs_path}?file={FULL_DOC_URL}"
# Clicking the link below opens the correct pdf to the correct page, but does not search/highlight the quote text,
# ...and of course does not open in an iframe
st.markdown(f"[link to the doc I can't get to open in iframe w/ buttons below]({FULL_DOC_URL})") # opens doc in a new tab but doesn't search/highlight quote
# clicking button below says "404: Not Found"
if st.button("Show PDF in iframe with highlights, via pdfjs viewer"):
components.iframe(pdfjs_viewer, height=800, scrolling=True)
# Clicking the button below opens an iframe border, but
# just says "this page has been blocked by chrome" inside
if st.button("Show PDF in iframe with highlights, via regular url w/ encoded params"):
components.iframe(FULL_DOC_URL, height=800, scrolling=True)
if __name__ == "__main__":
main()
Код: Выделить всё
|streamlit_n_pdfjs
|--app.py
|--vendor
|----pdfjs-4-9-155-dist
|------web
|--------viewer.html
Код: Выделить всё
[server]
enableStaticServing = true
Код: Выделить всё
PYTHONPATH=. streamlit run app.py

- Ссылка, открывающая PDF-файл файл в новой вкладке к заданному страница, но не использует iframe (намеренно, это в основном проверка доступности pdf/doc по URL-адресу), и не с успешным выделением желаемого текста/цитаты.
- Кнопка, которая пытается запустить iframe с документом с помощью pdf.js, но просто вызывает сообщение 404.
- Кнопка, которая пытается запустить iframe с документом только через рендеринг PDF-файла браузером по умолчанию из URL-адреса. , но какой выдает сообщение «эта страница заблокирована Chrome»
Подробнее здесь: https://stackoverflow.com/questions/792 ... eamlit-app