davidgohel / rvg

https://davidgohel.github.io/rvg/
132 stars 15 forks source link

adding Knitr output file (PDF) as graphic #11

Closed Tlopasha closed 7 years ago

Tlopasha commented 7 years ago

Hello David ,

is there any way to add a generated standalone-PDF from Knitr as "Image" , for example with this command or somthing like it :

doc <- ph_with_vg(doc,code = graphic.exporter(),index = 2,type = "body",editable = FALSE,height = unit(4,"inches"),width = unit(7,"inches"))

graphic.exporter <- function (){
knit2pdf(input ="standalone.Rnw", output = "standalone.tex")
}

best regards proadiga

davidgohel commented 7 years ago

Hello,

adding pdf is not a feature but the following link should help: https://cran.r-project.org/web/packages/magick/vignettes/intro.html#pages

What do you need to do exactly? What is producing graphic.exporter in your case, only graphics? ph_with_vg is producing a graphic.

Tlopasha commented 7 years ago

Hello David ,

what I need to do is basiclly to add the result of .tex file into my Powerpoint. this .tex file contain tikz graphics and tabularx

for example the standalone.Rnw can be like this very Simply example :

\documentclass{article}
\usepackage{tikz}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{\textwidth}{|c|X|}
\hline
Hello World &
\vspace{0pt}
\begin{tikzpicture}[baseline]
\draw (-3, -3) rectangle (3,3);
\draw (-3,-3) -- (3,3);
\draw (-3,3)  -- (3,-3);
\end{tikzpicture}
\\
\hline
\end{tabularx}
\end{document}

and like you said , it's not a feature to add PDF file to a Powerpoint , so what I thniking about now to find a way to convert the DVI file that is generated from tex to openxmlformats and then use the function : ph_from_xml()

similarly to what this tool do http://dvisvgm.bplaced.net/ hier the generated file is svg

maybe what I thinking about is a little bit complicated or wrong , the main goal that I looking for is to add Vectors not a photos . tell me please if you have any to do this function .

davidgohel commented 7 years ago

Hi

In PowerPoint, there are 3 types of output: text, images and tables ; these can not be mixed. I don't think you can achieve what you want to do. With officer (or ReporteRs), you would need to handle the graphics and the tables separately, a placeholder for the graph and a placeholder for the table.

[...] to add Vectors not a photos [...]

Package rvg is an R graphic device, you can only produce vector graphics from R in openxml format. See an example by typing ?ph_with_vg.

To summarize:

David

Tlopasha commented 7 years ago

Hi David ,

Is it possible to add EMF files to officer or ReporteRs ? because for my problem I found a way ,that i convert PDF to EMF with inkscape and then to add it the Powerpoint

inkscape -f=test.pdf --export-emf=test.emf

davidgohel commented 7 years ago

yes, with ph_with_img.

I don't understand why this complexity when you could use simple tools such as ph_with_img and flextable::ph_with_flextable.

I am closing this as it is not a bug and not related to rvg.

David