Please consider the following MWE:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{color}
\usepackage{enumitem}
\usepackage{listings}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstset {%
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
stringstyle=\color{codepurple},
basicstyle=\scriptsize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2,
%columns=fullflexible,
keepspaces=true,
language=C++,
columns=flexible,
%numberstyle=\noncopynumber % 1. If this line is only uncommented it produces 6 errors
%numberstyle=\tiny\color{codegray} % 2. If this line is only uncommented it compiles
%numberstyle=\tiny\color{codegray}\noncopynumber % 3. If this line is only uncommented it produces 6 errors
}
%\newcommand{\noncopynumber}[1]{% % Answer
%\BeginAccSupp{method=escape,ActualText={}}%
%#1%
%\EndAccSupp{}%
%}
%\makeatletter % Answer
%\def\lst@outputspace{{\ifx\lst@bkgcolor\empty\color{white}\else\lst@bkgcolor\fi\lst@visiblespace}}
%\makeatother
\begin{document}
\begin{lstlisting}
Example code line 1
*
... and 3
\end{lstlisting}
\end{document}
When I compile it using LaTeX->PS->PDF the output is very fancy:
However, when I am going to copy the text and paste it into a compiler (or anywhere else):
I tried the Martin Scharrer solution with differents options:
(suggested by TeXnician answer)

As you can see the problem is that the reference numbers (1, 2 and 3) are copied from PDF to any text editor even with the proposed solution.
I also take a look here, here and here but it does not work for me too (by the way please check that solutions).
I have code around all the full document.
Is there any easy solution to this problem?
Thanks!
EDIT: TeXnician's solution works for me as long as I keep the PDF file on my computer without sharing it via the Internet. However, when I try to upload it to, for example, Outlook his solution is without effect. You can see the reproduction in this gif (use fullscreen mode to see better the selected text in both PDF).
EDIT 2: also tested the Werner solution in Is there a LaTeX trick to prevent a PDF viewer from copying the line number? (adding \protect command inside the new command of TeXnician and/or renewing the \thelstnumber command) with the same results.




vmargin. – cfr Jul 21 '18 at 02:53geometryinstead":). I remember that @cfr, but if I change it togeometrythen the\setpapersize{A4},\setmargins{2.2cm},...code produces 3 errors. How would you fix that? – manooooh Jul 21 '18 at 03:18geometry's facilities. I would adda4paperas a class option and then use\geometry{margin=2.2cm,...}with whatever other options you need. (I don't know what all those arguments are for.texdoc geometryfor a full list of options. – cfr Jul 21 '18 at 03:31vmarginto give you equivalent code. That's a waste of my time because I shouldn't use the package. Whereas your learninggeometryisn't a waste of your time, because you should use that package. – cfr Jul 21 '18 at 03:42vmarginorgeometryis exactly the same? I really appreciate your suggestion, really, I trust you, but I am here not to fix that issue, but to fix these two problems that I posted with your help. When I find the solution that you gave me I will take a look atgeometry. – manooooh Jul 21 '18 at 03:51geometryis really necessary and I will take a look now. I do not like to disobey you because I know that you all know much more than me... – manooooh Jul 21 '18 at 03:54geometry. @cfr pointed out a recommendation. You can follow this advice or not. If there's a wasp nest, some people would recommend you to leave it alone. You can do with your code whatever you want (as long as no one cooperates, at least). You can rape it, make it entirely unreadable, format in-line... But I'd rather not recommend this. You shouldn't request something, nor get as cocky as to tell advisers they have to implement stuff in your code. We're in userland, users help users, you don't employ the users. See https://meta.stackexchange.com/q/17447 – nox Jul 21 '18 at 09:16vmarginpackage;). Please see my updated question. – manooooh Jul 21 '18 at 18:36