Hi, See how we use it in our ERP :
http://code.openconcerto.org/filedetails.php?repname=OpenConcerto&path=%2Ftrunk%2FOpenConcerto%2Fsrc%2Forg%2Fopenconcerto%2Ferp%2FgenerationDoc%2FSheetUtils.java convert2PDF() is your friend :) Regards, Guillaume Le jeu. 14 févr. 2019 à 22:11, <graziamu...@gmail.com> a écrit : > 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 > > > > > On Thursday, February 14, 2019 at 5:18:30 PM UTC-3, guillaume...@gmail.com > wrote: >> >> Hi, >> >> Can you share the code you are using to "print" it? >> >> Regards, >> >> Le jeu. 14 févr. 2019 à 20:15, <grazi...@gmail.com> a écrit : >> >>> >>> this is the layout that i'm trying to use >>> >>> On Thursday, February 14, 2019 at 4:13:21 PM UTC-3, grazi...@gmail.com >>> wrote: >>>> >>>> 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" >>>> >>>> >>>> On Tuesday, February 12, 2019 at 10:44:00 AM UTC-3, >>>> guillaume...@gmail.com wrote: >>>>> >>>>> Hi, >>>>> >>>>> I think that your print range is not defined in your ODS. >>>>> >>>>> Cordialement, >>>>> >>>>> Le mar. 12 févr. 2019 à 14:42, <grazi...@gmail.com> a écrit : >>>>> >>>>>> 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? >>>>>> >>>>>> -- >>>>>> >>>>>> --- >>>>>> 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. >>>>>> >>>>> -- >>> >>> --- >>> 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. >>> >> -- > > --- > 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 jopendocument+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- --- 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 jopendocument+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.