Problem exporting a Ods to PDF

20 views
Skip to first unread message

grazi...@gmail.com

unread,
Feb 12, 2019, 8:42:36 AM2/12/19
to jOpenDocument
hi.
i followed every instruction on the tutorial (using a old version of itext ) but i can't manage to print more than one page.
i tried changing the first page size, but it didn't work.

i dont know what im doing wrong.
how do you print more than one page?
can you print more than one page?

Guillaume Maillard

unread,
Feb 12, 2019, 8:44:00 AM2/12/19
to jopend...@googlegroups.com
Hi,

I think that your print range is not defined in your ODS.

Cordialement,

--

---
You received this message because you are subscribed to the Google Groups "jOpenDocument" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jopendocumen...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

grazi...@gmail.com

unread,
Feb 14, 2019, 2:13:21 PM2/14/19
to jOpenDocument
hi, i defined the print range in openoffice, its like before, it only prints the first page.
i know that the data is there, the size of the pdf varies if i try to print a larger or smaller document, but still it only prints the first page.
it "prints" a second page, but is allways blank.
i tried to play with the page size but the program (i think that itext) throws this line
"StylePageLayoutProperties: Assuming Page Format A4: Width:  21.0cm"

grazi...@gmail.com

unread,
Feb 14, 2019, 2:15:18 PM2/14/19
to jOpenDocument

this is the layout that i'm trying to use
estad2.ods

Guillaume Maillard

unread,
Feb 14, 2019, 3:18:30 PM2/14/19
to jopend...@googlegroups.com
Hi,

Can you share the code you are using to "print" it?

Regards,

grazi...@gmail.com

unread,
Feb 14, 2019, 4:11:36 PM2/14/19
to jOpenDocument
Hi.
yeah.
here it is

    public static void pdf(File  s, String ss) throws FileNotFoundException, DocumentException
    {
            // Load the ODS file
     OpenDocument doc = new OpenDocument();
     doc.loadFrom(s);
       
     // Open the PDF document
     Document document = new Document(PageSize.A4);
     File outFile = new File(ss);
    
     PdfDocument pdf = new PdfDocument();
     document.addDocListener(pdf);
    
     FileOutputStream fileOutputStream = new FileOutputStream(outFile);
     PdfWriter writer = PdfWriter.getInstance(pdf, fileOutputStream);
     pdf.addWriter(writer);

     document.open();

     // Create a template and a Graphics2D object
     Rectangle pageSize = document.getPageSize();
     int w = (int) (pageSize.getWidth() * 0.9);
     int h = (int) (pageSize.getHeight() * 0.95);
     PdfContentByte cb = writer.getDirectContent();
     PdfTemplate tp = cb.createTemplate(w, h);

     Graphics2D g2 = tp.createPrinterGraphics(w, h, null);
     // If you want to prevent copy/paste, you can use
     // g2 = tp.createGraphicsShapes(w, h, true, 0.9f);

     tp.setWidth(w);
     tp.setHeight(h);

     // Configure the renderer
     ODTRenderer renderer = new ODTRenderer(doc);
     renderer.setIgnoreMargins(true);
     renderer.setPaintMaxResolution(true);

     // Scale the renderer to fit width
     renderer.setResizeFactor(renderer.getPrintWidth() / w);
     // Render
     renderer.paintComponent(g2);
     g2.dispose();

     // Add our spreadsheet in the middle of the page
     float offsetX = (pageSize.getWidth() - w) / 2;
     float offsetY = (pageSize.getHeight() - h) / 2 ;
    
     cb.addTemplate(tp, offsetX, offsetY);
     // Close the PDF documen
     document.close();
    }

and this is the output

StylePageLayoutProperties: Assuming Page Format A4: Width:  21.0cm
StylePageLayoutProperties: Assuming Page Format A4: Height: 29.7cm
PageHeigth:863600

Guillaume Maillard

unread,
Feb 14, 2019, 5:01:16 PM2/14/19
to jopend...@googlegroups.com

grazi...@gmail.com

unread,
Feb 14, 2019, 5:15:49 PM2/14/19
to jOpenDocument
it worked!!
thanks ♥
i really appreciate it.
Reply all
Reply to author
Forward
0 new messages