Progress on embeddding image

This commit is contained in:
Dolan
2018-01-16 00:43:00 +00:00
parent 392db1cd11
commit f7c2072cff
12 changed files with 76 additions and 13 deletions

View File

@ -2,8 +2,10 @@ const docx = require('../build');
var doc = new docx.File();
const image = doc.createImage("./demo/penguins.jpg");
var paragraph = new docx.Paragraph("Hello World");
doc.addParagraph(paragraph);
const image = doc.createImage("./demo/image1.jpeg");
var exporter = new docx.LocalPacker(doc);
exporter.pack('My Document');

View File

Before

Width:  |  Height:  |  Size: 162 KiB

After

Width:  |  Height:  |  Size: 162 KiB

View File

@ -32,7 +32,7 @@ export class Compiler {
cwd: TEMPLATE_PATH,
});
const xmlDocument = xml(this.formatter.format(this.file.Document));
const xmlDocument = xml(this.formatter.format(this.file.Document), true);
const xmlStyles = xml(this.formatter.format(this.file.Styles));
const xmlProperties = xml(this.formatter.format(this.file.Properties), {
declaration: {

View File

@ -0,0 +1,11 @@
import { XmlAttributeComponent } from "file/xml-components";
export interface IGraphicDataAttributes {
uri?: string;
}
export class GraphicDataAttributes extends XmlAttributeComponent<IGraphicDataAttributes> {
protected xmlKeys = {
uri: "uri",
};
}

View File

@ -0,0 +1,16 @@
import { XmlComponent } from "file/xml-components";
import { GraphicDataAttributes } from "./graphic-data-attribute";
import { Pic } from "./pic";
export class GraphicData extends XmlComponent {
constructor(referenceId: number) {
super("a:graphicData");
this.root.push(new GraphicDataAttributes({
uri: "http://schemas.openxmlformats.org/drawingml/2006/picture",
}));
this.root.push(new Pic(referenceId));
}
}

View File

@ -1,10 +1 @@
import { XmlComponent } from "file/xml-components";
import { Pic } from "./pic";
export class GraphicData extends XmlComponent {
constructor(referenceId: number) {
super("a:graphicData");
this.root.push(new Pic(referenceId));
}
}
export * from "./graphic-data";

View File

@ -2,11 +2,13 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
interface IBlipProperties {
embed: string;
cstate: string;
}
class BlipAttributes extends XmlAttributeComponent<IBlipProperties> {
protected xmlKeys = {
embed: "r:embed",
cstate: "cstate",
};
}
@ -16,6 +18,7 @@ export class Blip extends XmlComponent {
super("a:blip");
this.root.push(new BlipAttributes({
embed: `rId${referenceId}`,
cstate: "none",
}));
}
}

View File

@ -0,0 +1,11 @@
import { XmlAttributeComponent } from "file/xml-components";
export interface IPicAttributes {
xmlns?: string;
}
export class PicAttributes extends XmlAttributeComponent<IPicAttributes> {
protected xmlKeys = {
xmlns: "xmlns:pic",
};
}

View File

@ -2,13 +2,16 @@
import { XmlComponent } from "file/xml-components";
import { BlipFill } from "./blip/blip-fill";
import { NonVisualPicProperties } from "./non-visual-pic-properties/non-visual-pic-properties";
import { PicAttributes } from "./pic-attributes";
import { ShapeProperties } from "./shape-properties/shape-properties";
export class Pic extends XmlComponent {
constructor(referenceId: number) {
super("pic:pic");
this.root.push(new PicAttributes({
xmlns: "http://schemas.openxmlformats.org/drawingml/2006/picture",
}));
this.root.push(new NonVisualPicProperties());
this.root.push(new BlipFill(referenceId));
this.root.push(new ShapeProperties());

View File

@ -0,0 +1,17 @@
import { XmlAttributeComponent } from "file/xml-components";
export interface IInlineAttributes {
distT?: number;
distB?: number;
distL?: number;
distR?: number;
}
export class InlineAttributes extends XmlAttributeComponent<IInlineAttributes> {
protected xmlKeys = {
distT: "distT",
distB: "distB",
distL: "distL",
distR: "distR",
};
}

View File

@ -1,12 +1,20 @@
import { XmlComponent } from "file/xml-components";
import { Graphic } from "./graphic";
import { GraphicFrameProperties } from "./graphic-frame/graphic-frame-properties";
import { InlineAttributes } from "./inline-attributes";
export class Inline extends XmlComponent {
constructor(referenceId: number) {
super("wp:inline");
this.root.push(new InlineAttributes({
distT: 0,
distB: 0,
distL: 0,
distR: 0,
}));
this.root.push(new GraphicFrameProperties());
this.root.push(new Graphic(referenceId));
}

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="jpeg" ContentType="image/jpeg"/>
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
<Default Extension="xml" ContentType="application/xml" />
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" />