Fix default section page props (#164)

* feat: Add default section page size and margin

* feat: Add reader

* spec: Update snaps

* feat: Suppoert page margin and size

* feat: support js
main
bokuweb 2020-10-09 20:30:55 +09:00 committed by GitHub
parent 3329543c56
commit 8e7ddbca70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 374 additions and 58 deletions

View File

@ -0,0 +1,18 @@
use docx_rs::*;
pub fn main() -> Result<(), DocxError> {
let path = std::path::Path::new("./output/page_margin.docx");
let file = std::fs::File::create(&path).unwrap();
Docx::new()
.add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello")))
.page_margin(
PageMargin::new()
.top(3200)
.footer(3200)
.left(3200)
.right(3200),
)
.build()
.pack(file)?;
Ok(())
}

View File

@ -0,0 +1,12 @@
use docx_rs::*;
pub fn main() -> Result<(), DocxError> {
let path = std::path::Path::new("./output/page_size.docx");
let file = std::fs::File::create(&path).unwrap();
Docx::new()
.add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello")))
.page_size(200, 400)
.build()
.pack(file)?;
Ok(())
}

View File

@ -97,6 +97,21 @@ impl Document {
.push(DocumentChild::BookmarkEnd(BookmarkEnd::new(id))); .push(DocumentChild::BookmarkEnd(BookmarkEnd::new(id)));
self self
} }
pub fn page_size(mut self, size: PageSize) -> Self {
self.section_property = self.section_property.page_size(size);
self
}
pub fn page_margin(mut self, margin: crate::types::PageMargin) -> Self {
self.section_property = self.section_property.page_margin(margin);
self
}
pub fn default_section_property(mut self, property: SectionProperty) -> Self {
self.section_property = property;
self
}
} }
impl BuildXML for Document { impl BuildXML for Document {

View File

@ -1,20 +1,7 @@
use crate::documents::BuildXML; use crate::documents::BuildXML;
use crate::types::PageMargin;
use crate::xml_builder::*; use crate::xml_builder::*;
use serde::Serialize;
#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PageMargin {
top: usize,
left: usize,
bottom: usize,
right: usize,
header: usize,
footer: usize,
gutter: usize,
}
// These values were based on microsoft office word2019 windows edition. // These values were based on microsoft office word2019 windows edition.
// <w:pgMar w:top="1985" w:right="1701" w:bottom="1701" w:left="1701" w:header="851" w:footer="992" w:gutter="0"/> // <w:pgMar w:top="1985" w:right="1701" w:bottom="1701" w:left="1701" w:header="851" w:footer="992" w:gutter="0"/>
impl Default for PageMargin { impl Default for PageMargin {
@ -36,27 +23,31 @@ impl PageMargin {
Default::default() Default::default()
} }
pub fn top(self, v: usize) -> PageMargin { pub fn top(self, v: u32) -> PageMargin {
PageMargin { top: v, ..self } PageMargin { top: v, ..self }
} }
pub fn left(self, v: usize) -> PageMargin { pub fn left(self, v: u32) -> PageMargin {
PageMargin { left: v, ..self } PageMargin { left: v, ..self }
} }
pub fn bottom(self, v: usize) -> PageMargin { pub fn bottom(self, v: u32) -> PageMargin {
PageMargin { bottom: v, ..self } PageMargin { bottom: v, ..self }
} }
pub fn right(self, v: usize) -> PageMargin { pub fn right(self, v: u32) -> PageMargin {
PageMargin { right: v, ..self } PageMargin { right: v, ..self }
} }
pub fn header(self, v: usize) -> PageMargin { pub fn header(self, v: u32) -> PageMargin {
PageMargin { header: v, ..self } PageMargin { header: v, ..self }
} }
pub fn gutter(self, v: usize) -> PageMargin { pub fn footer(self, v: u32) -> PageMargin {
PageMargin { footer: v, ..self }
}
pub fn gutter(self, v: u32) -> PageMargin {
PageMargin { gutter: v, ..self } PageMargin { gutter: v, ..self }
} }
} }

View File

@ -6,8 +6,8 @@ use serde::Serialize;
#[derive(Debug, Clone, PartialEq, Serialize)] #[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct PageSize { pub struct PageSize {
w: usize, w: u32,
h: usize, h: u32,
} }
// These values were based on microsoft office word2019 windows edition. // These values were based on microsoft office word2019 windows edition.
@ -23,9 +23,19 @@ impl PageSize {
Default::default() Default::default()
} }
pub fn size(self, w: usize, h: usize) -> PageSize { pub fn size(self, w: u32, h: u32) -> PageSize {
PageSize { w, h } PageSize { w, h }
} }
pub fn width(mut self, w: u32) -> PageSize {
self.w = w;
self
}
pub fn height(mut self, h: u32) -> PageSize {
self.h = h;
self
}
} }
impl BuildXML for PageSize { impl BuildXML for PageSize {

View File

@ -20,6 +20,16 @@ impl SectionProperty {
pub fn new() -> SectionProperty { pub fn new() -> SectionProperty {
Default::default() Default::default()
} }
pub fn page_size(mut self, size: PageSize) -> Self {
self.page_size = size;
self
}
pub fn page_margin(mut self, margin: PageMargin) -> Self {
self.page_margin = margin;
self
}
} }
impl Default for SectionProperty { impl Default for SectionProperty {

View File

@ -199,6 +199,16 @@ impl Docx {
self self
} }
pub fn page_size(mut self, w: u32, h: u32) -> Self {
self.document = self.document.page_size(PageSize::new().size(w, h));
self
}
pub fn page_margin(mut self, margin: crate::types::PageMargin) -> Self {
self.document = self.document.page_margin(margin);
self
}
pub fn build(&mut self) -> XMLDocx { pub fn build(&mut self) -> XMLDocx {
self.update_comments(); self.update_comments();
let (image_ids, images) = self.create_images(); let (image_ids, images) = self.create_images();

View File

@ -38,6 +38,11 @@ impl FromXML for Document {
doc = doc.add_bookmark_end(e.id); doc = doc.add_bookmark_end(e.id);
continue; continue;
} }
XMLElement::SectionProperty => {
let e = SectionProperty::read(&mut parser, &attributes)?;
doc = doc.default_section_property(e);
continue;
}
_ => {} _ => {}
} }
} }

View File

@ -21,6 +21,7 @@ mod read_zip;
mod rels; mod rels;
mod run; mod run;
mod run_property; mod run_property;
mod section_property;
mod settings; mod settings;
mod style; mod style;
mod styles; mod styles;

View File

@ -0,0 +1,96 @@
use std::io::Read;
use std::str::FromStr;
use xml::attribute::OwnedAttribute;
use xml::reader::{EventReader, XmlEvent};
use super::*;
fn read_page_size(attributes: &[OwnedAttribute]) -> Result<PageSize, ReaderError> {
let mut size = PageSize::new();
for a in attributes {
let local_name = &a.name.local_name;
match local_name.as_str() {
"w" => {
size = size.width(f32::from_str(&a.value)? as u32);
}
"h" => {
size = size.height(f32::from_str(&a.value)? as u32);
}
_ => {}
}
}
Ok(size)
}
fn read_page_margin(
attributes: &[OwnedAttribute],
) -> Result<crate::types::PageMargin, ReaderError> {
let mut margin = crate::types::PageMargin::new();
for a in attributes {
let local_name = &a.name.local_name;
match local_name.as_str() {
"top" => {
margin = margin.top(f32::from_str(&a.value)? as u32);
}
"right" => {
margin = margin.right(f32::from_str(&a.value)? as u32);
}
"bottom" => {
margin = margin.bottom(f32::from_str(&a.value)? as u32);
}
"left" => {
margin = margin.left(f32::from_str(&a.value)? as u32);
}
"header" => {
margin = margin.header(f32::from_str(&a.value)? as u32);
}
"footer" => {
margin = margin.footer(f32::from_str(&a.value)? as u32);
}
"gutter" => {
margin = margin.gutter(f32::from_str(&a.value)? as u32);
}
_ => {}
}
}
Ok(margin)
}
impl ElementReader for SectionProperty {
fn read<R: Read>(
r: &mut EventReader<R>,
_attrs: &[OwnedAttribute],
) -> Result<Self, ReaderError> {
let mut sp = SectionProperty::new();
loop {
let e = r.next();
match e {
Ok(XmlEvent::StartElement {
attributes, name, ..
}) => {
let e = XMLElement::from_str(&name.local_name).unwrap();
match e {
XMLElement::PageMargin => {
let margin = read_page_margin(&attributes)?;
sp = sp.page_margin(margin);
}
XMLElement::PageSize => {
let size = read_page_size(&attributes)?;
sp = sp.page_size(size);
}
_ => {}
}
}
Ok(XmlEvent::EndElement { name, .. }) => {
let e = XMLElement::from_str(&name.local_name).unwrap();
if e == XMLElement::SectionProperty {
return Ok(sp);
}
}
Err(_) => return Err(ReaderError::XMLReadError),
_ => {}
}
}
}
}

View File

@ -99,6 +99,9 @@ pub enum XMLElement {
TxbxContent, TxbxContent,
Pict, Pict,
DocId, DocId,
SectionProperty,
PageSize,
PageMargin,
Unsupported, Unsupported,
} }
@ -250,6 +253,9 @@ impl FromStr for XMLElement {
"lvlOverride" => Ok(XMLElement::LvlOverride), "lvlOverride" => Ok(XMLElement::LvlOverride),
"startOverride" => Ok(XMLElement::StartOverride), "startOverride" => Ok(XMLElement::StartOverride),
"docId" => Ok(XMLElement::DocId), "docId" => Ok(XMLElement::DocId),
"sectPr" => Ok(XMLElement::SectionProperty),
"pgSz" => Ok(XMLElement::PageSize),
"pgMar" => Ok(XMLElement::PageMargin),
_ => Ok(XMLElement::Unsupported), _ => Ok(XMLElement::Unsupported),
} }
} }

View File

@ -6,6 +6,7 @@ pub mod emu;
pub mod errors; pub mod errors;
pub mod font_pitch_type; pub mod font_pitch_type;
pub mod level_suffix_type; pub mod level_suffix_type;
pub mod page_margin;
pub mod section_type; pub mod section_type;
pub mod special_indent_type; pub mod special_indent_type;
pub mod style_type; pub mod style_type;
@ -22,6 +23,7 @@ pub use emu::*;
pub use errors::*; pub use errors::*;
pub use font_pitch_type::*; pub use font_pitch_type::*;
pub use level_suffix_type::*; pub use level_suffix_type::*;
pub use page_margin::*;
pub use section_type::*; pub use section_type::*;
pub use special_indent_type::*; pub use special_indent_type::*;
pub use style_type::*; pub use style_type::*;

View File

