- Code: Select all
@login_required(login_url='login')
def export_layout_image(request, output=None):
part_name = request.session['part_name']
file_name = part_name + '_Layout.pdf'
fault = error_check(request, 'Layout', 'Download')
if fault is None:
graph = layout_txt(request, 'str')
body = {
"graph": graph,
"layout": "dot",
"format": "svg"
}
r = requests.post('https://quickchart.io/graphviz', json=body)
# r.text is sufficient for SVG. Use `r.raw` for png images
svg = r.text
# writes returned object to svg file
with tempfile.NamedTemporaryFile(delete=False, suffix='.svg') as f:
with open(f.name, 'w') as file:
file.write(svg)
# loads above svg file to pdf
with tempfile.NamedTemporaryFile(delete=False, suffix='.pdf') as pdf:
# close temp file so spire can overwrite it
pdf.close()
# Create a PdfDocument object
doc = PdfDocument()
# Load an SVG file
doc.LoadFromSvg(file.name)
# Save the SVG file to PDF format
doc.SaveToFile(pdf.name, FileFormat.PDF)
# Close the PdfDocument object
doc.Close()
if output is None:
return FileResponse(open(pdf.name, 'rb'), as_attachment=True, filename=file_name)
if output == 'zip':
return pdf, file_name
else:
return fault
im new to spire.pdf and programming
function currently works but i want to be able to add boarder and table at bottom right with other details and make page size A3
svg is dymaically created so size is always changing so needs to resize to fit on page i just cant get it to work