2020.1 Migration Guide

PSPDFKit for Web 2020.1 comes with a few improvements that might require an ad hoc migration.

Notable Changes

  • PSPDFKit.I18n#localeData has been deprecated because we have adopted React Intl version 3.x.x changes. This version has dropped support for providing custom localization data in favor of using the standard Intl Web API for pluralization and other localization rules, which means that you no longer need to provide these rules if you want to support additional locales.

    This also means you will no longer be able to provide localization rules for locales not supported by the browser, but considering the large number of locales supported by modern browsers, this should not pose a problem.

    Browsers that do not support the Intl API (like IE11 and Safari < 13) will include a polyfill for Intl.PluralRules, as well as an individual polyfill for each of the supported locales. If you want to continue supporting these browsers when providing additional locales, you can do so by including the corresponding locale polyfill:

    Copy
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    // Add the locale to the locales list (Wolof language).
    PSPDFKit.I18n.locales.push("wo");
    // Is this browser using the `Intl.PluralRules` polyfill?
    if (Intl.PluralRules.polyfilled) {
      // Then include the plural rules locale data polyfill.
      await import("@formatjs/intl-pluralrules/dist/locale-data/wo");
    }
    // Add Wolof translations for messages.
    PSPDFKit.I18n.messages["wo"] = wolofMessages;
    // Change current language to Wolof
    instance.setLocale("wo");
    

    Add the locale data polyfills to your local node_modules folder by installing them using either npm or yarn:

    1
    
    yarn add @formatjs/intl-pluralrules
    
    1
    
    npm i @formatjs/intl-pluralrules
    
  • We reworked the font sizing for the entire application, and this might result in some UI differences. In particular, if you use custom CSS for your UI, please check your application to ensure the new setup doesn’t affect your integration negatively.

  • PSPDFKit.Annotations.RectangleAnnotation#cloudyBorderInsetRect and PSPDFKit.Annotations.EllipseAnnotation#cloudyBorderInsetRect are now deprecated, and they have been replaced by the new PSPDFKit.Annotations.RectangleAnnotation#cloudyBorderInset and PSPDFKit.Annotations.EllipseAnnotation#cloudyBorderInset properties, which use a new PSPDFKit.Geometry.Inset type instead of PSPDFKit.Geometry.Rect. Thanks to this change, you will not need to update the annotation whenever the bounding box changes, as was the case with the now deprecated cloudyBorderInsetRect property.

    It will still be possible to use PSPDFKit.Annotations.RectangleAnnotation#cloudyBorderInsetRect in the constructor, where it will be transformed into a PSPDFKit.Geometry.Inset and used to set PSPDFKit.Annotations.RectangleAnnotation#cloudyBorderInset instead. cloudyBorderInsetRect can still be read too, in which case a snapshot value will be returned, which is the result of adding the inset values from cloudyBorderInset to the current bounding box.

A deprecation warning will be shown each time cloudyBorderInsetRect is used. In the next major version, cloudyBorderInsetRect will finally be removed.

If you use the cloudyBorderInsetRect property in your code, you will have to update it so it does not break once the property is removed in the next major version.

Also, when you create a new rectangle or ellipse annotation with the cloudyBorderIntensity property set and there is no cloudyBorderInset or cloudyBorderInsetRect defined, a default cloudyBorderInset will be applied with values following this formula:

1
const inset = 4.5 * cloudyBorderIntensity + strokeWidth / 2;

This default cloudyBorderInset value ensures that the cloudy border is not cropped and that it’s just wide enough for the cloudy border to fit in it. If you wish to set a cloudyBorderInset with 0 values, do it explicitly instead, using the following:

1
2
3
4
5
6
const inset = new PSPDFKit.Geometry.Inset({
  left: 0,
  top: 0,
  right: 0,
  bottom: 0
});

Or, to make it less verbose, use the utility static class method PSPDFKit.Geometry.Inset#fromValue:

1
const inset = PSPDFKit.Geometry.Inset.fromValue(0);
  • event.formField has been removed from the documentation of PSPDFKit.AnnotationsFocusEvent and PSPDFKit.AnnotationsBlurEvent. It has never been part of the event payload, and this change only affects the aforementioned documentation, so it cannot break your implementation in any way. However, if you were relying on this, you may need to review your event listener logic in case the absence of this event.formField object may have been affecting its behavior. If you think you still need this object, you can easily get the formField associated with a particular annotation by using the following code:

    Copy
    1
    2
    3
    4
    5
    6
    7
    8
    
    instance.addEventListener("annotations.blur", event => {
      instance.getFormFields().then(formFields => {
        const formField = formFields.find(
          formField => formField.name === event.annotation.formFieldName
        );
        console.log(formField);
      });
    });
    

    If you are using event.formField, here is the change you need to make:

    Before

    Copy
    1
    2
    3
    4
    5
    6
    7
    
    instance.addEventListener("annotations.focus", event => {
      console.log(event.formField);
    });
    
    instance.addEventListener("annotations.blur", event => {
      console.log(event.formField);
    });
    

    After

    Copy
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    instance.addEventListener("annotations.focus", event => {
      instance.getFormFields().then(formFields => {
        const formField = formFields.find(
          formField => formField.name === event.annotation.formFieldName
        );
        console.log(formField);
      });
    });
    
    instance.addEventListener("annotations.blur", event => {
      instance.getFormFields().then(formFields => {
        const formField = formFields.find(
          formField => formField.name === event.annotation.formFieldName
        );
        console.log(formField);
      });
    });
    
  • When the Digital Signatures component is included in the license, PSPDFKit.Instance#exportPDF will export signed documents as incrementally saved by default so as to prevent modifying signed data, which would invalidate the document’s digital signatures. However, setting the incremental flag to false will override this behavior.

    If the Digital Signatures component is not included in the license, the former behavior will be followed and signed documents will be exported as fully saved by default. In order to prevent signed data corruption in this case, the incremental flag should be explicitly set:

    1
    
    instance.exportPDF({ incremental: true });
    
  • Previously, the object returned by PSPDFKit.ViewState#viewportPadding had the vertical value under the horizontal property and vice versa. This has been now fixed. If you were relying on the previous returned value, you will need to adjust your implementation accordingly.

  • The order in which annotations are rendered has been modified. In previous versions, annotations of the same type would be rendered in the same layer, in the following order from back to front:

    • Text markup
    • Link
    • Text
    • Widget
    • Stamp
    • Image
    • Ink
    • Shape
    • Note

    Beginning with the current release, annotations will be rendered in the same order they are in the document, regardless of their type. New annotations will always be rendered on top of the last one that has been added.

    If your implementation relies on the former annotation rendering order, you may need to rearrange the order in which annotations are created so as to continue obtaining the same result.

    You would need to first create the annotations that you want to be rendered in the background, followed by the ones that you want to be rendered in the foreground. For example: First create text annotations, then stamp annotations, then ink and shape annotations, in that order. This way, your annotations will keep rendering in the order they had with the former behavior.

    If your annotations never overlap, this change will probably not affect your implementation at all.

  • The note annotation icon in the main toolbar has been updated.

If you use PSPDFKit Server, please make sure you read the 2020.1 Migration Guide.

For a full list of changes, check out the changelog.