1

Bom dia galera,

estou com um codigo ja desenvolvido, porem, ja tentei de todas as formas fazer quebra de pagina e trazer todas as paginas para esse documento, alguem consegue me ajudar com esse caso?

estou utilizando python 2.7

ja tentei utilizar uma solução informada em outras perguntas, porem mesmo assim sem solução.

<p style="page-break-before: always"></p>

coloquei a div da impressão do pdf dentro do codigo, para que possam testar.

def render_pdf(request,pk):
if request.user.is_authenticated():
    if request.user.is_staff or request.user.is_impersonate:
        email = EmailsEnviados.objects.get(pk=pk)
        content = HTML(string='''<div>
    <table style= "border-collapse: collapse; margin:0; padding:0; " width="100%" cellpadding="0" cellspacing="0" align="center">
        <tr>
            <td>
                <table style= "background-color:#f7f7f7; border-collapse: collapse; " width="100%">
                    <tr>
                        <td>
                            <table style= "border-collapse: collapse; " width="900" align="center" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td><img src="http://customer.edgeglobalsupply.com.br/static/css/layout/img/logo.png" /></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
                <table style= "border-collapse: collapse; " width="100%">
                    <tr>
                        <td style="height: 4px; background-color: white;">
                        </td>
                    </tr>
                    
                    <tr>
                        <td align="center" style="padding-top: 30px;">
                            <span style= "font-size: 1.2em; color: #0d4d9b; ">ACOMPANHE OS SEUS PEDIDOS PELA NOSSA EXTRANET</span><br/>
                            Basta logar utilizando este e-mail e o seu CNPJ como usu&aacute;rio e senha <br/><br/>
                            <a href="http://customer.edgeglobalsupply.com.br" title="Acessar Extranet">
                                <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/pedido/css/img/customer-button.png" />
                            </a>
                        </td>
                    </tr>
                    
                    <tr>
                        <td style="padding:10px;">
                        
<table style= "border-collapse: collapse; font-family: &quot;Segoe UI&quot;, Frutiger, &quot;Frutiger Linotype&quot;, &quot;Dejavu Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 13px; " width="100%" cellpadding="0" cellspacing="0">
    <tr>
        <td width="52">
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/monitor.png" />
        </td>
        <td style= "font-size: 2em;padding-left: 8px; ">
            Pedido Aprovado
        </td>
        
        <td>
            
            <table style= "border-collapse: collapse; font-family: &quot;Segoe UI&quot;, Frutiger, &quot;Frutiger Linotype&quot;, &quot;Dejavu Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 13px; " cellpadding="0" cellspacing="0" align="right">
                <tr>
                    <td>
                        <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/calendar-pequeno.png" />
                    </td>
                    <td style= "padding-left: 8px; ">
                        Sexta-feira, 24 de Mar o de 2017
                    </td>
                </tr>
            </table>
            
        </td>
    </tr>
</table>

<!-- NUMEROS -->
<table style= "border-collapse: collapse;margin-top: 20px; font-family: &quot;Segoe UI&quot;, Frutiger, &quot;Frutiger Linotype&quot;, &quot;Dejavu Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 13px; " cellpadding="0" cellspacing="0">
    <tr>
        
        <td>
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/pc.png" />
        </td>
        <td style= "color: #0cf;padding-left: 8px; ">
            Pedido Cliente
        </td>

        <td style="padding: 0 10px; ">
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/seta-fluxo.png" />
        </td>
        
        
        <td>
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/no.png" />
        </td>
        <td style= "color: #5a0d9b;padding-left: 8px; ">
            N mero do Or amento
        </td>
        
        <td style="padding: 0 10px; ">
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/seta-fluxo.png" />
        </td>
        
        
        <td>
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/nv.png" />
        </td>
        <td style= "color: #0084ff;padding-left: 8px; ">
            N mero de Venda
        </td>
        
    </tr>
    <tr>
        
        <td colspan="2" style= "font-size: 2em;padding-left: 30px; ">
            4500643564
        </td>
        <td></td>
        
        
        <td colspan="2" style= "font-size: 2em;padding-left: 30px; ">
            0426782
        </td>
        <td></td>
        
        
        <td colspan="2" style= "font-size: 2em;padding-left: 30px; ">
            0173592
        </td>
        
    </tr>
</table>
<!-- END NUMEROS -->


<!-- FLUXO -->
<table style= "border-collapse: collapse; font-family: &quot;Segoe UI&quot;, Frutiger, &quot;Frutiger Linotype&quot;, &quot;Dejavu Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 13px; margin-top: 40px; " cellpadding="0" cellspacing="0">
    
    <tr>
        <td style= "text-align: center;color: #12c200; padding-bottom: 5px; " width="52">Pedido Realizado</td>
        <td></td>
        
        <td style= "text-align: center; color: #c0c0c1; padding-bottom: 5px; " width="52">Em Separa&ccedil;&atilde;o</td>
        <td></td>

        <td style= "text-align: center; color: #c0c0c1; padding-bottom: 5px; " width="52">Em <span style="font-size: 11px;">Faturamento</span></td>
        <td></td>

        <td style= "text-align: center; color: #c0c0c1; padding-bottom: 5px; " width="52">Em Tr&acirc;nsito</td>
        <td></td>
        
        <td style= "text-align: center; color: #c0c0c1; padding-bottom: 5px; " width="52">Pedido Entregue</td>
    </tr>
    

    <tr>
        <td>
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/pedido/css/img/realizado.png" />
        </td>
        <td>
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/pedido/css/img/sep-fluxo-email-off.png" />
        </td>
        <td>
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/pedido/css/img/separando-off.png" />
        </td>
        <td>
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/pedido/css/img/sep-fluxo-email-off.png" />
        </td>
        <td>
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/pedido/css/img/faturando-off.png" />
        </td>

        <td>
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/pedido/css/img/sep-fluxo-email-off.png" />
        </td>
        
        <td>
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/pedido/css/img/transito-off.png" />
        </td>
        <td>
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/pedido/css/img/sep-fluxo-email-off.png" />
        </td>
        <td>
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/pedido/css/img/entregue-off.png" />
        </td>
        
    </tr>
    
    
    <tr>
        <td style= "text-align: center;color: #12c200; padding-top: 5px; " width="52">24/03/17 14:21</td>
        <td></td>
        
        <td style= "text-align: center;color: #12c200; padding-top: 5px; " width="52"></td>
        <td></td>

        <td style= "text-align: center;color: #12c200; padding-top: 5px; " width="52"></td>
        <td></td>

        <td style= "text-align: center;color: #12c200; padding-top: 5px; " width="52"></td>
        <td></td>
        
        <td style= "text-align: center;color: #12c200; padding-top: 5px; " width="52"></td>
    </tr>
    
</table>
<!-- END FLUXO -->



<!-- FATURAMENTO -->
<h1 style= "font-family: &quot;Segoe UI&quot;, Frutiger, &quot;Frutiger Linotype&quot;, &quot;Dejavu Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 13px;font-size: 26px;margin: 0 0 10px 0;padding: 0;font-weight: normal; margin-top: 40px; ">Dados de Faturamento</h1>


<table style= "border-collapse: collapse; font-family: &quot;Segoe UI&quot;, Frutiger, &quot;Frutiger Linotype&quot;, &quot;Dejavu Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 13px; " cellpadding="0" cellspacing="0">
    <tr>
        <td width="27">
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/estrela.png" />
        </td>
        <td style= "font-weight: bold;padding-left: 8px; ">
            Raz o Social
        </td>
    </tr>
    <tr>
        <td colspan="2" style="padding-bottom: 20px;">
            <span style= "font-size: 1.4em; ">
                Empresa cadastrada
            </span><br/>
            <span style= "font-size: 1.2em; ">
                CNPJ: 11111111111111&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IE: 111111111111
            </span>
        </td>
    </tr>
    
    <tr>
        <td width="27">
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/endereco.png" />
        </td>
        <td style= "font-weight: bold;padding-left: 8px; ">
            Endere o
        </td>
    </tr>
    <tr>
        <td colspan="2" style="padding-bottom: 20px;">
            endere o da empresa cadastrada
        </td>
    </tr>
    
    <tr>
        <td width="27">
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/cfop.png" />
        </td>
        <td style= "font-weight: bold;padding-left: 8px; ">
            CFOP
        </td>
    </tr>
    <tr>
        <td colspan="2">
            
                <span style= "font-size: 1.4em; ">
                    codigo de venda
                </span><br/>
                <span style= "font-size: 1.2em; ">
                    Venda de mercadoria
                </span>
            
        </td>
    </tr>
    
</table>
<!-- END FATURAMENTO -->
</div>
<div style="page-break-before: always">
<!-- PAGAMENTO -->
<h1 style= "font-family: &quot;Segoe UI&quot;, Frutiger, &quot;Frutiger Linotype&quot;, &quot;Dejavu Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 13px;font-size: 26px;margin: 0 0 10px 0;padding: 0;font-weight: normal; margin-top: 40px; ">Dados de Pagamento</h1>


<table style= "border-collapse: collapse; font-family: &quot;Segoe UI&quot;, Frutiger, &quot;Frutiger Linotype&quot;, &quot;Dejavu Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 13px; " cellpadding="0" cellspacing="0">
    <tr>
        <td width="27">
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/estrela.png" />
        </td>
        <td style= "font-weight: bold;padding-left: 8px; ">
            Total Geral
        </td>
    </tr>
    <tr>
        <td colspan="2" style="padding-bottom: 20px;">
            <span style= "color: #12c200;font-size: 1.4em; ">
                R$ 20.283,62
            </span><br /><br />
            
            <span style= "font-weight: bold; ">
                Total sem IPI:
            </span> R$ 17.637,93<br /><br />
        </td>
    </tr>
    
    <tr>
        <td width="27">
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/endereco.png" />
        </td>
        <td style= "font-weight: bold;padding-left: 8px; ">
            Endere o de Cobran a
        </td>
    </tr>
    <tr>
        <td colspan="2" style="padding-bottom: 20px;">
            Endere o entrega
        </td>
    </tr>
    
    <tr>
        <td width="27">
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/calendar.png" />
        </td>
        <td style= "font-weight: bold;padding-left: 8px; ">
            Prazo para Pagamento
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <span style= "font-size: 1.4em;color: #12c200; ">
                70 DDL C/ VENCTO.  S 4  FEIRAS
            </span><br/><br />
        </td>
    </tr>
    
</table>
<!-- END FATURAMENTO -->


<!-- PAGAMENTO -->
<h1 style= "font-family: &quot;Segoe UI&quot;, Frutiger, &quot;Frutiger Linotype&quot;, &quot;Dejavu Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 13px;font-size: 26px;margin: 0 0 10px 0;padding: 0;font-weight: normal; margin-top: 40px; ">Dados de Entrega</h1>


<table style= "border-collapse: collapse; font-family: &quot;Segoe UI&quot;, Frutiger, &quot;Frutiger Linotype&quot;, &quot;Dejavu Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 13px; " cellpadding="0" cellspacing="0">
    <tr>
        <td width="27">
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/estrela.png" />
        </td>
        <td style= "font-weight: bold;padding-left: 8px; ">
            Prov vel Data da Entrega
        </td>
    </tr>
    <tr>
        <td colspan="2" style="padding-bottom: 20px;">
            
                
                <span style= "color: #12c200;font-size: 1.4em; ">
                    04/05/2017
                </span><br />
                
                <span style= "color: #12c200;font-size: 1.4em; ">
                    20/04/2017
                </span><br />
                
                <span style= "color: #12c200;font-size: 1.4em; ">
                    24/04/2017
                </span><br />
                
                <span style= "color: #12c200;font-size: 1.4em; ">
                    15/05/2017
                </span><br />
                
                <span style= "color: #12c200;font-size: 1.4em; ">
                    08/05/2017
                </span><br />
                
            
            <br />
            
            <span style= "font-weight: bold; ">
                Transportadora:
            </span> None<br /><br />
        </td>
    </tr>
    
    <tr>
        <td width="27">
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/endereco.png" />
        </td>
        <td style= "font-weight: bold;padding-left: 8px; ">
            Endere o de Entrega
        </td>
    </tr>
    <tr>
        <td colspan="2" style="padding-bottom: 20px;">
            Endere o entrega
        </td>
    </tr>
    
</table>
<!-- END FATURAMENTO -->

<!-- Detalhes do Pedido -->
<h1 style= "font-family: &quot;Segoe UI&quot;, Frutiger, &quot;Frutiger Linotype&quot;, &quot;Dejavu Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 13px;font-size: 26px;margin: 0 0 10px 0;padding: 0;font-weight: normal; margin-top: 40px; ">Detalhes do Pedido</h1>

<table style= "border-collapse: collapse; font-family: &quot;Segoe UI&quot;, Frutiger, &quot;Frutiger Linotype&quot;, &quot;Dejavu Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 13px; " cellpadding="0" cellspacing="0">
    <tr>
        <td width="27">
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/pedido-detalhes.png" />
        </td>
        <td style= "font-weight: bold;padding-left: 8px; ">
            Itens do Pedido
        </td>
    </tr>
</table>

<table style= "border-collapse: collapse; font-family: &quot;Segoe UI&quot;, Frutiger, &quot;Frutiger Linotype&quot;, &quot;Dejavu Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 13px; " cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <th style= "text-align: left;border-bottom: solid 1px #a0a0a0;padding: 0 35px 2px 0; ">Quantidade</th>
            <th style= "text-align: left;border-bottom: solid 1px #a0a0a0;padding: 0 35px 2px 0; ">Produto</th>
            <th style= "text-align: left;border-bottom: solid 1px #a0a0a0;padding: 0 35px 2px 0; ">Cardex</th>
            <th style= "text-align: left;border-bottom: solid 1px #a0a0a0;padding: 0 35px 2px 0; ">NCM</th>
            <th style= "text-align: left;border-bottom: solid 1px #a0a0a0;padding: 0 35px 2px 0; ">Valor Unit rio</th>
            <th style= "text-align: left;border-bottom: solid 1px #a0a0a0;padding: 0 35px 2px 0; ">ICMS</th>
            <th style= "text-align: left;border-bottom: solid 1px #a0a0a0;padding: 0 35px 2px 0; ">IPI</th>
            <th style= "text-align: left;border-bottom: solid 1px #a0a0a0;padding: 0 35px 2px 0; ">Valor com IPI</th>
            <th style= "text-align: left;border-bottom: solid 1px #a0a0a0;padding: 0 35px 2px 0; ">Data Entrega</th>
        </tr>
    
        <tr>
            <td>1</td>
            <td>1756TBCH</td>
            <td>1319785</td>
            <td>85369090</td>
            <td>R$ 275,86</td>
            <td>R$ 0,00</td>
            <td>R$ 41,38</td>
            <td>R$ 317,24</td>
            <td>15/05/2017</td>
        </tr>
    
        <tr>
            <td>1</td>
            <td>1734OB8S</td>
            <td>1328811</td>
            <td>85389010</td>
            <td>R$ 1.516,77</td>
            <td>R$ 0,00</td>
            <td>R$ 227,52</td>
            <td>R$ 1.744,29</td>
            <td>15/05/2017</td>
        </tr>
    
        <tr>
            <td>2</td>
            <td>1746HSCE</td>
            <td>1221010</td>
            <td>85389010</td>
            <td>R$ 3.419,18</td>
            <td>R$ 0,00</td>
            <td>R$ 1.025,75</td>
            <td>R$ 7.864,11</td>
            <td>08/05/2017</td>
        </tr>
    
        <tr>
            <td>2</td>
            <td>1746A7</td>
            <td>1241620</td>
            <td>85389010</td>
            <td>R$ 1.893,15</td>
            <td>R$ 0,00</td>
            <td>R$ 567,94</td>
            <td>R$ 4.354,23</td>
            <td>04/05/2017</td>
        </tr>
    
        <tr>
            <td>2</td>
            <td>1746OW16</td>
            <td>1230330</td>
            <td>85389010</td>
            <td>R$ 1.554,83</td>
            <td>R$ 0,00</td>
            <td>R$ 466,45</td>
            <td>R$ 3.576,10</td>
            <td>20/04/2017</td>
        </tr>
    
        <tr>
            <td>1</td>
            <td>20F11ND011AA0NNNNN</td>
            <td>1333146</td>
            <td>85044050</td>
            <td>R$ 2.111,00</td>
            <td>R$ 291,32</td>
            <td>R$ 316,65</td>
            <td>R$ 2.427,65</td>
            <td>24/04/2017</td>
        </tr>
    
    
</table>
<!-- END Detalhes do Pedido -->
<table style= "border-collapse: collapse; font-family: &quot;Segoe UI&quot;, Frutiger, &quot;Frutiger Linotype&quot;, &quot;Dejavu Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 13px; margin-top: 40px; " cellpadding="0" cellspacing="0">
    <tr>
        <td colspan="2" style="padding-bottom: 20px;">
            Se preferir, voc  pode entrar agora em contato com o respons vel para revisar o pedido.
        </td>
    </tr>
    <tr>
        <td width="27">
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/contato.png" />
        </td>
        <td style= "font-weight: bold;padding-left: 8px; ">
            Contato
        </td>
    </tr>
    <tr>
        <td colspan="2" style="padding-bottom: 20px;">
            Name completed
        </td>
    </tr>
    
    <tr>
        <td width="27">
            <img style= "display: block; " src="http://customer.edgeglobalsupply.com.br/static/icones/img/telefone.png" />
        </td>
        <td style= "font-weight: bold;padding-left: 8px; ">
            Telefones e E-mail
        </td>
    </tr>
    <tr>
        <td colspan="2" style="padding-bottom: 20px;">
            11 1111-1111&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[email protected]
        </td>
    </tr>
</table>

                        </td>
                    </tr>
                </table>
                <table style= "background-color:#f7f7f7; border-collapse: collapse; " width="100%">
                    <tr>
                        <td>
                            <table style= "border-collapse: collapse; " width="900" align="center" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td><img src="http://customer.edgeglobalsupply.com.br/static/css/layout/img/logo-base.png" /></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</div> ''').write_pdf()
        print(email.mensagem)
        http_response = HttpResponse(content, content_type='application/pdf')
        http_response['Content-Disposition'] = 'attachment; filename="email-{}.pdf"'.format(email.pk)
        return http_response
raise Http404
1

1 Resposta 1

1

Galera consegui utilizando outra biblioteca, PYDF, nela consegui resolver o problema de sair somente uma pagina.

documentação da lib

https://github.com/tutorcruncher/pydf

import pydf

def render_pdf(request,pk):
if request.user.is_authenticated():
    if request.user.is_staff or request.user.is_impersonate:
        email = EmailsEnviados.objects.get(pk=pk)

        pdf = pydf.generate_pdf(email.mensagem,page_size='A4',zoom='1.1')

        http_response = HttpResponse(pdf, content_type='application/pdf')
        http_response['Content-Disposition'] = 'attachment; filename="email-{}.pdf"'.format(email.pk)
        return http_response
raise Http404

antes eu usava essa linha

content = HTML(string=email.mensagem)..write_pdf()

alterei para essa linha

pdf = pydf.generate_pdf(email.mensagem,page_size='A4',zoom='1.1')
2
  • poxa... então escreve a resposta que eu queria aprender =/ Commented 19/03/2021 às 15:31
  • Prontinho editei a resposta com as mudanças Commented 19/03/2021 às 17:13

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .