aspose-words / Aspose.Words-for-Python-via-.NET

Aspose.Words for Python via .NET examples and showcases
MIT License
104 stars 22 forks source link

download the file #34

Closed i-salameh95 closed 1 year ago

i-salameh95 commented 1 year ago

I have tried this package with Django 4.2 its awesome !, however there is some issues:

def download_approval(request, project_id):
    project = get_object_or_404(Project, pk=project_id)
    doc = DocxTemplate('letter.docx')
    context = {
        'ref_num': project.ref_num,
        'author_name': project.author.get_full_name,
        'approval_date': project.approved_date.date(),
        'project_title': project.title_en
    }
    doc.render(context)
    file_path = project.ref_num + '_' + 'approval_letter.docx'
    full_path = os.path.join(MEDIA_URL, 'approval/') + file_path
    doc.save(full_path)
    doc_final = aw.Document(full_path)
    response = HttpResponse(doc_final.save('research_permission_request.pdf'), content_type='application/pdf')
    response['Content-Disposition'] = 'inline; filename=' + os.path.basename(full_path)
    return response

I have tried convert a docx to pdf by aspose.words, BUT i CANNOT render the file in the browser, so how could I make the file generated by Aspose downloadable ? also: is it necessary to add this watermark to the generated pdf file :( also there is a punch of red statements which says its an evaluation copy...

AlexNosk commented 1 year ago

@i-salameh95 You can save the document as PDF to stream and then send the stream into the client's browser. Please see our documentation to learn how to save the document to stream: https://docs.aspose.com/words/python-net/save-a-document/#save-a-document-to-a-stream

Regarding the red message in the output document. Aspose.Words is a commercial product and have two limitation when it is used without license (in evaluation mode):

Please see our documentation for more information: https://docs.aspose.com/words/python-net/licensing/

If you would like to test Aspose.Words without evaluation version limitations, you can request a free 30-days temporary license: https://purchase.aspose.com/temporary-license/

PS: The main place or getting support is Aspose.Words support forum. So please post your questions in the forum to get timely response: https://forum.aspose.com/c/words/8