Code Monkey home page Code Monkey logo

Comments (18)

sbraconnier avatar sbraconnier commented on May 26, 2024 1

Have you tried with the latest libreoffice version ? It works on my end. You example xlsx file is a bit extreme tho! The output is not readable :)

from jodconverter.

sbraconnier avatar sbraconnier commented on May 26, 2024

Is it something you can do without JODConverter (using libreoffice only)?

from jodconverter.

phoekoby avatar phoekoby commented on May 26, 2024

Sorry, my question wasn't correct. I need to generate pdf, with one sheet on one page, like this:
image
Can I do it with JodConverter?

from jodconverter.

phoekoby avatar phoekoby commented on May 26, 2024

Is it something you can do without JODConverter (using libreoffice only)?

I screenshot above, I set “Fit print range(s) on number of pages”, now I need do it in JodConverter

from jodconverter.

sbraconnier avatar sbraconnier commented on May 26, 2024

I'll try to find out how it can be done with jodconverter and come back to you in a day or 2.

from jodconverter.

sbraconnier avatar sbraconnier commented on May 26, 2024

Try this (note that I also change the orientation to landscape, which can be removed):

final File inputFile = new File("in.ods");
final File outputFile = new File("out.pdf");

// Create a filter to change to page style of each sheet of the document.
final Filter changePageStyleFilter = (context, document, chain) -> {

    // Use the StyleFamiliesSupplier interface to get the XNameAccess interface of the actual style families.
    final XStyleFamiliesSupplier styleFamiliesSupplier = Lo.qi(XStyleFamiliesSupplier.class, document);
    final XNameAccess styleFamilies = Lo.qi(XNameAccess.class, styleFamiliesSupplier.getStyleFamilies());
    // Access the 'PageStyles' Family
    final XNameContainer pageStyleFamily = Lo.qi(XNameContainer.class, styleFamilies.getByName("PageStyles"));

    // No we must go through all the sheets to change the page style of each sheet.
    final XSpreadsheetDocument spreadsheetDocument = Lo.qi(XSpreadsheetDocument.class, document);
    final XSpreadsheets sheets = spreadsheetDocument.getSheets();
    final XIndexAccess indexedSheets = Lo.qi(XIndexAccess.class, sheets);
    final int count = indexedSheets.getCount();
    for (int i = 0; i < count; i++) {

        // We must change the page style properties of the spreadsheet.

        // First get the properties of the page style for this spreadsheet.
        final XSpreadsheet sheet = Lo.qi(XSpreadsheet.class, indexedSheets.getByIndex(i));
        final XPropertySet sheetProperties = Lo.qi(XPropertySet.class, sheet);
        final String pageStyleName = (String) sheetProperties.getPropertyValue("PageStyle");
        final XStyle pageStyle = Lo.qi(XStyle.class, pageStyleFamily.getByName(pageStyleName));
        final XPropertySet pageStyleProps = Lo.qi(XPropertySet.class, pageStyle);

        // Set the ScaleToPages property to 1, which is the programmatic equivalent
        // for setting the page style scaling mode option (Sheet tab) to:
        // "Fit print rage(s) on number of pages"
        pageStyleProps.setPropertyValue("ScaleToPages", (short) 1);

        // Change the print orientation to "landscape" and the page size, which is
        // the programmatic equivalent for setting the page style orientation (Page tab) to:
        // Landscape
        // REMOVE  TFOLLOWING 3 LINES THIS IF YOU DON'T WANT TO CHANGE THE ORIENTATION TO LANDSCAPE.
        pageStyleProps.setPropertyValue("IsLandscape", true);
        final Size pageSize = (Size) AnyConverter.toObject(Size.class, pageStyleProps.getPropertyValue("Size"));
        pageStyleProps.setPropertyValue("Size", new Size(pageSize.Height, pageSize.Width));
    }
};

LocalConverter
        .builder()
        .officeManager(manager)
        .filterChain(changePageStyleFilter)
        .build()
        .convert(inputFile)
        .to(outputFile)
        .execute();

from jodconverter.

phoekoby avatar phoekoby commented on May 26, 2024

Thanks! I have another question, can I export Sheet's Name in names of pages in PDF??

from jodconverter.

sbraconnier avatar sbraconnier commented on May 26, 2024

Hmm... again, I'm not sure I understand your question ? What is a name of page ?? :)

from jodconverter.

phoekoby avatar phoekoby commented on May 26, 2024

I meant bookmarks, I export sheet name to bookmarks:
image
But when I convert excel sheet to single page there are no bookmarks in the resulting pdf

from jodconverter.

sbraconnier avatar sbraconnier commented on May 26, 2024

Oh ok, I understand now... I'll take a look.

from jodconverter.

sbraconnier avatar sbraconnier commented on May 26, 2024

We have to find a way to do it first without jodconverter... Are you able do reproduce this behavior without jodconverter ??

from jodconverter.

phoekoby avatar phoekoby commented on May 26, 2024

I'm trying to find out how to do it, but I think it's a bug in LibreOffice, because I can not export bookmarks and moreover resulting PDF is not correct:
Example.pdf
This file is full blank, but I have this file:
Example.xlsx

from jodconverter.

phoekoby avatar phoekoby commented on May 26, 2024

Can you send me your examples??

from jodconverter.

sbraconnier avatar sbraconnier commented on May 26, 2024

Which version of libreoffice are you using ?

from jodconverter.

phoekoby avatar phoekoby commented on May 26, 2024

Which version of libreoffice are you using ?

7.5.2.2

from jodconverter.

phoekoby avatar phoekoby commented on May 26, 2024

Can I find out the size of the filled area (of the whole table) in an excel file?

from jodconverter.

sbraconnier avatar sbraconnier commented on May 26, 2024

Hmm I'm not sure what you want to do exactly. When I try to find if something can be done programatically, I often look at this guide, maybe you will find an example or something that will put you in the right direction.

from jodconverter.

sbraconnier avatar sbraconnier commented on May 26, 2024

I'll close this one. Feel free to reopen if needed.

from jodconverter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.