Comments (2)
I'm glad someone tried to create a new Filter!!! You are the first one to post one here :).
I've made minor changes in order to get your filter to work. Could you please try this one. If it works, I'll added it into the main disctribution.
/** This filter is used to set the margins of the document being converted. */
public class PageMarginsFilter implements Filter {
// This class has been inspired by these examples:
// https://wiki.openoffice.org/wiki/Translating_Java_Code_in_cpp
// https://github.com/bomm/thera-pi-2/blob/master/RehaBillEdit/src/Tools/OOTools.java#L328
private static final Logger LOGGER = LoggerFactory.getLogger(PageMarginsFilter.class);
private final Integer topMargin;
private final Integer rightMargin;
private final Integer bottomMargin;
private final Integer leftMargin;
/**
* Creates a new filter that will set the margins of the document.
*
* @param leftMargin The left margin (millimeters), may be null. If null, the left margin does not
* change.
* @param topMargin The top margin (millimeters), may be null. If null, the top margin does not
* change.
* @param rightMargin The right margin (millimeters), may be null. If null, the right margin does
* not change.
* @param bottomMargin The bottom margin (millimeters), may be null. If null, the bottom margin
* does not change.
*/
public PageMarginsFilter(
final Integer leftMargin,
final Integer topMargin,
final Integer rightMargin,
final Integer bottomMargin) {
super();
this.leftMargin = leftMargin;
this.topMargin = topMargin;
this.rightMargin = rightMargin;
this.bottomMargin = bottomMargin;
}
@Override
public void doFilter(
final OfficeContext context, final XComponent document, final FilterChain chain)
throws Exception {
// Querying for the interface XTextDocument (text interface) on the XComponent
final XTextDocument docText = UnoRuntime.queryInterface(XTextDocument.class, document);
// Create a text cursor from the cells XText interface
final XTextCursor xTextCursor = docText.getText().createTextCursor();
// Get the property set of the cell's TextCursor
final XPropertySet xTextCursorProps =
UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
// Get the Page Style name at the cursor position
final String pageStyleName = xTextCursorProps.getPropertyValue("PageStyleName").toString();
// Get the StyleFamiliesSupplier interface of the document
final XStyleFamiliesSupplier xSupplier =
UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, docText);
// Use the StyleFamiliesSupplier interface to get the XNameAccess interface of the
// actual style families
final XNameAccess xFamilies =
UnoRuntime.queryInterface(XNameAccess.class, xSupplier.getStyleFamilies());
// Access the 'PageStyles' Family
final XNameContainer xFamily =
UnoRuntime.queryInterface(XNameContainer.class, xFamilies.getByName("PageStyles"));
// Get the style of the current page from the PageStyles family
final XStyle xStyle = UnoRuntime.queryInterface(XStyle.class, xFamily.getByName(pageStyleName));
//
// We could also just bet that the Standard style is used. If this is what we want,
// uncomment the following line, and remove the ones (used to get the pageStyleName)
// that will no longer be required.
//
// Get the "Standard" style from the PageStyles family
// XStyle xStyle = UnoRuntime.queryInterface(XStyle.class, xFamily.getByName("Standard"));
LOGGER.debug(
"Changing margins using: [left={}, top={}, right={}, bottom={}]",
leftMargin,
topMargin,
rightMargin,
bottomMargin);
// Get the property set of the style
final XPropertySet xStyleProps = UnoRuntime.queryInterface(XPropertySet.class, xStyle);
// Change the margins (1 = 0.01 mm)
if (leftMargin != null) {
xStyleProps.setPropertyValue("LeftMargin", leftMargin * 100);
}
if (topMargin != null) {
xStyleProps.setPropertyValue("TopMargin", topMargin * 100);
}
if (rightMargin != null) {
xStyleProps.setPropertyValue("RightMargin", rightMargin * 100);
}
if (bottomMargin != null) {
xStyleProps.setPropertyValue("BottomMargin", bottomMargin * 100);
}
// Invoke the next filter in the chain
chain.doFilter(context, document);
}
}
from jodconverter.
Hello Simon,
this works for me!
Thank you
from jodconverter.
Related Issues (20)
- Add publish mode to presentation->html conversion in document-formats.json HOT 7
- missing fonts on convertion from docx to pdf HOT 2
- When exporting a PDF document, how do I set the document title / author? HOT 2
- 启动加载异常 bean of type 'org.jodconverter.core.DocumentConverter' that could not be found. HOT 1
- Accesible PDF export HOT 2
- Failed to load class "org.slf4j.impl.StaticLoggerBinder".
- Could not store document: tempfile_1.pdf HOT 4
- Can not convert .pdf to .docx HOT 1
- Using SpringBoot autoconfiguration with a remote setup fails with ClassNotFoundException HOT 2
- Compress Images When convert from Excel to pdf HOT 2
- Custom Page Size HOT 18
- excel转pdf设置格式 HOT 3
- Issues with converting Excel to HTML HOT 6
- 4.4.2word导出pdf,偶尔出现org.jodconverter.core.office.OfficeException: Task did not complete: LocalConversionTask{source=SourceDocumentSpecsFromInputStream{file=null, for mat=null}, loadProperties=null, target=TargetDocumentSpecsFromOutputStream{file=null, format=pdf}, storeProperties=null} HOT 9
- Getting error: Unsupported URL "type detection failed" HOT 2
- Unable to connect to external liberoffice when deploying springboot applications using Docker HOT 2
- LibreOffice not starting when run from Systemd / tomcat user HOT 2
- Feature Request - Send multiple documents to JodConverter and receive a merged document? HOT 1
- Use of plug-ins HOT 1
- hwp file cannot be opened HOT 2
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.