IzakMarais/reporter

Generate horizontal pdf

kokunas opened this issue ยท 14 comments

I was wondering if it is possible to generate horizontal pdf's?

Thanks in advance

You have to define a custom LaTeX template and add it to the url in your link in order to modify the report. I highly recommend looking into all of the cool things that LaTeX can do as it's possible to add logos, move titles, add extra text and all sorts of things.

\usepackage{pdflscape}
...
\begin{landscape}
...
\end{landscape}

The template must be in your project directory under /bin/templates/landscapeTemplate.tex
Then you can add the following package and parameters to the LaTeX template:
http://myserver_hostname:8686/api/v5/report/yDjwtFiiz?apitoken=abc123def456ghi789=?template=landscapeTemplate

For example:

%landscapeTemplate.tex
%use square brackets as golang text templating delimiters
\documentclass{article}
\usepackage{pdflscape}
\usepackage{graphicx}
\usepackage[margin=1in]{geometry}
\graphicspath{ {images/} }
\begin{document}
\begin{landscape}
\title{[[.Title]] [[if .VariableValues]] \ \large [[.VariableValues]] [[end]] [[if .Description]] \ \small [[.Description]] [[end]]}
\date{[[.FromFormatted]]\to\[[.ToFormatted]]}
\maketitle
\begin{center}
[[range .Panels]][[if .IsSingleStat]]\begin{minipage}{0.3\textwidth}
\includegraphics[width=\textwidth]{image[[.Id]]}
\end{minipage}
[[else]]\par
\vspace{0.5cm}
\includegraphics[width=\textwidth]{image[[.Id]]}
\par
\vspace{0.5cm}
[[end]][[end]]
\end{center}
\end{landscape}
\end{document}

Thanks for the info @herrkutt,

I'll do it. LaTex is another new world for me.

@herrkutt Thanks for the good answer!

Didr commented

The example that @herrkutt provided didn't work for me. It is missing a backward slash wherever there is supposed to be two. Probably Github that broke something.

%use square brackets as golang text templating delimiters
\documentclass{article}
\usepackage{pdflscape}
\usepackage{graphicx}
\usepackage[margin=1in]{geometry}
\graphicspath{ {images/} }
\begin{document}
\begin{landscape}
\title{[[.Title]] [[if .VariableValues]] \\ \large [[.VariableValues]] [[end]] [[if .Description]] \\ \small [[.Description]] [[end]]}
\date{[[.FromFormatted]]\\to\\[[.ToFormatted]]}
\maketitle
\begin{center}
[[range .Panels]][[if .IsSingleStat]]\begin{minipage}{0.3\textwidth}
\includegraphics[width=\textwidth]{image[[.Id]]}
\end{minipage}
[[else]]\par
\vspace{0.5cm}
\includegraphics[width=\textwidth]{image[[.Id]]}
\par
\vspace{0.5cm}
[[end]][[end]]
\end{center}
\end{landscape}
\end{document}

It seems the project does not support v4 version api to use the customed latex template?

The template feature should be independent of the api version; it should work.

Follow up

I saw the url used in thsi thread is v5, but we are currently in v4 api.

http://myserver_hostname:8686/api/v5/report/yDjwtFiiz?
    apitoken=abc123def456ghi789=?
    template=landscapeTemplate

I am using the -templates parameter and the script is like

--templates "templates/landscape.tex"

But the pdf generated is still the default one, I have copied and pasted the latex code enclosed in this thread. Did I miss something?


Edit

I found the -cmd_template argumet, but no luck

./grafana-reporter -cmd_enable=1 -cmd_apiVersion v4 -cmd_dashboard your-dashboard-name -cmd_ts "from=now-7d&to=now" -cmd_template "templates/landscapeTemplate.tex" -cmd_o weekly_report.pdf

Update:

Solved by directly editing the source code texTemplate.go. It seems the command line flag does not work?

Thanks!!

I am using the -templates parameter and the script is like --templates "templates/landscape.tex"

From the readme:

-templates string: Directory for custom TeX templates. (default "templates/")

You are incorrectly supplying a file, not a directory. If you have created a directory templates relative to the location of the reporter binary and put your custom file landscape.tex in there you do not need to also specify the --templates command line argument, since you already used the default directory.

Hello, I have created a custom template and it works fine when I start grafana-reporter from command line:

/root/go/bin/./grafana-reporter &

However, I created a system service file in order to launch grafana reporter as a service which is using exactly the same command:

ExecStart=/root/go/bin/./grafana-reporter &

In that case, grafana reporter is started, but I get the following error:

Error reading template file: "open templates/logoTemplate.tex: no such file or directory"

What is the issue here ? When I start grafana-reporter from command line it finds the template but when started via systemctl as a service, it doesn't find it.....

fntkg commented

You can use the param --templates $GOPATH/bin/templates/ to workaround

You have to define a custom LaTeX template and add it to the url in your link in order to modify the report. I highly recommend looking into all of the cool things that LaTeX can do as it's possible to add logos, move titles, add extra text and all sorts of things.

\usepackage{pdflscape}
...
\begin{landscape}
...
\end{landscape}

The template must be in your project directory under /bin/templates/landscapeTemplate.tex Then you can add the following package and parameters to the LaTeX template: http://myserver_hostname:8686/api/v5/report/yDjwtFiiz?apitoken=abc123def456ghi789=?template=landscapeTemplate

For example:

%landscapeTemplate.tex
%use square brackets as golang text templating delimiters
\documentclass{article}
\usepackage{pdflscape}
\usepackage{graphicx}
\usepackage[margin=1in]{geometry}
\graphicspath{ {images/} }
\begin{document}
\begin{landscape}
\title{[[.Title]] [[if .VariableValues]] \ \large [[.VariableValues]] [[end]] [[if .Description]] \ \small [[.Description]] [[end]]}
\date{[[.FromFormatted]]\to[[.ToFormatted]]}
\maketitle
\begin{center}
[[range .Panels]][[if .IsSingleStat]]\begin{minipage}{0.3\textwidth}
\includegraphics[width=\textwidth]{image[[.Id]]}
\end{minipage}
[[else]]\par
\vspace{0.5cm}
\includegraphics[width=\textwidth]{image[[.Id]]}
\par
\vspace{0.5cm}
[[end]][[end]]
\end{center}
\end{landscape}
\end{document}

where i could find this setting. can you tell me please the location

I haven't seen this documented anywhere, but for custom templates that require conditionals based on panel type, the .Is() function can be used with the corresponding Panel.Type integer.

0 - SingleStat
1 - Text
2 - Graph
3 - Table

For example, if you want to rotate a Table rather than the entire page. The width of the table image is set to \textheight.

[[if .Is 3]]
\par
\rotatebox[origin=c]{270}{\includegraphics[width=\textheight]{image[[.Id]]}}
\par
[[end]]

Ideally, the user-friendly option would be to add IsText(), IsGraph(), and IsTable() funcs to grafana/dashboard.go.

func (p Panel) IsText() bool {
	return p.Is(Text)
}

func (p Panel) IsGraph() bool {
	return p.Is(Graph)
}

func (p Panel) IsTable() bool {
	return p.Is(Table)
}

Hi, I already did all the steps and test, but it does not work here, someone can help me ? the pdf is not in landscap mode

%use square brackets as golang text templating delimiters
\documentclass{article}
\usepackage{pdflscape}
\usepackage{graphicx}
\usepackage[margin=1in]{geometry}
\graphicspath{ {images/} }
\begin{document}
\begin{landscape}
\title{[[.Title]] [[if .VariableValues]] \ \large [[.VariableValues]] [[end]] [[if .Description]] \ \small [[.Description]] [[end]]}
\date{[[.FromFormatted]]\to\[[.ToFormatted]]}
\maketitle
\begin{center}
[[range .Panels]][[if .IsSingleStat]]\begin{minipage}{0.3\textwidth}
\includegraphics[width=\textwidth]{image[[.Id]]}
\end{minipage}
[[else]]\par
\vspace{0.5cm}
\includegraphics[width=\textwidth]{image[[.Id]]}
\par
\vspace{0.5cm}
[[end]][[end]]
\end{center}
\end{landscape}
\end{document}

image

image

I am editing in this path