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

Bullet number on version 0.15.0 not work #1517

Closed
thuskin opened this issue May 11, 2024 · 3 comments · Fixed by #1568
Closed

Bullet number on version 0.15.0 not work #1517

thuskin opened this issue May 11, 2024 · 3 comments · Fixed by #1568
Assignees

Comments

@thuskin
Copy link

thuskin commented May 11, 2024

Bug Report

Bullet number on version 0.15.0 not work

Description of the problem

Bullet number on version 0.15.0 not work. Then I returned to version 0.14.0. It works well

Code sample

doc.list([
"A",
"B"
], {listType: "numbered", indent: 20, bulletIndent:20, textIndent:20, align: "left"});

Your environment

  • pdfkit version: 0.15.0
  • Node version:
  • Browser version (if applicable):
  • Operating System:
@blikblum blikblum self-assigned this May 17, 2024
@nstdspace
Copy link

I do not know what @thuskin means with "not work", but I can confirm that there is a problem with that function.

pdf.list(["A", "B", "C"], { listType: "numbered" });

creates a list with each item prefixed with "1.", instead of "1.", "2." and "3." as expected.
I did not dig too deep, but in this function "i" seems to be always 0.

@hugo-t-b
Copy link

I also ran into this problem. I solved it by editing the module locally so that it passes i to the drawListItem function on this line. Then I used pnpm patch so I didn't have to downgrade.

This fix works for my (simple) use case but I haven't tested it much or using customized options, but I'm happy to submit a PR. Here's the diff for my patch:

@@ -3359,11 +3359,10 @@ var TextMixin = {
           return `${text}.`;
       }
     };
-    const drawListItem = function (listItem) {
+    const drawListItem = function (listItem, i) {
       wrapper = new LineWrapper(this, options);
       wrapper.on('line', this._line);
       level = 1;
-      let i = 0;
       wrapper.once('firstLine', () => {
         let item, itemType, labelType, bodyType;
         if (options.structParent) {
@@ -3420,7 +3419,7 @@ var TextMixin = {
       wrapper.wrap(listItem, options);
     };
     for (let i = 0; i < items.length; i++) {
-      drawListItem.call(this, items[i]);
+      drawListItem.call(this, items[i], i);
     }
     return this;
   },

filecage added a commit to filecage/pdfkit that referenced this issue Nov 27, 2024
filecage added a commit to filecage/pdfkit that referenced this issue Nov 27, 2024
@filecage filecage mentioned this issue Nov 27, 2024
4 tasks
@filecage
Copy link
Contributor

Thanks @hugo-t-b, I have created PR #1568 that incorporates your suggested fix.

liborm85 pushed a commit that referenced this issue Dec 14, 2024
* adds test cases for ordered lists

* fixes broken labels for ordered lists (#1517)

* adds test for sub-lists (ordered and unordered)

* update changelog for fix of #1517

---------

Co-authored-by: David <filecage@users.noreply.github.com>
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

Successfully merging a pull request may close this issue.

5 participants