Comments (18)
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.
Is it something you can do without JODConverter (using libreoffice only)?
from jodconverter.
Sorry, my question wasn't correct. I need to generate pdf, with one sheet on one page, like this:
Can I do it with JodConverter?
from jodconverter.
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.
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.
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.
Thanks! I have another question, can I export Sheet's Name in names of pages in PDF??
from jodconverter.
Hmm... again, I'm not sure I understand your question ? What is a name of page ?? :)
from jodconverter.
I meant bookmarks, I export sheet name to bookmarks:
But when I convert excel sheet to single page there are no bookmarks in the resulting pdf
from jodconverter.
Oh ok, I understand now... I'll take a look.
from jodconverter.
We have to find a way to do it first without jodconverter... Are you able do reproduce this behavior without jodconverter ??
from jodconverter.
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.
Can you send me your examples??
from jodconverter.
Which version of libreoffice are you using ?
from jodconverter.
Which version of libreoffice are you using ?
7.5.2.2
from jodconverter.
Can I find out the size of the filled area (of the whole table) in an excel file?
from jodconverter.
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.
I'll close this one. Feel free to reopen if needed.
from jodconverter.
Related Issues (20)
- When converting DOCX to PDF the style is confused and many pages are lost HOT 4
- how to use it in android application ? HOT 1
- pptx file conversion of PDF failed HOT 1
- Why Task was cancelled automatically HOT 2
- StoreProperties property settings HOT 1
- Temp folder not deleted after Timeout Exceptions HOT 5
- High memory consumptiom while converting even 2-3MB of excel files to PDF HOT 5
- The Word document with more than 12 pages will automatically cancel the task. HOT 4
- Started process; pid = -2
- Error when converting Excel to PDF HOT 3
- The program running on Docker keeps generating zombie processes.
- Not working with quartz? HOT 13
- I have a question about conversion options (password, page size ,etc) HOT 10
- Xslx SparkLine HOT 1
- Decimal number, from comma to dot HOT 17
- Information about supported properties and their meaning HOT 2
- LocalOfficeManager not killing existing process on the same port HOT 4
- Same issue with Temporary file name added in CSV -> PDF conversion HOT 3
- jodconverter-local 4.4.3 or later causes the service to fail to end. HOT 7
- org.jodconverter.core.office.OfficeException: Task was cancelled: LocalConversionTask HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jodconverter.