Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate horizontal pdf #50

Closed
kokunas opened this issue Apr 5, 2018 · 14 comments
Closed

Generate horizontal pdf #50

kokunas opened this issue Apr 5, 2018 · 14 comments

Comments

@kokunas
Copy link

kokunas commented Apr 5, 2018

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

Thanks in advance

@herrkutt
Copy link

herrkutt commented Apr 5, 2018

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}

@kokunas
Copy link
Author

kokunas commented Apr 5, 2018

Thanks for the info @herrkutt,

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

@kokunas kokunas closed this as completed Apr 5, 2018
@IzakMarais
Copy link
Owner

@herrkutt Thanks for the good answer!

@Didr
Copy link

Didr commented Jul 24, 2019

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}

@Zhenye-Na
Copy link

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

@IzakMarais
Copy link
Owner

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

@Zhenye-Na
Copy link

Zhenye-Na commented Dec 3, 2019

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!!

@IzakMarais
Copy link
Owner

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.

@sanemogi
Copy link

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
Copy link

fntkg commented Jun 29, 2021

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

@therus000
Copy link

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

@rgrizzell
Copy link

rgrizzell commented Aug 4, 2023

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)
}

@ericsirius
Copy link

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}

@ericsirius
Copy link

image

image

I am editing in this path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants