pdfmake icon indicating copy to clipboard operation
pdfmake copied to clipboard

Image shifted

Open andreadompe opened this issue 11 years ago • 6 comments

Hi all! I've already red other issues but i didn't find a solution, this is my problem: i've copied the playground images example and after the PDF creation on the browser everything is ok but if i open the pdf file all the images are shifted to the right...

I've already tried with jpg, png but the result is the same, also switching from Windows 7 to iOS.

How can i fix this?

Greeting

Andrea

andreadompe avatar Jul 10 '15 13:07 andreadompe

No one has the same problem???

andreadompe avatar Jul 17 '15 12:07 andreadompe

I just tested and I have the same problem as you. All the images get shifted to the right when you reopen the pdfs.

gabucito avatar Jul 20 '15 15:07 gabucito

I took a quick look at the files and it seems that this line in elementWriter.js is what is causing the problem:

image.x = context.x + (image.x || 0);

I am taking a guess but it seems the value for image.x do not get resetted when you reopen the pdf which causes the problem.

If you are not setting an initial position then changing the above line to:

image.x = context.x;

might help.

This might break your initial positioning, if you set one, for the images so beware. Hopefully one of the devs will take a look into this soon.

gabucito avatar Jul 20 '15 16:07 gabucito

Now it works perfectly! Thanks gabucito!

andreadompe avatar Jul 29 '15 09:07 andreadompe

Another solution I've found is to redefine your docDefinition every time you generate the PDF. In other words, structure it like

var savePDF = function(){
    var docDefinition = {...};
    pdfMake.createPdf(docDefinition);
}

and call savePDF() every time. @Elyahou has a cleaner solution at #376 but I figured this may help someone.

By the way, this issue has been duplicated multiple times: #389, #446, #592

EpicWolverine avatar Aug 12 '16 19:08 EpicWolverine

Fix is included in the new version (0.1.22).

liborm85 avatar Dec 23 '16 12:12 liborm85