Admin print function - Preview/Print PDF

Admin print function - Preview/Print PDF

skraloupak
Shopify Partner
24 3 3

Hello all,

 

We are trying to invoke printing from the new admin print extension. We have an endpoint that is returning a PDF content and we would like to print and preview it directly in the admin dialog (same as HTML endpoint). Is it possible, or we have to preview/print only HTML endpoints?

 

Thank you

Jan

Replies 3 (3)

Liam
Shopify Staff
2873 312 820

Hi Jan,

 

I've checked with the admin UI extensions team and PDF endpoints should be supported. 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

skraloupak
Shopify Partner
24 3 3

Thank you for your reply. That's great.

I've tried multiple ways, but the document isn't previewed correctly.

 

See anything that might be wrong? 

Response data: base64

Headers: 

'Content-Type', 'application/pdf'
'Content-disposition', 'inline; filename="xxxx.pdf"'

screenshot 136.pngscreenshot 137.png

 

Thank you for letting me know 🙂

Best

Jan

skraloupak
Shopify Partner
24 3 3

Code detail:

ctx.res.setHeader('Content-Type', 'application/pdf');
ctx.res.setHeader('Content-disposition', 'inline; filename="' + hash + '.pdf"');
ctx.body = Buffer.from(printLabels.result, 'base64');