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

switchToPage not working #1404

Open
hani647 opened this issue Nov 27, 2022 · 2 comments
Open

switchToPage not working #1404

hani647 opened this issue Nov 27, 2022 · 2 comments

Comments

@hani647
Copy link

hani647 commented Nov 27, 2022

Bug Report

I've a document that shows content in 2 columns so now 1 column size has increased which caused new page to be added but when I'm trying to use doc.switchToPage(0) and doc.text(...) its not working. Even on playground its not working.

Description of the problem

I've a document that shows content in 2 columns so now 1 column size has increased which caused new page to be added but when I'm trying to use doc.switchToPage(0) and doc.text(...) its not working. Even on playground its not working.

Code sample

`// create a document and pipe to a blob
var doc = new PDFDocument();
var stream = doc.pipe(blobStream());

// draw some text
doc.fontSize(25).text('Here is some vector graphics...', 100, 80);

// some vector graphics
doc
.save()
.moveTo(100, 150)
.lineTo(100, 250)
.lineTo(200, 250)
.fill('#FF3300');

doc.circle(280, 200, 50).fill('#6600FF');

// an SVG path
doc
.scale(0.6)
.translate(470, 130)
.path('M 250,75 L 323,301 131,161 369,161 177,301 z')
.fill('red', 'even-odd')
.restore();

doc.addPage();
doc.addPage();
doc.switchToPage(0);
// and some justified text wrapped into columns
doc
.text('And here is some wrapped text...', 100, 300)
.font('Times-Roman', 13)
.moveDown()
.text(lorem, {
width: 412,
align: 'justify',
indent: 30,
columns: 2,
height: 300,
ellipsis: true
});

// end and display the document in the iframe to the right
doc.end();
stream.on('finish', function() {
iframe.src = stream.toBlobURL('application/pdf');
});`

Your environment

  • pdfkit version:
  • Node version:
  • Browser version (if applicable):
  • Operating System:
@rohinthr
Copy link

rohinthr commented Feb 28, 2023

Try var doc = new PDFDocument({bufferPages: true}). Bufferpages enable the option to switch pages.

@doublepithre
Copy link

doublepithre commented Jun 16, 2023

Related issue,
Let's say we are creating pdf pages with 2 columns. Once the pdf left side column is overflown it creates a new page when all the left side content (suppose 2 pages), we try to switch to the first page this works if we set the bufferPages: true but when first page right side content is full, the text will be written to 3 page instead of 2nd page
Attaching the text that can be used playground to see the issue
pdfplay.txt

After looking at the issues, noticed #1201 should fix but not sure why it's not working

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