Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes when generating barcode with SVG output #96

Closed
hatsantos opened this issue Apr 13, 2022 · 1 comment
Closed

App crashes when generating barcode with SVG output #96

hatsantos opened this issue Apr 13, 2022 · 1 comment

Comments

@hatsantos
Copy link

hatsantos commented Apr 13, 2022

I have a script in nodejs to generate some PDF files. Each page must have a barcode, so I'm using symbology to generate the barcode in the SVG format and add it to each PDF page.

This is working ok, so far, but now I had to generate a large number of pages.

I need to run 3000 times, but the app crashes every time at iteration 509/510.
I isolated the code and simply running the function that returns the barcode SVG string make the app crash.

This seems to happen if the output is SVG. If the output is set to PNG the app runs all the iterations that I tested (1000 / 2000 and 3000).

/**
 * Returns an SVG string of a CODE39 barcode.
 * @param value string: barcode value.
 * @returns 
 */
const getBarCode = async (value:string):Promise<string> =>
{
    try 
    {
        const { data } = await createStream
        (
            { 
                symbology: SymbologyType.CODE39, 
                showHumanReadableText: true,
                height: 190, 
                scale: 1
            },
            value,
            OutputType.SVG
        );
    
        return data; 
    } 
    catch (error) 
    {
        throw error;
    }
}

/**
 * Render a number of pages corresponding to totalPages number.
 * @param totalPages: number total pages to render
 */
const generatePages = async (totalPages:number) => 
{
    console.time('Time Rendering');

    try 
    {
        const pages = [...Array(totalPages).keys()].map(page => (page + 1).toString().padStart(4, '0'));
        
        for (const [index, value] of pages.entries()) 
        {
            console.log('Barcode to page: ', value);
            await getBarCode(value);
        }

        console.timeEnd('Time Rendering');
    } 
    catch (error) 
    {
        throw error;
    }
}

//Starts to generate n pages
generatePages(1000);

I'm using node v16.14.0 and the latest version of this lib: v3.0.8

@HitomiTenshi
Copy link

I just encountered the same problem with node v16.16.0 and the latest version of this lib: v3.0.8. Using PNG output instead of SVG output solves the crash.

jshor added a commit that referenced this issue Nov 27, 2022
This changes the output of EPS and SVG data to write to a string buffer
instead of a file buffer. This fixes the issue where the binary would
crash after a substantial number of iterations.
jshor added a commit that referenced this issue Nov 27, 2022
This changes the output of EPS and SVG data to write to a string buffer
instead of a file buffer. This fixes the issue where the binary would
crash after a substantial number of iterations.
jshor added a commit that referenced this issue Nov 27, 2022
This changes the output of EPS and SVG data to write to a string buffer
instead of a file buffer. This fixes the issue where the binary would
crash after a substantial number of iterations.
@jshor jshor closed this as completed Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants