Fix referenceId +1 error and spelling mistakes
Add demo
This commit is contained in:
@ -38,8 +38,8 @@ export class File {
|
||||
this.numbering = new Numbering();
|
||||
this.relationships = new Relationships();
|
||||
this.media = new Media();
|
||||
this.header = new Header();
|
||||
this.footer = new Footer();
|
||||
this.header = new Header(this.media, this.relationships);
|
||||
this.footer = new Footer(this.media, this.relationships);
|
||||
}
|
||||
|
||||
public addParagraph(paragraph: Paragraph): void {
|
||||
|
@ -1,12 +1,13 @@
|
||||
// http://officeopenxml.com/WPfooters.php
|
||||
import { IMediaData } from "file/media";
|
||||
import { IMediaData, Media } from "file/media";
|
||||
import { Relationships } from "file/relationships";
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { Paragraph, PictureRun } from "../paragraph";
|
||||
import { Table } from "../table";
|
||||
import { FooterAttributes } from "./footer-attributes";
|
||||
|
||||
export class Footer extends XmlComponent {
|
||||
constructor() {
|
||||
constructor(private readonly media: Media, private readonly relationships: Relationships) {
|
||||
super("w:ftr");
|
||||
this.root.push(
|
||||
new FooterAttributes({
|
||||
@ -58,9 +59,13 @@ export class Footer extends XmlComponent {
|
||||
this.root.push(paragraph);
|
||||
}
|
||||
|
||||
public createDrawing(imageData: IMediaData): void {
|
||||
this.addDrawing(imageData);
|
||||
|
||||
return;
|
||||
public createImage(image: string): void {
|
||||
const mediaData = this.media.addMedia(image, this.relationships.RelationshipCount);
|
||||
this.relationships.createRelationship(
|
||||
mediaData.referenceId,
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
`media/${mediaData.fileName}`,
|
||||
);
|
||||
this.addDrawing(mediaData);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
// http://officeopenxml.com/WPheaders.php
|
||||
import { IMediaData } from "file/media";
|
||||
import { IMediaData, Media } from "file/media";
|
||||
import { Relationships } from "file/relationships";
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { Paragraph, PictureRun } from "../paragraph";
|
||||
import { Table } from "../table";
|
||||
import { HeaderAttributes } from "./header-attributes";
|
||||
|
||||
export class Header extends XmlComponent {
|
||||
constructor() {
|
||||
constructor(private readonly media: Media, private readonly relationships: Relationships) {
|
||||
super("w:hdr");
|
||||
this.root.push(
|
||||
new HeaderAttributes({
|
||||
@ -58,9 +59,13 @@ export class Header extends XmlComponent {
|
||||
this.root.push(paragraph);
|
||||
}
|
||||
|
||||
public createDrawing(imageData: IMediaData): void {
|
||||
this.addDrawing(imageData);
|
||||
|
||||
return;
|
||||
public createImage(image: string): void {
|
||||
const mediaData = this.media.addMedia(image, this.relationships.RelationshipCount);
|
||||
this.relationships.createRelationship(
|
||||
mediaData.referenceId,
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
`media/${mediaData.fileName}`,
|
||||
);
|
||||
this.addDrawing(mediaData);
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ export class Media {
|
||||
const dimensions = sizeOf(filePath);
|
||||
|
||||
const imageData = {
|
||||
referenceId: this.map.size + relationshipsCount,
|
||||
referenceId: this.map.size + relationshipsCount + 1,
|
||||
stream: fs.createReadStream(filePath),
|
||||
path: filePath,
|
||||
fileName: key,
|
||||
|
Reference in New Issue
Block a user