Closed akalittle closed 5 years ago
This is caused by the font. After i set
{font:pdfWriter.getFontForFile(__dirname + '/mydirectory/fonts/Couri.ttf'),size:14,colorspace:'gray',color:0x00}
It worked!
But i found another issus that
let pdfWriter = hummus.createWriterToModify(
new hummus.PDFRStreamForBuffer(buffer),
new hummus.PDFStreamForResponse(outStreamT)
);
let pageModifier = new hummus.PDFPageModifier(pdfWriter, 0);
var imageOptions = {
transformation: [0.5, 0, 0, 0.5, 0, 0],
index: 1000
};
pageModifier
.startContext()
.getContext()
// .drawRectangle(0, 0, 100, 40, pathFillOptions)
// parameters top left /filepath
.drawImage(100, 800, __dirname + '/png/transfer.png', imageOptions);
pageModifier.endContext().writePage();
pdfWriter.end();
It confuses that the params in imageOptions. I have no idea of transformation array. What do the each params means?
and after i use .drawImage()
I know from the wiki the first two params are the location.
However i tried. When i set the param more than about 850 the image will lost.
This is an example.
If i set the first two params of drawImage()
bigger. The image will cant be seen
https://github.com/galkahana/HummusJS/wiki/Show-images#simple-image-drawing
maybe you can try with the object instead
{
transformation: {
width:100,
height:100,
proportional:true
}
}
@chunyenHuang
Thanks~
I tried with the object instead, it still doesnt work.
However, i tried to clone your hummusRecipe
and do some change.
To support new HummusRecipe(buffer)
receive buffer;
And the result return is also buffer. Below is usage.
Wondering if i could create a pr to ur repo.
const pdfDoc = new HummusRecipe(buffer);
const result = pdfDoc
.editPage(5)
.image('./png/google.png', 100, 230, {
width: 100,
keepAspectRatio: true,
opacity: 0.7
})
.endPage()
.endPDF();
PR is welcome, but I think your issue should be able to be resolved by the HummusJS. My repo is just a wrapper on top of HummusJS.
Description
I tried to modify an existing pdf from buffer. With my code below, i can get another pdf file
./result.pdf
just the same as origin one.