Comments (15)
Welp, I circumvented the express packer by using a local packer and downloading that file.
Thanks anyway, awesome module you've created! Very neat. I was using Officegen but that one didn't have header/footer image support, many thanks for that.
:]
Here are some of the problems I encountered while using this module:
ExpressPacker.packPdf() isn't a function for some reason.
The Header error in ExpressPacker crashing Node after a successful download.
LocalPacker.packPdf does indeed pack a valid PDF, but it ignored image.scale changes in the PDF.
from docx.
That is not supported yet
Will add as a feature request
from docx.
It seems that I can make them fit to the margins by setting the cell width to something large like 20000.
I have another question, how can I anchor a picture to the top of a header/footer?
I can't seem to win against the margins at the top of the header/bottom of the footer.
Also, a funny thing, if I tried to insert a picture into the footer and the path to the file or the file has a space in its name, it corrupts the output for some reason. This occurs in the body and header/footer.
from docx.
It seems for my use case, I simply need the image in the header to be wrapped behind text and move to a specified location.
Is there anything that this module can do on that front?
from docx.
Do you mean fixed image positioning? And then placing that image behind the text?
If so, fixed positioning of images are coming soon! The code is there, just need to release
from docx.
Hi, thanks for being so helpful so far. This module is great.
I have one final small question.
My express packer is throwing out errors and when I call:
router.post('/', (req, res) => {
...
const express_exporter = new docx.ExpressPacker(doc, res);
express_exporter.pack('docx');
});
It works fine with a localpacker, but the express packer gives this error:
_http_outgoing.js:471
throw new ERR_HTTP_HEADERS_SENT('set');
^
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:471:11)
at ServerResponse.header
at ServerResponse.send
at ServerResponse.ExpressPacker.res.on
at ServerResponse.emit (events.js:187:15)
at emitCloseNT (_http_server.js:589:8)
at process._tickCallback (internal/process/next_tick.js:63:19)
The downloaded file says it's corrupted too.
Any ideas? Thanks.
from docx.
Also, it seems the PDFpacker ignores any picture scaling I've made.
from docx.
It looks like you are calling some express related stuff along with pack()
Are you calling res.send(), or res.end() by any chance?
from docx.
I'm not calling those at all.
Maybe because I'm using the version in npm but I'm not sure if that's even the issue.
Is the npm package outdated or something?
from docx.
Check out these RunKit examples I've got on the README, its all express, and it works like a charm
https://runkit.com/dolanmiu/docx-demo1
from docx.
Okay, I got the express packer spit out a download that is not corrupted but I still cannot seem to resolve that error regarding the set header.
I just can't seem to get rid of that error and try/catch doesn't seem to stop it from crashing the Node process.
To be more specific, this is what my router for the download looks like:
let script = require('../Report generator');
router.post("/download/docx/:id", (req, res) => {
console.log('-- Downloading DOCX...');
let report_json = results;
async function get_report() {
// Setting some json from post request
return await script.generate_report(report_json, res);
}
if (req.params && req.params.id) {
console.log("params.id: " + req.params.id);
if (req.body.generate_report && report_json) {
console.log("Report generation flag OK");
get_report().then((success) => {
if (success)
console.log("back in router, successful");
}
} else {
console.log("Generate report flag not set, invalid state.");
}
}
});
My report generation works, and it downloads a proper DOCX report, but the express packer seem to just kill the node process after download with the header bug:
_http_outgoing.js:471
throw new ERR_HTTP_HEADERS_SENT('set');
^
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:471:11)
at ServerResponse.header
at ServerResponse.send
at ServerResponse.ExpressPacker.res.on
at ServerResponse.emit (events.js:187:15)
at emitCloseNT (_http_server.js:589:8)
at process._tickCallback (internal/process/next_tick.js:63:19)
I also replaced my get index (router.get('/')) with your example line for line, and it does download a DOCX but it also faces the same header issue.
from docx.
Hmmm...
I think the header issue is because I called some next() and that causes it to call some middleware to call res.send or res.end somewhere.
Is it possible to not call res.end in the expresspacker?
Officegen had a streamer and I just set an attachment.
//Officegen's method
await docx.generate(res);
console.log("DOCX streamed to res.");
res.set({"Content-Type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", 'Content-disposition': 'attachment; filename=' + filename'});
from docx.
Good suggestion, will add in the major version of docx
and this would be breaking
from docx.
+1 for this feature request
from docx.
Fixed in #288
API will be like so:
https://github.com/dolanmiu/docx/blob/master/demo/demo32.ts#L59-L64
Will be released in v5
from docx.
Related Issues (20)
- How can I convert latex to Word format HOT 6
- Can open in libre, not in word. OOXML-Validator has a bunch of errors HOT 8
- Adding a validator HOT 4
- Patcher does not replace content in Footer HOT 2
- Repeat header in row HOT 1
- Attempted import error: 'Packer' is not exported from 'docx' (imported as 'Packer'). HOT 7
- Packer.toBuffer error in browser: nodebuffer not supported by this platform HOT 1
- Lists - instance not working with level greater than 0
- ExternalHyperlink renders empty line HOT 3
- tableHeader repeats row only if declared on the first row in a table
- el.elements not iterable when patching comments
- can not set indent by chars HOT 2
- Adding different numbering within the same line of paragraph HOT 12
- Field Codes in SimpleField Formulas HOT 1
- Corrupt Word document from patching with an XML attribute with an ampersand HOT 3
- After Patching, Following Text is Wrong Font Family HOT 1
- Possibility of adding hanging without affecting left indent of the paragraph.
- `PageNumber.TOTAL_PAGES_IN_SECTION` not documented and not functional, but within TS enum HOT 2
- Colors are not showing properly HOT 2
- When I open a document using WPS office, the width of the table cannot fill the entire page HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docx.