Update app.py
Browse files
app.py
CHANGED
@@ -19,8 +19,7 @@ from datetime import datetime
|
|
19 |
import pytz
|
20 |
from pypdf import PdfReader, PdfWriter
|
21 |
from pypdf.annotations import Link
|
22 |
-
from
|
23 |
-
from pypdf.generic import Fit
|
24 |
|
25 |
st.set_page_config(layout="wide", initial_sidebar_state="collapsed")
|
26 |
|
@@ -386,10 +385,15 @@ def create_and_link_pdfs(source_pdf="TestSource.pdf", target_pdf="TestTarget.pdf
|
|
386 |
text_pdf = PdfReader(buffer)
|
387 |
page = writer.pages[0]
|
388 |
page.merge_page(text_pdf.pages[0])
|
389 |
-
#
|
|
|
|
|
|
|
|
|
|
|
390 |
link = Link(
|
391 |
rect=(90, seven_y - 10, 150, seven_y + 10),
|
392 |
-
|
393 |
)
|
394 |
writer.add_annotation(page_number=0, annotation=link)
|
395 |
with open(source, "wb") as f:
|
|
|
19 |
import pytz
|
20 |
from pypdf import PdfReader, PdfWriter
|
21 |
from pypdf.annotations import Link
|
22 |
+
from pypdf.generic import Fit, DictionaryObject, NameObject, TextStringObject
|
|
|
23 |
|
24 |
st.set_page_config(layout="wide", initial_sidebar_state="collapsed")
|
25 |
|
|
|
385 |
text_pdf = PdfReader(buffer)
|
386 |
page = writer.pages[0]
|
387 |
page.merge_page(text_pdf.pages[0])
|
388 |
+
# Create a URI action dictionary
|
389 |
+
uri_action = DictionaryObject({
|
390 |
+
NameObject("/S"): NameObject("/URI"),
|
391 |
+
NameObject("/URI"): TextStringObject(f"file://{os.path.abspath(target)}#page=1")
|
392 |
+
})
|
393 |
+
# Create the link annotation with the URI action
|
394 |
link = Link(
|
395 |
rect=(90, seven_y - 10, 150, seven_y + 10),
|
396 |
+
**{"/A": uri_action} # Add the action dictionary directly
|
397 |
)
|
398 |
writer.add_annotation(page_number=0, annotation=link)
|
399 |
with open(source, "wb") as f:
|