OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

¿How can I send a pdf from Python to PHP?

  • Thread starter Thread starter CRISTIAN ULISES BARENCA SOTELO
  • Start date Start date
C

CRISTIAN ULISES BARENCA SOTELO

Guest
I have the next code, I try create the pdf in Python and then send the pdf to PHP. After, when I open the PDF I don´t see the content of the PDF it´s corrupted. Can anyone help me on that?

Python code

Code:
from reportlab.pdfgen import canvas
from io import BytesIO
from django.http import HttpResponse

def generar_pdf():
 
    buffer = BytesIO()
    c = canvas.Canvas(buffer)

    
    c.drawString(50, 50, "¡Hola, mundo!")

    
    c.save()

    
    pdf_bytes = buffer.getvalue()

    return HttpResponse(bytes(pdf_bytes), content_type='application/pdf')        
    

pdf_response = generar_pdf()


print(pdf_response)

PHP Code

Code:
<?php

$pdf_bytes = shell_exec("python prueba.py");


header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="archivo.pdf"');


echo $pdf_bytes;
?>
<p>I have the next code, I try create the pdf in Python and then send the pdf to PHP. After, when I open the PDF I don´t see the content of the PDF it´s corrupted. Can anyone help me on that?</p>
<p>Python code</p>
<pre><code>from reportlab.pdfgen import canvas
from io import BytesIO
from django.http import HttpResponse

def generar_pdf():

buffer = BytesIO()
c = canvas.Canvas(buffer)


c.drawString(50, 50, "¡Hola, mundo!")


c.save()


pdf_bytes = buffer.getvalue()

return HttpResponse(bytes(pdf_bytes), content_type='application/pdf')


pdf_response = generar_pdf()


print(pdf_response)
</code></pre>
<p>PHP Code</p>
<pre><code><?php

$pdf_bytes = shell_exec("python prueba.py");


header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="archivo.pdf"');


echo $pdf_bytes;
?>
</code></pre>
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top