I'm trying to print (the action of sending to printer) a PNG image I get as a response from my ajax call. The response comes as an "inline" image/png type response from my View. The reply from ajax is successful, meaning the image is properly sent. I can even open it in another window. However, I want to send that image automatically to print. The window itself has other info I don't want to get mixed with the response, thus I need to print only the image I'm getting. I can do window.print() but that just prints the current page, not the response (obviously). Does anyone know how to process the response in order to print it?
function traer_1234(){
$.ajax({
dataType: "html",
contentType: "application/json",
type: 'GET',
data: {"nanda": 1},
url: "{% url 'View_test' %}",
success: function (response) {
alert("1234")
window.print()
},
error: function (response) {
alert("Error")
}
})
}
The View side looks like this
def View_test(request):
ean=barcode.codex.Code39("int-12345",writer=ImageWriter(), add_checksum= False)
image = ean.render()
response = HttpResponse( headers={
'Content-Type': 'image/png',
'Content-Disposition': 'inline; filename="borrar.png"',
})
image.save(response, "PNG")
return response
Thanks in advance to anyone who can supply any info.