简体   繁体   English

使用Docx4j在Word文档中设置自定义页面大小

[英]Set Custom Page size in Word Document using Docx4j

How can I create a document with custom page size using docx4j. 如何使用docx4j创建具有自定义页面大小的文档。 I have searched over the net and able to find that we can create the page size available in PageSizePaper ENUM only....Please help me out to create the doc with custom page size.. 我在网上搜索了一下,发现我们只能在PageSizePaper ENUM中创建可用的页面大小。...请帮助我创建具有自定义页面大小的文档。

Hello World invokes WordprocessingMLPackage.createPackage() Hello World调用WordprocessingMLPackage.createPackage()

If you follow that code, you'll see at https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/openpackaging/packages/WordprocessingMLPackage.java#L445 that you need a PgSz object. 如果您遵循该代码,则会在https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/openpackaging/packages/WordprocessingMLPackage.java#L445中看到PgSz对象。

You can use the docx4j webapp or Helper AddIn on a docx where you have set a custom page size (ie in Word) to see what that code would look like. 您可以在设置了自定义页面大小(即在Word中)的docx上使用docx4j webapp或Helper AddIn来查看该代码的外观。 Here is an example: 这是一个例子:

        SectPr.PgSz sectprpgsz = wmlObjectFactory.createSectPrPgSz(); 
        sectpr.setPgSz(sectprpgsz); 
            sectprpgsz.setH( BigInteger.valueOf( 16838) ); 
            sectprpgsz.setW( BigInteger.valueOf( 11906) );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM