parent
2d866193d0
commit
66a5e7c71a
|
@ -4,11 +4,11 @@ use std::fs::File;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let mut file = File::open("./#3276.docx").unwrap();
|
let mut file = File::open("./hello.docx").unwrap();
|
||||||
let mut buf = vec![];
|
let mut buf = vec![];
|
||||||
file.read_to_end(&mut buf).unwrap();
|
file.read_to_end(&mut buf).unwrap();
|
||||||
|
|
||||||
let mut file = File::create("./#3276.json").unwrap();
|
let mut file = File::create("./hello.json").unwrap();
|
||||||
let res = read_docx(&buf).unwrap().json();
|
let res = read_docx(&buf).unwrap().json();
|
||||||
file.write_all(res.as_bytes()).unwrap();
|
file.write_all(res.as_bytes()).unwrap();
|
||||||
file.flush().unwrap();
|
file.flush().unwrap();
|
||||||
|
|
|
@ -175,6 +175,7 @@ pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
|
||||||
let data = read_zip(&mut archive, "_rels/.rels")?;
|
let data = read_zip(&mut archive, "_rels/.rels")?;
|
||||||
Rels::from_xml(&data[..])?
|
Rels::from_xml(&data[..])?
|
||||||
};
|
};
|
||||||
|
|
||||||
// Finally, the minimum content for the Main Document part must be defined
|
// Finally, the minimum content for the Main Document part must be defined
|
||||||
// (physically located at /document.xml in the package):
|
// (physically located at /document.xml in the package):
|
||||||
let main_rel = rels
|
let main_rel = rels
|
||||||
|
@ -323,6 +324,7 @@ pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
|
||||||
docx.content_type = docx.content_type.add_footer();
|
docx.content_type = docx.content_type.add_footer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref f) = docx
|
if let Some(ref f) = docx
|
||||||
.document
|
.document
|
||||||
.section_property
|
.section_property
|
||||||
|
@ -406,13 +408,13 @@ pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
|
||||||
docx = docx.web_settings(web_settings);
|
docx = docx.web_settings(web_settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read media
|
// Read media
|
||||||
let media = rels.find_target_path(IMAGE_TYPE);
|
let media = rels.find_target_path(IMAGE_TYPE);
|
||||||
if let Some(paths) = media {
|
if let Some(paths) = media {
|
||||||
for (_, media) in paths {
|
for (_, media) in paths {
|
||||||
let data = read_zip(&mut archive, media.to_str().expect("should have media"))?;
|
if let Ok(data) = read_zip(&mut archive, media.to_str().expect("should have media")) {
|
||||||
docx = docx.add_image(data);
|
docx = docx.add_image(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(docx)
|
Ok(docx)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "docx-wasm",
|
"name": "docx-wasm",
|
||||||
"version": "0.0.253",
|
"version": "0.0.254",
|
||||||
"main": "dist/node/index.js",
|
"main": "dist/node/index.js",
|
||||||
"browser": "dist/web/index.js",
|
"browser": "dist/web/index.js",
|
||||||
"author": "bokuweb <bokuweb12@gmail.com>",
|
"author": "bokuweb <bokuweb12@gmail.com>",
|
||||||
|
|
Loading…
Reference in New Issue