ramonlopes / jzebra

Automatically exported from code.google.com/p/jzebra
0 stars 0 forks source link

Printing PDFs without pdf extension? #48

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Is there a way to print generated pdfs that don't have a pdf file extension. 
Example, applet.appendPDF("http://www.example.com/pdf.php?id=1"); throws error 
"Exception occured: This may not be a PDF File" and does not print although it 
is a PDF.

Original issue reported on code.google.com by rvtecrv...@gmail.com on 13 Mar 2012 at 10:19

GoogleCodeExporter commented 8 years ago
May have to be added. Are you relying on any session cookies that Java would be 
aware of?

I'll check this code tonight and see if I'm filtering on extension.

Original comment by tres.fin...@gmail.com on 13 Mar 2012 at 10:25

GoogleCodeExporter commented 8 years ago
Actually, it is looking for Content-disposition in the header it seems.
This works:
<?php
header('Content-Type: application/pdf');
header('Content-Disposition:inline;filename=example.pdf');
?>
This does not:
<?php
header('Content-Type: application/pdf');
?>

Original comment by rvtecrv...@gmail.com on 13 Mar 2012 at 10:32

GoogleCodeExporter commented 8 years ago
Good catch.  I reviewed the code, and there are no strict bindings to file 
extension or Content-Disposition.  Since jZebra uses PDF-RENDERER as a plugin, 
it is likely the limitation is with PDF-RENDERER.  I would suggest anyone using 
jZebra for pdf printing through php appends your header tags.  I'm putting it 
in the wiki, and marking bug as WontFix.

Feel free to open a bug report with PDF-RENDERER project if you think it's 
worth addressing, and if you do, also feel free to cross-link back to this bug 
report.

-Tres

Original comment by tres.fin...@gmail.com on 14 Mar 2012 at 1:48

GoogleCodeExporter commented 8 years ago
excuse me, i have an issue related to this, i hope someone can help me.
i'm trying to print a pdf that i generate from java(server)like that:
--------------------------------------------------------------------------------
--
@RequestMapping(value = "/getReporteFactura", method = RequestMethod.GET) 
    public void getReporteFactura(@RequestParam String idFactura, HttpServletResponse httpServletResponse) {
        ReporteFacturaService service = new ReporteFacturaService();
        try{
            httpServletResponse.setContentType("application/pdf");
            //enviar como descarga
            httpServletResponse.setHeader("Content-Disposition", "inline");
            httpServletResponse.setHeader("filename","example.pdf");
            byte[] pdfImage = service.generaReporteTalon(idFactura, "LEN");
            httpServletResponse.getOutputStream().write(pdfImage);
            httpServletResponse.flushBuffer();

        }catch(Exception e){
            System.out.print(e.getMessage());
        }           
    }
---------------------------------------------------------------------
the pdf file its fine, but how do i have to send to print pdf?

this way not work :
-----------------------------------------------------------------------
function tryprintpdf(){
        if (notReady()) { return; }

        // Append our pdf (only one pdf can be appended per print)
        qz.appendPDF("http://192.168.0.100:8080/facturacion/app/seguimiento/getReporteFactura/?idFactura=11010803500");
            qz.setCopies(1);
        window['qzDoneAppending'] = function() {
            qz.printPS();
            window['qzDoneAppending'] = null;
        };
}
-----------------------------------------------------------------
OUTPUT:
java.awt.print.PrinterException: This may not be a PDF File *********
but if i acces to the route i can see the pdf file render on the browser....

Original comment by olmosman...@gmail.com on 29 Apr 2015 at 12:25

GoogleCodeExporter commented 8 years ago
Did you add `header('Content-Disposition:inline;filename=example.pdf');` like 
the OP suggested?

If so, you may want to try accessing your URL via another browser and see if it 
is behind some authentication mechanism which Java would not be able to handle 
(and land on a 404 page, etc).

Original comment by tres.fin...@gmail.com on 29 Apr 2015 at 12:55

GoogleCodeExporter commented 8 years ago
well... i set the header like:
            httpServletResponse.setHeader("Content-Disposition", "inline");
            httpServletResponse.setHeader("filename","example.pdf");
i guest it's the same as 
header('Content-Disposition:inline;filename=example.pdf')
....actualy i can acces from diferent browsers, but i dont know if i'm doing 
the call rigth from the javascript coud you please give me your mail or 
something =)
tnx.
PD: sory about my english jeje 

Original comment by olmosman...@gmail.com on 29 Apr 2015 at 2:07

GoogleCodeExporter commented 8 years ago
Your logic looks just fine.

I would recommend that you:

1. Download a PDF from your site
2. Replace the sample_pdf file in the demo with your downloaded PDF
3. Report results.

If the file still does not work, it might be related to PDF-RENDERER.  We have 
an alternate library we have bundled for a few clients, but we should start a 
support agreement before jumping into special builds.

-Tres

Original comment by tres.fin...@gmail.com on 29 Apr 2015 at 4:05