AnsweredAssumed Answered

How to download PDF from PdfManager/generate endpoint

Question asked by Brett Zufelt on Feb 25, 2019

Version 8.3 of Sugar introduced the GET PdfManager/generate endpoint that is supposed to return and initiate a download of a PDF. I can't figure out how to get the download of the PDF to happen. Any help?

 

Here is my code to call the endpoint:

var url = app.api.buildURL('PdfManager', 'generate', null, {
    'module': this.module,
    'record': this.model.id,
    'pdf_template_id': 'd277ade8-43e9-4a8d-634c-5629a76f9ff1',
    'sugarpdf': 'pdfmanager'
});

app.api.call('read', url, null, {success: function(pdf){console.log(pdf);}}, {'dataType': 'text'});

The API call appears to be working as it is calling my success callback and returning a response that looks like this:

%PDF-1.7
3 0 obj
<</Type /Page
/Parent 1 0 R
/MediaBox [0 0 612.00 792.00]
/Resources 2 0 R
/Contents 4 0 R>>
endobj
4 0 obj
<</Length 21457>>
stream
8.c ��R�`��d�Q�W��W��x=�  ��1b<OV� Ũ��Ɩ �Y{�6�rI~�^�j[�+��Wa�GHmq�5�<� 8�ݴ�
� �����bu? 9YF��  w�% � � Ǟ�E� S'Mm�up�j [��� IPݹ,�Yl � ��$�k'y���o�XQ<1Ţ �jb �s���J$[���- ...

 

How do I then take the response and download it as a PDF file to the user's computer?

Outcomes