Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteafbd5d

Browse files
committed
fixed pdf download issue
1 parent0455cfd commiteafbd5d

File tree

8 files changed

+24
-9
lines changed

8 files changed

+24
-9
lines changed

‎Angular_frontend/src/app/pages/dfsm-result/dfsm-result.component.html‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ <h2>DFA Simulation Result</h2>
55
{{ result.accepted ? 'Accepted ✅' : 'Rejected ❌' }}
66
</strong></p>
77

8-
<a[href]="pdfUrl"download="dfa_output.pdf"target="_blank">
8+
<a[href]="pdfUrl"[attr.download]="getPdfFileName()"target="_blank">
99
📄 Download DFA PDF
10-
</a>
10+
</a>
11+
12+
<!-- <a [href]="pdfUrl" target="_blank" rel="noopener">
13+
📄 View DFA PDF
14+
</a> -->
1115

1216
<button(click)="router.navigate(['/'])">Simulate Again</button>
1317
</div>

‎Angular_frontend/src/app/pages/dfsm-result/dfsm-result.component.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import { Router } from '@angular/router';
1010
styleUrl:'./dfsm-result.component.css'
1111
})
1212
exportclassDfsmResultComponentimplementsOnInit{
13+
getPdfFileName():string{
14+
if(!this.pdfUrl)return'dfa_output.pdf';
15+
returnthis.pdfUrl.split('/').pop()||'dfa_output.pdf';
16+
}
1317
result:any;
1418
pdfUrl:string='';
1519

-21 Bytes
Binary file not shown.

‎python_backend/dfa_output.pdf.pdf‎

-12.4 KB
Binary file not shown.

‎python_backend/main.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def simulate_dfa(data: DFARequest):
3838
#allow_partial=True
3939
)
4040
result=dfa.accepts_input(data.input_string)
41-
pdf_path=generate_pdf(dfa,"dfa_output.pdf")
41+
pdf_path=generate_pdf(dfa)
4242

4343
return {"accepted":result,"pdf_path":pdf_path}
4444
exceptExceptionase:
-12.4 KB
Binary file not shown.
211 Bytes
Binary file not shown.

‎python_backend/utils/visualize.py‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
importos
2+
fromdatetimeimportdatetime
23
fromgraphvizimportDigraph
34

4-
defgenerate_pdf(dfa,filename="dfa_output.pdf"):
5+
defgenerate_pdf(dfa):
56
dot=Digraph(format='pdf')
67
dot.attr(rankdir='LR')
78

@@ -16,14 +17,20 @@ def generate_pdf(dfa, filename="dfa_output.pdf"):
1617
forsymbol,to_stateintransitions.items():
1718
dot.edge(from_state,to_state,label=symbol)
1819

19-
# ✅ Save into backend/pdf/
20+
# ✅ Generate unique filename
21+
timestamp=datetime.now().strftime("%Y%m%d%H%M%S")
22+
filename=f"dfa_{timestamp}"
23+
24+
# ✅ Ensure output directory exists
2025
output_dir=os.path.join(os.path.dirname(__file__),'..','pdf')
2126
os.makedirs(output_dir,exist_ok=True)
2227

2328
pdf_path=os.path.join(output_dir,filename)
2429

25-
# ✅ Save PDF and return path
26-
final_path=dot.render(pdf_path,cleanup=True)
27-
print("✅ PDF saved at:",final_path)
30+
dot.render(pdf_path,cleanup=True)
31+
32+
final_pdf_name=f"{filename}.pdf"
33+
print("✅ PDF saved as:",final_pdf_name)
2834

29-
returnf"/pdf/{filename}"# This is the public path for Angular
35+
# Return the correct public-facing path
36+
returnf"/pdf/{final_pdf_name}"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp