Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Jun 01, 2022 1:50 pm

Hi,
I have issue using spire.pdf.dll library to draw rectangle on pdf document.
I am seaching for text "7754235-00" on pdf document and drawing rectangle around that text.

On 3 different computers I get 3 different results, see attached.
Do you know what might be causing this issue, e.g. can some settings on operating system affect this?

I am using this code:
Code: Select all
foreach (PdfPageBase page in pdf.Pages)
                {
                    PdfTextFindCollection findTextCollection = page.FindText("7754235-00", TextFindParameter.WholeWord);
                    PdfTextFind textFind = findTextCollection.Finds[0];
                    PdfPen pen = new PdfPen(color, 0.7f);
                    RectangleF rectangle = textFind.TextBounds[0];
                    PdfGraphicsState state = page.Canvas.Save();
                    page.Canvas.DrawRectangle(pen, rectangle);
                    page.Canvas.Restore(state);
                }

filipfilipfilip
 
Posts: 45
Joined: Mon Jun 14, 2021 10:27 am

Thu Jun 02, 2022 2:48 am

Hi Filip,

Thanks for your inquiry.

According to past experience, the locale setting of the operating system will have a certain impact on the results of text search. Not sure if this caused the issue. Are the locale settings different in your three computers? If yes, you can try to set them all the same and test again. If it doesn't work, please provide the test PDF file and more details about your computers.
You can upload them here or send them to us via email(support@e-iceblue.com). Thank you in advance.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Mon Jun 06, 2022 1:46 pm

Hi,
It does not work correctly on:
Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-159-generic x86_64)

Attached is pdf file where drawing rectangle around text "7754235-00" is incorrect.
Also, I have attached the result of drawing rectangle around that text.

We are using docker and docker file to run this program:
Code: Select all
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update;apt-get install apt-utils -y;apt-get install libfontconfig1 -y
RUN apt-get update \
    && apt-get install -y --allow-unauthenticated \
        libc6-dev \
        libgdiplus \
        libx11-dev \
     && rm -rf /var/lib/apt/lists/*

WORKDIR /app

FROM base AS final
WORKDIR /app
COPY . /app
ENV ASPNETCORE_URLS http://*:12000
ENTRYPOINT ["dotnet", "DrawRectangle.dll"]

filipfilipfilip
 
Posts: 45
Joined: Mon Jun 14, 2021 10:27 am

Wed Jun 08, 2022 9:39 am

Hi Filip,

Thanks for your sharing and sorry for the late reply.

I tested in a similar environment based on the dockerfile and PDF file you provided. But I still can't reproduce your problem. Below is my test environment information.

Code: Select all
docker version: 19.03.12
system: ubuntu linux 18.04 x64
project: .netcore 2.2

I also tried to change the current thread culture, but that didn't affect the result. To make our testing process as consistent as possible, could you please share your testing .NETCORE project with me as well? Thanks in advance for your assistance.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Fri Jun 10, 2022 12:02 pm

Hi ,
Attached is the c# solution and input file where rectangle is not drawn properly on our machine.
Best regards,
Filip

filipfilipfilip
 
Posts: 45
Joined: Mon Jun 14, 2021 10:27 am

Tue Jun 21, 2022 1:18 pm

Hi,
Have you replicated this issue?
Best regards,
Filip

filipfilipfilip
 
Posts: 45
Joined: Mon Jun 14, 2021 10:27 am

Tue Jun 28, 2022 1:46 pm

Hi,
Can you take a look at this issue,
have you managed to replicate this?
Best regards,
Filip

filipfilipfilip
 
Posts: 45
Joined: Mon Jun 14, 2021 10:27 am

Wed Jun 29, 2022 1:35 am

Hi Filip,

Sorry for the late reply.

I've tested your project before, but I had to put it on hold to deal with other clients because I encountered some unexpected errors when executing your dockerfile, and after a few tries it still didn't work. Sorry, I forgot later that your issue is not finished yet. I'm really sorry. Please forgive me. I will continue to test and investigate your issue and give you feedback today.
My apologies again for my negligence.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Wed Jun 29, 2022 10:18 am

Hi Filip,

I've finished test and reproduced the issue. The drawn rectangle does deviate from the area where the original text was(shown in the screenshot).
5E6B39C3-A4B3-4a73-97F9-9F4C5115DD7A.png

I have logged this issue in our bug tracking system with the ticket SPIREPDF-5311. We will investigate further and resolve this issue. Sorry for the inconvenience caused.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Tue Jul 12, 2022 2:10 am

Hi Filip.

I'm writing to give an update of SPIREPDF-5311 to you.
After investigation by the developers, the cause of this issue is missing fonts. The font Arial-Bold is used in your PDF file, but it is not present in the docker container, causing Spire.PDF to miscalculate the position of the text.
Therefore, you need to copy the relevant fonts into the docker container. You can find the Arial family of fonts in the Windows fonts library. And add the following commands(for reference) to the dockerfile to copy the fonts to the /usr/share/fonts/ directory in the docker container.
Looking forward to your feedback.

Code: Select all
#copy fonts
RUN mkdir /usr/share/fonts/
COPY ARIAL.TTF /usr/share/fonts/ARIAL.TTF
COPY ARIALBD.TTF /usr/share/fonts/ARIAL.TTF
COPY ARIALBI.TTF /usr/share/fonts/ARIALBI.TTF
COPY ARIALN.TTF /usr/share/fonts/ARIALN.TTF
COPY ARIALNB.TTF /usr/share/fonts/ARIALNB.TTF
COPY ARIALNBI.TTF /usr/share/fonts/ARIALNBI.TTF
COPY ARIALNI.TTF /usr/share/fonts/ARIALNI.TTF
COPY ARIALUNI.TTF /usr/share/fonts/ARIALUNI.TTF
COPY ARIALI.TTF /usr/share/fonts/ARIALI.TTF
COPY ARIBLK.TTF /usr/share/fonts/ARIBLK.TTF
COPY ARLRDBD.TTF /usr/share/fonts/ARLRDBD.TTF
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Mon Jul 18, 2022 2:02 am

Hi Filip,

Hope you are doing well.

Did that solution works for you? Could you please give us some feedback at your convenience?
Thanks in advance.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Wed Jul 20, 2022 7:50 am

Hi Andy,
I will let you know as soon as possible.
Best regards,
Filip

filipfilipfilip
 
Posts: 45
Joined: Mon Jun 14, 2021 10:27 am

Wed Jul 20, 2022 9:00 am

Hi Filip,

Looking forward to your feedback.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Mon Aug 29, 2022 2:09 pm

Hi,
It still doesn't work after adding fonts, position of rectangle is a bit changed but not correct.
Does anything besides font has an effect on drawing rectangles on Ubuntu?

I have sent you pdf examples to support@e-iceblue.com and result.
Result can be seen on sent pdfs also around texts "2200.55" and "306.81" where "Courirer" font is used,
"Courirer" font is added to Ubuntu, has an effect on drawn rectangles positions, but it is still not good enough.

Can you take a look?

Best regards,
Filip

filipfilipfilip
 
Posts: 45
Joined: Mon Jun 14, 2021 10:27 am

Tue Aug 30, 2022 9:33 am

Hi Filip,

Thanks for your feedback.

I have done many tests and I also added "Cour" series fonts to docker container but the rectangles were still not good enough. Now I'm not sure if there are other factors affecting the calculation of the coordinates. The developers will investigate it further and I'll let you know the progress.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Return to Spire.PDF