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 jsmain
parent
3329543c56
commit
8e7ddbca70
|
@ -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(())
|
||||
}
|
|
@ -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(())
|
||||
}
|
|
@ -97,6 +97,21 @@ impl Document {
|
|||
.push(DocumentChild::BookmarkEnd(BookmarkEnd::new(id)));
|
||||
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 {
|
||||
|
|
|
@ -1,20 +1,7 @@
|
|||
use crate::documents::BuildXML;
|
||||
use crate::types::PageMargin;
|
||||
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.
|
||||
// <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 {
|
||||
|
@ -36,27 +23,31 @@ impl PageMargin {
|
|||
Default::default()
|
||||
}
|
||||
|
||||
pub fn top(self, v: usize) -> PageMargin {
|
||||
pub fn top(self, v: u32) -> PageMargin {
|
||||
PageMargin { top: v, ..self }
|
||||
}
|
||||
|
||||
pub fn left(self, v: usize) -> PageMargin {
|
||||
pub fn left(self, v: u32) -> PageMargin {
|
||||
PageMargin { left: v, ..self }
|
||||
}
|
||||
|
||||
pub fn bottom(self, v: usize) -> PageMargin {
|
||||
pub fn bottom(self, v: u32) -> PageMargin {
|
||||
PageMargin { bottom: v, ..self }
|
||||
}
|
||||
|
||||
pub fn right(self, v: usize) -> PageMargin {
|
||||
pub fn right(self, v: u32) -> PageMargin {
|
||||
PageMargin { right: v, ..self }
|
||||
}
|
||||
|
||||
pub fn header(self, v: usize) -> PageMargin {
|
||||
pub fn header(self, v: u32) -> PageMargin {
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ use serde::Serialize;
|
|||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PageSize {
|
||||
w: usize,
|
||||
h: usize,
|
||||
w: u32,
|
||||
h: u32,
|
||||
}
|
||||
|
||||
// These values were based on microsoft office word2019 windows edition.
|
||||
|
@ -23,9 +23,19 @@ impl PageSize {
|
|||
Default::default()
|
||||
}
|
||||
|
||||
pub fn size(self, w: usize, h: usize) -> PageSize {
|
||||
pub fn size(self, w: u32, h: u32) -> PageSize {
|
||||
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 {
|
||||
|
|
|
@ -20,6 +20,16 @@ impl SectionProperty {
|
|||
pub fn new() -> SectionProperty {
|
||||
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 {
|
||||
|
|
|
@ -199,6 +199,16 @@ impl Docx {
|
|||
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 {
|
||||
self.update_comments();
|
||||
let (image_ids, images) = self.create_images();
|
||||
|
|
|
@ -38,6 +38,11 @@ impl FromXML for Document {
|
|||
doc = doc.add_bookmark_end(e.id);
|
||||
continue;
|
||||
}
|
||||
XMLElement::SectionProperty => {
|
||||
let e = SectionProperty::read(&mut parser, &attributes)?;
|
||||
doc = doc.default_section_property(e);
|
||||
continue;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ mod read_zip;
|
|||
mod rels;
|
||||
mod run;
|
||||
mod run_property;
|
||||
mod section_property;
|
||||
mod settings;
|
||||
mod style;
|
||||
mod styles;
|
||||
|
|
|
@ -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),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -99,6 +99,9 @@ pub enum XMLElement {
|
|||
TxbxContent,
|
||||
Pict,
|
||||
DocId,
|
||||
SectionProperty,
|
||||
PageSize,
|
||||
PageMargin,
|
||||
Unsupported,
|
||||
}
|
||||
|
||||
|
@ -250,6 +253,9 @@ impl FromStr for XMLElement {
|
|||
"lvlOverride" => Ok(XMLElement::LvlOverride),
|
||||
"startOverride" => Ok(XMLElement::StartOverride),
|
||||
"docId" => Ok(XMLElement::DocId),
|
||||
"sectPr" => Ok(XMLElement::SectionProperty),
|
||||
"pgSz" => Ok(XMLElement::PageSize),
|
||||
"pgMar" => Ok(XMLElement::PageMargin),
|
||||
_ => Ok(XMLElement::Unsupported),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ pub mod emu;
|
|||
pub mod errors;
|
||||
pub mod font_pitch_type;
|
||||
pub mod level_suffix_type;
|
||||
pub mod page_margin;
|
||||
pub mod section_type;
|
||||
pub mod special_indent_type;
|
||||
pub mod style_type;
|
||||
|
@ -22,6 +23,7 @@ pub use emu::*;
|
|||
pub use errors::*;
|
||||
pub use font_pitch_type::*;
|
||||
pub use level_suffix_type::*;
|
||||
pub use page_margin::*;
|
||||
pub use section_type::*;
|
||||
pub use special_indent_type::*;
|
||||
pub use style_type::*;
|
||||
|
|
|
@ -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
|
@ -16,6 +16,7 @@ import { Numbering } from "./numbering";
|
|||
import { BookmarkStart } from "./bookmark-start";
|
||||
import { BookmarkEnd } from "./bookmark-end";
|
||||
import { Settings } from "./settings";
|
||||
import { SectionProperty, PageMargin } from "./section-property";
|
||||
import { DocxJSON } from "./json";
|
||||
|
||||
import * as wasm from "./pkg";
|
||||
|
@ -53,6 +54,7 @@ export class Docx {
|
|||
abstractNumberings: AbstractNumbering[] = [];
|
||||
numberings: Numbering[] = [];
|
||||
settings: Settings = new Settings();
|
||||
sectionProperty: SectionProperty = new SectionProperty();
|
||||
|
||||
addParagraph(p: Paragraph) {
|
||||
if (p.hasNumberings) {
|
||||
|
@ -95,6 +97,16 @@ export class Docx {
|
|||
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) {
|
||||
let run = wasm.createRun();
|
||||
r.children.forEach((child) => {
|
||||
|
@ -532,6 +544,32 @@ export class Docx {
|
|||
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);
|
||||
docx.free();
|
||||
return buf;
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
};
|
|
@ -48,6 +48,16 @@ impl Docx {
|
|||
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> {
|
||||
let buf = Vec::new();
|
||||
let mut cur = std::io::Cursor::new(buf);
|
||||
|
|
|
@ -1790,13 +1790,13 @@ Object {
|
|||
"id": "rId4",
|
||||
},
|
||||
"pageMargin": Object {
|
||||
"bottom": 1701,
|
||||
"bottom": 600,
|
||||
"footer": 992,
|
||||
"gutter": 0,
|
||||
"header": 851,
|
||||
"left": 1701,
|
||||
"right": 1701,
|
||||
"top": 1985,
|
||||
"right": 1400,
|
||||
"top": 1700,
|
||||
},
|
||||
"pageSize": Object {
|
||||
"h": 16838,
|
||||
|
@ -2373,8 +2373,8 @@ Object {
|
|||
"top": 1985,
|
||||
},
|
||||
"pageSize": Object {
|
||||
"h": 16838,
|
||||
"w": 11906,
|
||||
"h": 16840,
|
||||
"w": 11900,
|
||||
},
|
||||
"sectionType": null,
|
||||
},
|
||||
|
@ -3729,3 +3729,30 @@ exports[`writer should write lvlOverride with level 3`] = `
|
|||
</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>"
|
||||
`;
|
||||
|
||||
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>"
|
||||
`;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue