Coder Social home page Coder Social logo

Comments (17)

edi9999 avatar edi9999 commented on May 13, 2024

Will definitely add a test for this.

I am currently refactoring the imgReplacer class to see where the problem lies.

Here are some things I found about this problem:

  • it doesn't seem to behave the same way in the browser (it is not broken on FF)
  • a sneaky workaround is to save the images you don't want to be recognized as qrCodes in jpeg format (non PNG)

from docxtemplater.

edi9999 avatar edi9999 commented on May 13, 2024

hey,

just to tell you I think I wouldn't have the time to deal with it until next week, have a lot of contract work to do right now.

from docxtemplater.

edi9999 avatar edi9999 commented on May 13, 2024

Hi,

the error seems to be solved now (since v0.5.4). Please tell me if the error still occurs.

from docxtemplater.

zamentur avatar zamentur commented on May 13, 2024

Hi,
With node this correction doesn't work. When docxtemplater tries to find a qrcode into an image without qrcode, it fails with this message:
findpat.js:398
throw "Couldn't find enough finder patterns:"+startSize+" patterns found";

from docxtemplater.

edi9999 avatar edi9999 commented on May 13, 2024

Hi,

I have never seen this issue before. Can you please upload an example that
does this ?

Does this work in the browser but not in node, right ?

Also, are you up to date with the latest version ?

On 6 May 2014 16:46, "zamentur" [email protected] wrote:

Hi,
With node this correction doesn't work. When docxtemplater tries to find a
qrcode into an image without qrcode, it fails with this message:
findpat.js:398
throw "Couldn't find enough finder patterns:"+startSize+" patterns found";


Reply to this email directly or view it on GitHubhttps://github.com//issues/24#issuecomment-42311597
.

from docxtemplater.

zamentur avatar zamentur commented on May 13, 2024

I am up to date with the version 0.5.4 fdaa90e
I did not try in browser, but I tried with and without my png image. This png image doesn't contain any qrcode. With: it fails, without it works.

I have fix this problem with this code at line 58 in imgReplacer.coffee:

finished= (a) =>
    png.decoded= a
    try
        @qr[u]= new DocxQrCode(png,@xmlTemplater,imgName,@xmlTemplater.DocxGen.qrCodeNumCallBack)
        @qr[u].decode(@imageSetter)
    catch e
        mockedQrCode={xmlTemplater:@xmlTemplater,imgName:imgName,data:oldFile.asBinary()}
        @imageSetter(mockedQrCode)

from docxtemplater.

LitRidl avatar LitRidl commented on May 13, 2024

I have checked @zamentur's problem and successfully repeated it on my system.
Also I've replicated slightly different problem: qrCode + tagging are true and document contains both qr and non-qr png, which makes templater fail. I suggest to add this to test cases.

@zamentur's quick-fix works correctly and doesn't ruin any tests. Probably it's good idea to add it to the codebase (at least temporarily to get some time to think about better solution).

By the way, I am talking about node.js environment.

from docxtemplater.

edi9999 avatar edi9999 commented on May 13, 2024

@LitRidl I can't download your files on firefox nor chrome, can you upload them somewhere else ?

Update: Download all button did work !

from docxtemplater.

edi9999 avatar edi9999 commented on May 13, 2024

The fix of @zamentur doesn't solve the regression test I have just added to branch #24.1. I think those are two separate issues.

They is actually no error that is thrown by docxtemplater in the regression text. However, the generated file is 0 Byte, that's why the image doesn't show

from docxtemplater.

LitRidl avatar LitRidl commented on May 13, 2024

@edi9999, I see.
For my own code I use his pseudo-fix because for me it is far more important to have both qr and non-qr images in one file. Are there any better solutions rather than this try-Ok,insert-catch-Ok,preserve fix?

from docxtemplater.

edi9999 avatar edi9999 commented on May 13, 2024

Hi, I have added a fix for this, However I have not tested if it works because I have never encountered the issue my self. Basically I'm also doing a try catch but more close to the call of the qrcode library.

It's in the decode function of the DocxQrCode.coffee file:

    try
        if env=='browser'
            @qr.decode("data:image/png;base64,#{@base64Data}")
        else
            @qr.decode(@data,@data.decoded)
    catch
        @qr.result=null
        @qr.callback()

I think it should then do nothing with images where the qrcode library doesn't find enough patterns.

I haven't created a new version on npm too.

from docxtemplater.

LitRidl avatar LitRidl commented on May 13, 2024

Well, somehow it failed for me.

I think I have to give you kind of test for this situation: here I have file with both qr and non-qr image, config.json for it, expected output and real output.

outputReal.docx is obviously corrupt: non-qr images are just killed in it, but at least the file is opened.
outputExpected.docx is correct: it preserved both qr and non-qr images. I've got it by using zamentur's fix.

Actually there are two modes for pictures in document right now: all images either must be qr, or all of them must be non-qr. So, I think this case should be added to templater's test suite.

from docxtemplater.

LitRidl avatar LitRidl commented on May 13, 2024

By the way, in your fix you actually just ignore original image in case if it was qr-scanned?
It doesn't preserve original non-qr image, I've just tested.
The only thing that changed is that I see 'output' in console twice now, which is sign, that it executed callback. And that is all. Also, qr-callback is called only in catch. Is that Ok?

from docxtemplater.

edi9999 avatar edi9999 commented on May 13, 2024

Actually the @callback method should be called whether an exception is thrown or not. When no exception is thrown, it's the qrcodejs library that will wall the callback method: https://github.com/edi9999/docxtemplater/blob/master/vendor/jsqrcode/qrcode.js

from docxtemplater.

edi9999 avatar edi9999 commented on May 13, 2024

The branch I'm working in is bug-#24.2

from docxtemplater.

edi9999 avatar edi9999 commented on May 13, 2024

If you only use the command line interface, you could try to install this version: b8110b0

However, the bug is not still yet completely repaired because for now, the document is outputed two times (which is not the expected behavior)

from docxtemplater.

edi9999 avatar edi9999 commented on May 13, 2024

Fixed for good ! :-)

from docxtemplater.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.