pdf-export: remove option to export to pdf
This commit is contained in:
@ -43,11 +43,8 @@
|
|||||||
"@types/archiver": "^2.1.0",
|
"@types/archiver": "^2.1.0",
|
||||||
"@types/express": "^4.0.35",
|
"@types/express": "^4.0.35",
|
||||||
"@types/image-size": "0.0.29",
|
"@types/image-size": "0.0.29",
|
||||||
"@types/request-promise": "^4.1.41",
|
|
||||||
"archiver": "^2.1.1",
|
"archiver": "^2.1.1",
|
||||||
"image-size": "^0.6.2",
|
"image-size": "^0.6.2",
|
||||||
"request": "^2.83.0",
|
|
||||||
"request-promise": "^4.2.2",
|
|
||||||
"xml": "^1.0.1"
|
"xml": "^1.0.1"
|
||||||
},
|
},
|
||||||
"author": "Igor Bulovski",
|
"author": "Igor Bulovski",
|
||||||
|
@ -30,13 +30,4 @@ describe("LocalPacker", () => {
|
|||||||
fs.statSync("build/tests/test.docx");
|
fs.statSync("build/tests/test.docx");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#packPdf", () => {
|
|
||||||
it("should create a standard PDF file", async function() {
|
|
||||||
this.timeout(99999999);
|
|
||||||
|
|
||||||
await packer.packPdf("build/tests/pdf-test");
|
|
||||||
fs.statSync("build/tests/pdf-test.pdf");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
@ -1,19 +1,14 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as os from "os";
|
|
||||||
import * as path from "path";
|
|
||||||
|
|
||||||
import { File } from "../../file";
|
import { File } from "../../file";
|
||||||
import { Compiler } from "./compiler";
|
import { Compiler } from "./compiler";
|
||||||
import { IPacker } from "./packer";
|
import { IPacker } from "./packer";
|
||||||
import { PdfConvertWrapper } from "./pdf-convert-wrapper";
|
|
||||||
|
|
||||||
export class LocalPacker implements IPacker {
|
export class LocalPacker implements IPacker {
|
||||||
private stream: fs.WriteStream;
|
private stream: fs.WriteStream;
|
||||||
private readonly pdfConverter: PdfConvertWrapper;
|
|
||||||
private readonly packer: Compiler;
|
private readonly packer: Compiler;
|
||||||
|
|
||||||
constructor(file: File) {
|
constructor(file: File) {
|
||||||
this.pdfConverter = new PdfConvertWrapper();
|
|
||||||
this.packer = new Compiler(file);
|
this.packer = new Compiler(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,25 +18,4 @@ export class LocalPacker implements IPacker {
|
|||||||
this.stream = fs.createWriteStream(`${filePath}.docx`);
|
this.stream = fs.createWriteStream(`${filePath}.docx`);
|
||||||
await this.packer.compile(this.stream);
|
await this.packer.compile(this.stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async packPdf(filePath: string): Promise<void> {
|
|
||||||
filePath = filePath.replace(/.pdf$/, "");
|
|
||||||
|
|
||||||
const fileName = path.basename(filePath, path.extname(filePath));
|
|
||||||
const tempPath = path.join(os.tmpdir(), `${fileName}.docx`);
|
|
||||||
this.stream = fs.createWriteStream(tempPath);
|
|
||||||
await this.packer.compile(this.stream);
|
|
||||||
const text = await this.pdfConverter.convert(tempPath);
|
|
||||||
// const writeFile = util.promisify(fs.writeFile); --use this in future, in 3 years time. Only in node 8
|
|
||||||
// return writeFile(`${filePath}.pdf`, text);
|
|
||||||
return new Promise<void>((resolve, reject) => {
|
|
||||||
fs.writeFile(`${filePath}.pdf`, text, (err) => {
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
/* tslint:disable:object-literal-key-quotes */
|
|
||||||
// This tslint disable is needed, or it simply won't work
|
|
||||||
import * as fs from "fs";
|
|
||||||
import * as request from "request-promise";
|
|
||||||
|
|
||||||
export interface IConvertOutput {
|
|
||||||
data: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class PdfConvertWrapper {
|
|
||||||
public convert(filePath: string): request.RequestPromise {
|
|
||||||
return request.post({
|
|
||||||
url: "http://mirror1.convertonlinefree.com",
|
|
||||||
encoding: null,
|
|
||||||
headers: {
|
|
||||||
"User-Agent":
|
|
||||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36",
|
|
||||||
},
|
|
||||||
formData: {
|
|
||||||
__EVENTTARGET: "",
|
|
||||||
__EVENTARGUMENT: "",
|
|
||||||
__VIEWSTATE: "",
|
|
||||||
ctl00$MainContent$fu: {
|
|
||||||
value: fs.readFileSync(filePath),
|
|
||||||
options: {
|
|
||||||
filename: "output.docx",
|
|
||||||
contentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
ctl00$MainContent$btnConvert: "Convert",
|
|
||||||
ctl00$MainContent$fuZip: "",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user