I am learning PDFkit I am playing with a demo now I want to create a rectangle with text inside which looks like a material UI texfield.
The Expected results:
So far here is what I have.
var doc = new PDFDocument();
var stream = doc.pipe(blobStream());
doc.rect(45, 165, 240, 22).fillAndStroke('#ddd', '#000');
doc.fill('#F00').stroke();
doc.fontSize(16);
doc.text("Sample text", 50, 170, {lineBreak: false} );
doc.end();
stream.on('finish', function() {
iframe.src = stream.toBlobURL('application/pdf');
});
You can run the example above here. : live demo
What do I need to add here to get what I want? any suggestion will be appreciated.
UPDATE I am struggling to remove the line where there is top text as image shows below .


Building PDF with a fixed set of objects can be a challenge.
Normally using primitives a line would be drawn around the desired area but with a gap left before fill.
Using PDFKit you may need to adapt as graphics workarounds thus adapting the example above, in comments I suggested simply add a background to the text as emulated here.
you could make the white box smaller/higher so it only clips the edge of the grey area here I reduced size to 11.1 (can be any suited value) but its a flaky setting and for the text confusing as two background colours.
The better solution is to use the same background colour
Or fancy