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

Long address texts are overlapped on invoice/creditmemo pdf #107

Open
HirokazuNishi opened this issue Jan 28, 2020 · 5 comments
Open

Long address texts are overlapped on invoice/creditmemo pdf #107

HirokazuNishi opened this issue Jan 28, 2020 · 5 comments

Comments

@HirokazuNishi
Copy link
Collaborator

Preconditions

  1. Install Magento2.3.4 with sample data.
  2. Install CommunityEngineering_ConfigurablePdfFont.
  3. Create customer account with long address text data.
  4. Create order.
  5. Create invoice.

Expected result

  • Invoice pdf generated without any broken layout.

correct-pdf

Actual result

  • Invoice pdf generated with broken layout. Cannot read customer address.

incorrect-pdf

Issue reason

Magento\Framework\Stdlib\StringUtils has 2 methods strlen and split. These are useful for single byte characters for PDF generation. For pdf generation, we have to check the text contains double byte characters or not.

@lenaorobei
Copy link
Contributor

@HirokazuNishi looks like strlen uses mb_strlen and split uses binary safe split so this might be not the reason of the issue.

@HirokazuNishi
Copy link
Collaborator Author

@lenaorobei for PDF generation, we have to mind character width , too. mb_strwidth can detect the given string contain only single bytes or not. The issue reason is, strlen and split functions in StringUtils doesn't check string width against double byte characters.

@sukeshini-kot
Copy link

Same issue occurs when there are long product names in the invoice or in other PDFs. Is there any workaround for this?

@HirokazuNishi
Copy link
Collaborator Author

@sukeshini-kot You need to define plugin against StringUtils.

@sukeshini-kot
Copy link

sukeshini-kot commented Jun 9, 2022

@HirokazuNishi Thank you very much. Adding an around plugin to strlen() solved the issue.

public function aroundStrlen(
        \Magento\Framework\Stdlib\StringUtils $subject,
        \Closure $proceed,
        $string
    ) {
        if ($string !== null) {
            if (mb_strlen($string, 'UTF-8') !== strlen($string)) {
                // String contains multibyte characters
                return strlen($string);
            }
            return $proceed($string);
        }
        return 0;
    }

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