Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

wBB

[Resolvido] FPDF: Não gera o PDF

Recommended Posts

Pessoal,

Estou tentando gerar PDF com a classe FPDF, mas em lugar de aparecer o PDF no browser parece que está sendo impresso o "binário" do que foi gerado.

O código é simples:

define("FPDF_FONTPATH", "fpdf/font/");
require_once("fpdf/fpdf.php");
$pdf = new FPDF();
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont("Arial", "B", 36);
$pdf->Cell(50, 30, "Hello World");
$pdf->Output();
É exibido no browser o seguinte:

%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream xœ3Rðâ2Ð35W(çr QÐw3T06Ó30PISp  êZ*˜›è)„¤(hx¤æää+„çå¤h*„d”v) endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 5 0 R >> /XObject << >> >> endobj 6 0 obj << /Producer (FPDF 1.53) /CreationDate (D:20080801222633) >> endobj 7 0 obj << /Type /Catalog /Pages 1 0 R /OpenAction [3 0 R /FitH null] /PageLayout /OneColumn >> endobj xref 0 8 0000000000 65535 f 0000000229 00000 n 0000000417 00000 n 0000000009 00000 n 0000000087 00000 n 0000000316 00000 n 0000000521 00000 n 0000000597 00000 n trailer << /Size 8 /Root 7 0 R /Info 6 0 R >> startxref 700 %%EOF
Alguém sabe dizer o que está errado?

Compartilhar este post


Link para o post
Compartilhar em outros sites

AlterC, o problema não é fazer o PDF e sim exibir, que estava dando erro.

 

De qualquer forma já resolvi e não era uma problema propriamente, conforme exposto na FAQ da classe FPDF:

 

2. When I try to create a PDF, a lot of weird characters show on the screen. Why?

 

These "weird" characters are in fact the actual content of your PDF. This behavior is a bug of IE6. When it first receives an HTML page, then a PDF from the same URL, it displays it directly without launching Acrobat. This happens frequently during the development stage: on the least script error, an HTML page is sent, and after correction, the PDF arrives.

To solve the problem, simply quit and restart IE. You can also go to another URL and come back.

To avoid this kind of inconvenience during the development, you can generate the PDF directly to a file and open it through the explorer.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.