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

Image over canvas in background #2709

Closed
Fanfong68 opened this issue Mar 22, 2024 · 1 comment
Closed

Image over canvas in background #2709

Fanfong68 opened this issue Mar 22, 2024 · 1 comment

Comments

@Fanfong68
Copy link

Fanfong68 commented Mar 22, 2024

Is it possible to use background canva and image together. I am going to generate a certificate, so i need a frame and a few rectangles as the background. Below is my code:

     background: function(currentPage, pageSize) {
        return {
            canvas: [
                {
                    type: 'rect',
                    x: pageSize.width * 0.42,
                    y: pageSize.height * 0.16,
                    w: pageSize.width * 0.08,
                    h: pageSize.height * 0.04,
                    lineColor: 'black',
                },
                {
                    type: 'rect',
                    x: pageSize.width * 0.84,
                    y: pageSize.height * 0.16,
                    w: pageSize.width * 0.08,
                    h: pageSize.height * 0.04,
                    lineColor: 'black',
                },
                {
                    type: 'rect',
                    x: pageSize.width * 0.64,
                    y: pageSize.height * 0.32,
                    w: pageSize.width * 0.28,
                    h: pageSize.height * 0.12,
                    lineColor: 'black',
                },
                {
                    image: 'sampleImage.jpg',
                    width: pageSize.width,
                    height: pageSize.height,
                    absolutePosition: { x: pageSize.width * 0.37, y: pageSize.height * 0.001 },
                    // opacity: 0.3,
                    // margin: [0, -120, 0, 0]
                }
            ]
            
        };
    },
@Fanfong68 Fanfong68 changed the title How to use background image and canva together Image over canvas in background Mar 22, 2024
@liborm85
Copy link
Collaborator

You can use stack, example:

var dd = {
	content: [
		'First paragraph',
		'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
	],
	     background: function(currentPage, pageSize) {
        return {
            stack: [
                {
                    image: 'sampleImage.jpg',
                    width: pageSize.width,
                    height: pageSize.height,
                    absolutePosition: { x: pageSize.width * 0.37, y: pageSize.height * 0.001 },
                    // opacity: 0.3,
                    // margin: [0, -120, 0, 0]
                },
                {
            canvas: [
                {
                    type: 'rect',
                    x: pageSize.width * 0.42,
                    y: pageSize.height * 0.16,
                    w: pageSize.width * 0.08,
                    h: pageSize.height * 0.04,
                    lineColor: 'black',
                },
                {
                    type: 'rect',
                    x: pageSize.width * 0.84,
                    y: pageSize.height * 0.16,
                    w: pageSize.width * 0.08,
                    h: pageSize.height * 0.04,
                    lineColor: 'black',
                },
                {
                    type: 'rect',
                    x: pageSize.width * 0.64,
                    y: pageSize.height * 0.32,
                    w: pageSize.width * 0.28,
                    h: pageSize.height * 0.12,
                    lineColor: 'black',
                },
            ]
        }]
            
        };
    },
	
}

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

2 participants