i am using laravel and php and tiny-but-strong-world
engine
i have php file that will generate the docx and i have sample template
docx
but i got the output like this
PK!ߤ?Z [Content_Types].xml ¢( ´??E?·Ub袪*>-R?{V?¼þ¾QU l"%3?3Vƃ?l µw%?=^i7+??d&???l4¼½L60#µÒ? O£X?*V$z3?3?½??p)Oµ^ ²?}nH"d??gL´??|Prۃs??PW?t4Q+?"¦wa©¯|T\y¹°¤,N??U¥%´?-D/?¢X¡ݞÿ(¦¼?U>\þ??(a?§P£¨F?«K!ʑ¦U?¤z§1gw1?6§1?'0ª¿Ŵªw?¸?4´5(K#S z¿?gX§¹#? ?LJP?P¶&:2UH?¤#?Ð?$gq?C:§??I ?M¾??W?D¤³4K?"»!iq;??r#9?r?H:6VW¼µ?½¾4}?·N?£µɡ??.XQ-Ӳ??4?v wO9qgj??5TnO1¿??˟F?½?&??Cn&D?¹???v??h ¹S?¬¦z?[}].-s¶*7h?Ю7{]?²?«??IJH y<º^YA
Related
I'm running a shiny app using flexdashboard but having trouble adding images to the app. The folder containing the images is not being recognized. Here is my folder structure -
Root_Project
-- \app
--- \app_R
---- app.Rmd
---- \bike_img
----- \product_id_37417.jpg
Inside my project, I have a folder called app
Inside app, I have another folder called app_R.
Inside app_R I have a app.Rmd file (which contains the code for the app) and another folder called bike_img (which contains a .jpg file)
In the app.Rmd, I have the following code chunk (after the hashtag is just a comment explaining what the code is doing) -
renderPrint ({
id = "37420" #an id string
dir_files <- fs::dir_ls("bike_img/") #list all files in the bike_img directory
dir_res <- dir_files %>% str_detect(detect_product_id) #detect any file containing the id string
dir_files[dir_res] #return the file containing the id string
})
When I run this in the console, I get the required result which is bike_img/product_id_37420.jpg. However when I run the app, I get the following error
Error: [ENOENT] Failed to search directory 'bike_img': no such file or directory
There seems to be an issue detecting the bike_img folder. Not sure if this is an issue with my code or the {fs} package.
Can anyone see what I may be doing wrong??
R Officer package is not able to read old PPT files of type Windows Presentation 97-2003. It gives below error.
simpleError in zip::unzip(zipfile = newfile, exdir = folder): zip error: Cannot open zip fileC:\Users\user1\AppData\Local\Temp\RtmpeYD5pQ\file41fc3c39b6.pptfor reading in file zip.c:238>
below is the sample code
content <- read_pptx(fileName)
data <- pptx_summary(content)
The content object should return rpptx object.
No, the officer package only support *.docx and *.pptx documents. See https://davidgohel.github.io/officer/ for more details
I have created powerpoint files using officer package and I would also like to save them as pdf from R (dont want to manualy open and save as pdf each file). Is this possible?
you can save the powerpoint object edited using the code which is posted here: create pdf in addition to word docx using officer.
You will need to first install pdftools and libreoffice
library(pdftools)
office_shot <- function( file, wd = getwd() ){
cmd_ <- sprintf(
"/Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf --outdir %s %s",
wd, file )
system(cmd_)
pdf_file <- gsub("\\.(docx|pptx)$", ".pdf", basename(file))
pdf_file
}
office_shot(file = "your_presentation.pptx")
Note that the author of the officer package is the one who referred someone to this response.
Note that the answer from Corey Pembleton has the LibreOffice iOS path. (Which I personally didn't initially notice). The Windows path would be something like "C:/Program Files/LibreOffice/program/soffice.exe".
Since the initial answer provided by Corey, an example using docxtractr::convert_to_pdf can now be found here.
The package and function are the ones John M commented in Corey initial answer.
An easy solution to this question is to use convert_to_pdf function from docxtractr package. Note: this solution requires to download LibreOffice from here. I used the following order.
First, I need to set the path to LibreOffice and soffice.exe
library(docxtractr)
set_libreoffice_path("C:/Program Files/LibreOffice/program/soffice.exe")
Second, I set the path of the PowerPoint document I want to convert to pdf.
pptx_path <- "G:/My Drive/Courses/Aysem/Certifications/September17_Part2.pptx"
Third, convert it using convert_to_pdf function.
pdf <- convert_to_pdf(pptx_path, pdf_file = tempfile(fileext = ".pdf"))
Be careful here. The converted pdf file is saved in a local temporary folder. Here is mine to give you an idea. Just go and copy it from the temporary folder.
"C:\\Users\\MEHMET~1\\AppData\\Local\\Temp\\RtmpqAaudc\\file3eec51d77d18.pdf"
EDIT: A quick solution to find where the converted pdf is saved. Just replace the third step with the following line of code. You can set the path where you want to save. You don't need to look for the weird local temp folder.
pdf <- convert_to_pdf(pptx_path, pdf_file = sub("[.]pptx", ".pdf", pptx_path))
I have a mixed filetype collection of MS Word documents. Some files are *.doc and some are *.docx. I'm learning to use tm and I've (more or less*) successfully created a corpus composed of the *.doc files using this:
ex_eng <- Corpus(DirSource('~/R/expertise/corpus/english'),
readerControl=list(reader=readDOC,
language='en_CA',
load=TRUE));
This command does not handle *.docx files. I assume that I need a different reader. From this article, I understand that I could write my own (given a good understanding of the .docx format which I do not currently have).
The readDOC reader uses antiword to parse *.doc files. Is there a similar application that will parse *.docx files?
Or better still, is there already a standard way of creating a corpus of *.docx files using tm?
* more or less, because although the files go in and are readable, I get this warning for every document: In readLines(y, encoding = x$Encoding) : incomplete final line found on 'path/to/a/file.doc'
.docx files are zipped XML files. If you execute this:
> uzfil <- unzip(file.choose())
And then pick a .docx file in your directory, you get:
> str(uzfil)
chr [1:13] "./[Content_Types].xml" "./_rels/.rels" "./word/_rels/document.xml.rels" ...
> uzfil
[1] "./[Content_Types].xml" "./_rels/.rels" "./word/_rels/document.xml.rels"
[4] "./word/document.xml" "./word/theme/theme1.xml" "./docProps/thumbnail.jpeg"
[7] "./word/settings.xml" "./word/webSettings.xml" "./word/styles.xml"
[10] "./docProps/core.xml" "./word/numbering.xml" "./word/fontTable.xml"
[13] "./docProps/app.xml"
This will also silently unpack all of those files to your working directory. The "./word/document.xml" file has the words you are looking for, so you can probably read them with one of the XML tools in package XML. I'm guessing you would do something along the lines of :
library(XML)
xtext <- xmlTreeParse(unz(uzfil[4]), useInternalNodes = TRUE) )
Actually you will probably need to save this to a temp-directory and add that path to the file name, "./word/document.xml".
You may want to use the further steps provided by #GaborGrothendieck in this answer: How to extract xml data from a CrossRef using R?
I ended up using docx2txt to convert the .docx files to text. Then I created a corpus from them like this:
ex_eng <- Corpus(DirSource('~/R/expertise/corpus/english'),
readerControl=list(reader=readPlain,
language='en_CA',
load=TRUE));
I figure I could probably hack the readDOC reader so that it would use docx2txt or antiword as needed, but this works.
Is there a standalone library of OpenOffice's formula renderer? I'm looking for something that can take plain text (e.g. E = mc^2) in the same syntax as used by OpenOffice, and convert to png or pdf fragments.
(note: I don't need the WYSIWYG editor, just the renderer. Basically I would like to work in OpenOffice to interactively edit my formulas, and then copy the source text for use in other contexts w/o needing OpenOffice to render them.)
I'm using unoconv to convert OpenOffice/LibreOffice document to PDF.
However, first I had to create some input document with a formula.
Unfortunately, it is not possible to use just the formula editor to create ODF file because the output PDF file would contain weird headers and footers.
Therefore, I created a simple text document (in Writer) and embedded the formula as a single object (aligned as a character). I saved the ODT file, unzipped it (since ODT is just a ZIP) and edited the content. Then, I identified what files can be deleted and formatted the remaining files to get a minimal example.
In my example, the formula itself is located in Formula/content.xml. It should be easy to change just the code within the <annotation>...</annotation> tags in an automated way.
Finally, I zipped the directory and produced a new ODT file.
Then, using unoconv and pdfcrop, I produced a nice formula as PDF.
# this trick prevents zip from creating an additional directory
cd formula.odt.unzipped
zip -r ../formula.odt .
cd ..
unoconv -f pdf formula.odt # ODT to PDF
pdfcrop formula.pdf # keep only the formula
# you can convert the PDF to bitmap as follows
convert -density 300x300 formula-crop.pdf formula.png
Content of the unzipped ODT directory:
Here is the minimal content of an ODT file formula.odt.
formula.odt.unzipped/Formula/content.xml
formula.odt.unzipped/META-INF/manifest.xml
formula.odt.unzipped/content.xml
File formula.odt.unzipped/Formula/content.xml contains:
<?xml version="1.0" encoding="UTF-8"?>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<semantics>
<annotation encoding="StarMath 5.0">
f ( x ) = sum from { { i = 0 } } to { infinity } { {f^{(i)}(0)} over {i!} x^i}
</annotation>
</semantics>
</math>
File formula.odt.unzipped/content.xml contains:
<?xml version="1.0" encoding="UTF-8"?>
<office:document-content
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
xmlns:xlink="http://www.w3.org/1999/xlink">
<office:body>
<office:text>
<text:p>
<draw:frame>
<draw:object xlink:href="./Formula"/>
</draw:frame>
</text:p>
</office:text>
</office:body>
</office:document-content>
File formula.odt.unzipped/META-INF/manifest.xml contains:
<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2">
<manifest:file-entry manifest:full-path="/" manifest:version="1.2" manifest:media-type="application/vnd.oasis.opendocument.text"/>
<manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/>
<manifest:file-entry manifest:full-path="Formula/content.xml" manifest:media-type="text/xml"/>
<manifest:file-entry manifest:full-path="Formula/" manifest:version="1.2" manifest:media-type="application/vnd.oasis.opendocument.formula"/>
</manifest:manifest>
There are several web services that run LaTeX for you and return an image. For instance, http://rogercortesi.com/eqn/