@ -0,0 +1,16 @@
use serde::Serialize;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PageMargin {
pub top: u32,
pub left: u32,
pub bottom: u32,
pub right: u32,
pub header: u32,
pub footer: u32,
pub gutter: u32,
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -16,6 +16,7 @@ import { Numbering } from "./numbering";
import { BookmarkStart } from "./bookmark-start"; import { BookmarkStart } from "./bookmark-start";
import { BookmarkEnd } from "./bookmark-end"; import { BookmarkEnd } from "./bookmark-end";
import { Settings } from "./settings"; import { Settings } from "./settings";
import { SectionProperty, PageMargin } from "./section-property";
import { DocxJSON } from "./json"; import { DocxJSON } from "./json";
import * as wasm from "./pkg"; import * as wasm from "./pkg";
@ -53,6 +54,7 @@ export class Docx {
abstractNumberings: AbstractNumbering[] = []; abstractNumberings: AbstractNumbering[] = [];
numberings: Numbering[] = []; numberings: Numbering[] = [];
settings: Settings = new Settings(); settings: Settings = new Settings();
sectionProperty: SectionProperty = new SectionProperty();
addParagraph(p: Paragraph) { addParagraph(p: Paragraph) {
if (p.hasNumberings) { if (p.hasNumberings) {
@ -95,6 +97,16 @@ export class Docx {
return this; return this;
} }
pageSize(w: number, h: number) {
this.sectionProperty.pageSize(w, h);
return this;
}
pageMargin(margin: Partial<PageMargin>) {
this.sectionProperty.pageMargin(margin);
return this;
}
buildRun(r: Run) { buildRun(r: Run) {
let run = wasm.createRun(); let run = wasm.createRun();
r.children.forEach((child) => { r.children.forEach((child) => {
@ -532,6 +544,32 @@ export class Docx {
docx = docx.doc_id(this.settings._docId); docx = docx.doc_id(this.settings._docId);
} }
if (this.sectionProperty._pageMargin) {
const {
top,
left,
right,
bottom,
header,
footer,
gutter,
} = this.sectionProperty._pageMargin;
const margin = new wasm.PageMargin();
margin.top = top;
margin.left = left;
margin.right = right;
margin.bottom = bottom;
margin.header = header;
margin.footer = footer;
margin.gutter = gutter;
docx = docx.page_margin(margin);
}
if (this.sectionProperty._pageSize) {
const { w, h } = this.sectionProperty._pageSize;
docx = docx.page_size(w, h);
}
const buf = docx.build(this.hasNumberings); const buf = docx.build(this.hasNumberings);
docx.free(); docx.free();
return buf; return buf;

View File

@ -0,0 +1,38 @@
export class SectionProperty {
_pageSize: PageSize | null = null;
_pageMargin: PageMargin | null = null;
pageSize(w: number, h: number) {
this._pageSize = { w, h };
return this;
}
pageMargin(margin: Partial<PageMargin>) {
this._pageMargin = { ...defaultPageMargin(), ...margin };
return this;
}
}
export type PageSize = { w: number; h: number };
export type PageMargin = {
top: number;
right: number;
bottom: number;
left: number;
header: number;
footer: number;
gutter: number;
};
export const defaultPageMargin = () => {
return {
top: 1985,
left: 1701,
bottom: 1701,
right: 1701,
header: 851,
footer: 992,
gutter: 0,
};
};

View File

@ -48,6 +48,16 @@ impl Docx {
self self
} }
pub fn page_size(mut self, w: u32, h: u32) -> Docx {
self.0 = self.0.page_size(w, h);
self
}
pub fn page_margin(mut self, margin: docx_rs::PageMargin) -> Docx {
self.0 = self.0.page_margin(margin);
self
}
pub fn build(&mut self, has_numberings: bool) -> Result<Vec<u8>, JsValue> { pub fn build(&mut self, has_numberings: bool) -> Result<Vec<u8>, JsValue> {
let buf = Vec::new(); let buf = Vec::new();
let mut cur = std::io::Cursor::new(buf); let mut cur = std::io::Cursor::new(buf);

View File

@ -1790,13 +1790,13 @@ Object {
"id": "rId4", "id": "rId4",
}, },
"pageMargin": Object { "pageMargin": Object {
"bottom": 1701, "bottom": 600,
"footer": 992, "footer": 992,
"gutter": 0, "gutter": 0,
"header": 851, "header": 851,
"left": 1701, "left": 1701,
"right": 1701, "right": 1400,
"top": 1985, "top": 1700,
}, },
"pageSize": Object { "pageSize": Object {
"h": 16838, "h": 16838,
@ -2373,8 +2373,8 @@ Object {
"top": 1985, "top": 1985,
}, },
"pageSize": Object { "pageSize": Object {
"h": 16838, "h": 16840,
"w": 11906, "w": 11900,
}, },
"sectionType": null, "sectionType": null,
}, },
@ -3729,3 +3729,30 @@ exports[`writer should write lvlOverride with level 3`] = `
</w:num><w:num w:numId=\\"0\\"> </w:num><w:num w:numId=\\"0\\">
<w:abstractNumId w:val=\\"0\\" /><w:lvlOverride w:ilvl=\\"0\\"><w:lvl w:ilvl=\\"0\\"><w:start w:val=\\"3\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"%1\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /></w:pPr></w:lvl></w:lvlOverride></w:num></w:numbering>" <w:abstractNumId w:val=\\"0\\" /><w:lvlOverride w:ilvl=\\"0\\"><w:lvl w:ilvl=\\"0\\"><w:start w:val=\\"3\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"%1\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /></w:pPr></w:lvl></w:lvlOverride></w:num></w:numbering>"
`; `;
exports[`writer should write page size 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<Relationships xmlns=\\"http://schemas.openxmlformats.org/package/2006/relationships\\">
<Relationship Id=\\"rId1\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles\\" Target=\\"styles.xml\\" />
<Relationship Id=\\"rId2\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable\\" Target=\\"fontTable.xml\\" />
<Relationship Id=\\"rId3\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings\\" Target=\\"settings.xml\\" />
<Relationship Id=\\"rId4\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header\\" Target=\\"header1.xml\\" />
<Relationship Id=\\"rId5\\" Type=\\"http://schemas.microsoft.com/office/2011/relationships/commentsExtended\\" Target=\\"commentsExtended.xml\\" />
</Relationships>"
`;
exports[`writer should write page size 2`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" standalone=\\"yes\\"?>
<w:document xmlns:o=\\"urn:schemas-microsoft-com:office:office\\" xmlns:r=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\\" xmlns:v=\\"urn:schemas-microsoft-com:vml\\" xmlns:w=\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\" xmlns:w10=\\"urn:schemas-microsoft-com:office:word\\" xmlns:wp=\\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\\" xmlns:wps=\\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\\" xmlns:wpg=\\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\\" xmlns:mc=\\"http://schemas.openxmlformats.org/markup-compatibility/2006\\" xmlns:wp14=\\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\\" xmlns:w14=\\"http://schemas.microsoft.com/office/word/2010/wordml\\" xmlns:w15=\\"http://schemas.microsoft.com/office/word/2012/wordml\\" mc:Ignorable=\\"w14 wp14\\">
<w:body><w:p w14:paraId=\\"0000001f\\"><w:pPr><w:rPr /></w:pPr><w:r><w:rPr><w:rFonts /></w:rPr><w:t xml:space=\\"preserve\\">Hello world!!</w:t></w:r></w:p><w:sectPr><w:pgSz w:w=\\"400\\" w:h=\\"800\\" /><w:pgMar w:top=\\"1985\\" w:right=\\"1701\\" w:bottom=\\"1701\\" w:left=\\"1701\\" w:header=\\"851\\" w:footer=\\"992\\" w:gutter=\\"0\\" /><w:headerReference w:type=\\"default\\" r:id=\\"rId4\\" /><w:cols w:space=\\"425\\" />
<w:docGrid w:type=\\"lines\\" w:linePitch=\\"360\\" />
</w:sectPr></w:body>
</w:document>"
`;
exports[`writer should write page size 3`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" standalone=\\"yes\\"?>
<w:numbering xmlns:r=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\\" xmlns:o=\\"urn:schemas-microsoft-com:office:office\\" xmlns:v=\\"urn:schemas-microsoft-com:vml\\" xmlns:w=\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\"><w:abstractNum w:abstractNumId=\\"1\\"><w:lvl w:ilvl=\\"0\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"%1.\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"420\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr></w:lvl><w:lvl w:ilvl=\\"1\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"(%2)\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"840\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr></w:lvl><w:lvl w:ilvl=\\"2\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimalEnclosedCircle\\" /><w:lvlText w:val=\\"%3\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"1260\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr></w:lvl><w:lvl w:ilvl=\\"3\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"%4.\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"1680\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr></w:lvl><w:lvl w:ilvl=\\"4\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"(%5)\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"2100\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr></w:lvl><w:lvl w:ilvl=\\"5\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimalEnclosedCircle\\" /><w:lvlText w:val=\\"%6\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"2520\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr></w:lvl><w:lvl w:ilvl=\\"6\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"%7.\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"2940\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr></w:lvl><w:lvl w:ilvl=\\"7\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"(%8)\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"3360\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr></w:lvl><w:lvl w:ilvl=\\"8\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimalEnclosedCircle\\" /><w:lvlText w:val=\\"%9\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"3780\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr></w:lvl></w:abstractNum><w:num w:numId=\\"1\\">
<w:abstractNumId w:val=\\"1\\" />
</w:num></w:numbering>"
`;

View File

@ -52,4 +52,15 @@ describe("writer", () => {
} }
} }
}); });
test("should write page size", () => {
const p = new w.Paragraph().addRun(new w.Run().addText("Hello world!!"));
const buf = new w.Docx().addParagraph(p).pageSize(400, 800).build();
const z = new Zip(Buffer.from(buf));
for (const e of z.getEntries()) {
if (e.entryName.match(/document.xml|numbering.xml/)) {
expect(z.readAsText(e)).toMatchSnapshot();
}
}
});
}); });