stephanrauh / ngx-extended-pdf-viewer

A full-blown PDF viewer for Angular 16, 17, and beyond
https://pdfviewer.net
Apache License 2.0
450 stars 168 forks source link

Text within the text block is printed upside down (independent line) #2255

Closed bryanwac closed 2 months ago

bryanwac commented 3 months ago

Hi, has been a while since we talk !

Now I'm facing this error:

I am using this function to add a text-block into my pdf on page with pageNumber X:

public async addTextEditorForPage(pageNumber: number): Promise<void> {

    let usuario = JSON.parse(this.storage.read('usuario'));
    let cpfFormatado = usuario?.documento?.replace(/^(\d{3})(\d{3})(\d{3})(\d{2})$/, '***.$2.$3-**');

    const textEditorAnnotation: FreeTextEditorAnnotation = {
      annotationType: 3,
      color: [0, 0, 0],
      fontSize: 10,
      value: `Assinado digitalmente por:\n${usuario.nome}.\nDocumento: ${cpfFormatado}`,
      pageIndex: pageNumber - 1, // Índices de página começam do 0
      rect: [
        70, // espaço entre a borda da esquerda e o texto
        0,
        0,
        this.pageHeight - 30, //posicao baseada na orientação da pagina
      ],
      rotation: 0,
    };
    this.addedAnnotations.push(textEditorAnnotation);
    this.pdfService.addEditorAnnotation(textEditorAnnotation);
    this.editStylesOfEditToolBar();
  }

The text is correctly added, and displayed this way:

image

And I am using the line below to save PDF as blob:

const blob = await this.pdfService.getCurrentDocumentAsBlob();

the blob is uploaded on aws and I save it to my database.

==============================================

I am facing this issue here that I would like to use ur help:

If I just add the text-block, and do not resize it / move it, this happens:

image

The text-block moves left and up sides, and all lines on the text-block turn upside down.

I could not replicate this on ur trial version, cz If I place a text-block there, with content, and do not resize or move, the block is not gettin printed on pdf when I download it.

stephanrauh commented 2 months ago

I've managed to reproduce the bug. It's really strange:

stephanrauh commented 2 months ago

It seems to be a problem with your coordinates.

So you've defined a box that spans almost the entire page but it only zero pixels wide. That confuses other PDF renderers and the printer. It's weird that the print function is confused because it's the same renderer. But maybe there's a small difference.