I have a Django app hosted on Heroku. In it, I am using a view written in LaTeX to generate a pdf on-the-fly, and have installed the Heroku LaTeX buildpack to get this to work. My LaTeX view is below.
def pdf(request):
context = {}
template = get_template('cv/cv.tex')
rendered_tpl = template.render(context).encode('utf-8')
with tempfile.TemporaryDirectory() as tempdir:
process = Popen(
['pdflatex', '-output-directory', tempdir],
stdin=PIPE,
stdout=PIPE,
)
out, err = process.communicate(rendered_tpl)
with open(os.path.join(tempdir, 'texput.pdf'), 'rb') as f:
pdf = f.read()
r = HttpResponse(content_type='application/pdf')
r.write(pdf)
return r
This works fine when I use one of the existing document classes in cv.tex (eg. \documentclass{article}), but I would like to use a custom one, called res. Ordinarily I believe there are two options for using a custom class.
Place the class file (res.cls, in this case) in the same folder as the .tex file. For me, that would be in the templates folder of my app. I have tried this, but pdflatex cannot find the class file. (Presumably because it is not running in the templates folder, but in a temporary directory? Would there be a way to copy the class file to the temporary directory?)
Place the class file inside another folder with the structure localtexmf/tex/latex/res.cls, and make pdflatex aware of it using the method outlined in the answer to this question. I've tried running the CLI instructions on Heroku using heroku run bash, but it does not recognise initexmf, and I'm not entirely sure how to specify a relevant directory.
How can I tell pdflatex where to find to find the class file?
Just 2 ideas, I don't know if it'll solve your problems.
First, try to put your localtexmf folder in ~/texmf which is the default local folder in Linux systems (I don't know much about Heroku but it's mostly Linux systems, right?).
Second, instead of using initexmf, I usually use texhash, it may be available on your system?
I ended up finding another workaround to achieve my goal, but the most straightforward solution I found would be to change TEXMFHOME at runtime, for example...
TEXMFHOME=/d pdflatex <filename>.tex
...if you had /d/tex/latex/res/res.cls.
Credit goes to cfr on tex.stackexchange.com for the suggestion.
Related
I am currently using Bruno Paz's extension File Templates to create some file templates...lol. The issue is I am having trouble locating where the templates are stored once they are created. I want to find where and how they are stored so I can hard code some templates in. That way users of my version of the extension will have premade templates they can immediately access instead of having to create them first. The readme indicates that the Templates should be stored as follows for windows:
C:\Users\User\AppData\Roaming\Code\User\FileTemplates
However, that path does not exist for me. The readme also states the following (I could use this a possible work around):
However, you can change the default location by adding the following to your user or workspace settings:
"fileTemplates.templates_dir": "path/to/my/templates"
However, Im unaware of what workspace settings are in VS Code.
I have a suite which has 50 test cases. When I execute my suite, I get all the failed screenshots listed in the project's folder. I want to point and store those screenshots to a different directory with the name of the test case. I wanted it to be a one time setup than doing it explicitly for every test cases.
There's quite a few ways to change the screenshots default directory.
One way is to set the screenshot_root_directory argument when importing Selenium2Library. See the importing section of Selenium2Library's documentation, and importing libraries in the user guide.
Another way is to use the Set Screenshot Directory keyword, which will do pretty much the same thing as specifying a path when importing the library. Though, using this keyword you can set the path to a new one whenever you like. For example, you could make it so that each test case could have it's own screenshot directory using this keyword. According to your question, this may be the best solution.
And finally, you may also post-process screenshots using an external tool, or even a listener, that would move all screenshots to another directory. Previously mentioned solutions are in most cases much better, but you still may want to do this in some cases, where say, the directory where you want screenshots to be saved would be created only after the tests have finished executing.
I suggest you to do the follow:
For new directory, you should put the following immediately after where you open a browser such:
Open Browser ${URL} chrome
Set screenshot directory ${OUTPUT FILE}${/}..${/}${TEST_NAME}${/}
For replace the screenshot name from the default to your own name, create the following keyword:
sc
Capture page screenshot filename=${SUITE_NAME}-{index}.png
Then, create another keyword and run it on Setup's test case:
Register Keyword To Run On Failure sc
In the above example, I created a new folder with the test case name, which create a screenshot (in case of failure) with the name of suite project name (instead of 'selenium-screenshot-1.png').
I've installed Aldryn-boilerplates, using Configuration block's advices from github (https://github.com/aldryn/aldryn-boilerplates#configuration).
But when I make python manage.py runserver I recieve a message:
/home/stp/env/local/lib/python2.7/site-packages/django/template/loader.py:110: UserWarning: Your TEMPLATE_LOADERS setting includes'aldryn_boilerplates.template_loaders.AppDirectoriesLoader', but your Python installation doesn't support that type of template loading. Consider removing that line from TEMPLATE_LOADERS.
warnings.warn("Your TEMPLATE_LOADERS setting includes %r, but your Python installation doesn't support that type of template loading. Consider removing that line from TEMPLATE_LOADERS." % loader)
The web page loads normally (without any template or style).
Also a question, where to put line ALDRYN_BOILERPLATE_NAME = 'bootstrap3'? I've placed it in the bottom of my project's settings.py file.
Anyone knows how to fix that? Or maybe there are another framework with much more detailed description about installation and configuration, which fits for beginners?
I got the some error with django 1.8 and a custom template loader. I had overridden the Loader class out of django.templates.loaders.base. To get rid of this error I also had to the set the class variable is_usable to true
class Myloader(Loader):
is_usable = True
So maybe you can solve your issue with subclassing the 'aldryn_boilerplates.template_loaders.AppDirectoriesLoader' and only change the class variable as shown above.
You have placed the ALDRYN_BOILERPLATE_NAME = 'bootstrap3' at the right place. Please mention the versions of python and django-cms you are using. If you want to try another blogging platform for python, then http://mezzanine.jupo.org/ is helpful for beginners, because it's very easy to setup.
I'm using the JavaLoader.cfc. I've used it before, but am having trouble understanding how to get one of these libraries to respond to me.
I've placed the JAR files into my java folder. I've created the "JavaLoader" object and passed the "paths" to it. But it keeps saying it cannot find the class names in the jar files or something along those lines...
The requested class could not be found. The requested class
opennlp.tools.sentdetect could not be found in the loaded
jars/directories.
I recognize I'm a total n00b when it comes to Java and how to tie it in with ColdFusion. I'm sure it's something stupid that IF I KNEW I could probably use any JAR file at my disposal...
Please help if you can!
I checked the OpenNLP javadocs here and it seems that opennlp.tools.sentdetect has no constructor so that's why it returns an error. Which method do you want to call?
I've done a simple example to detect sentences but for that you need to get the english model available here :
<cfscript>
// load NLP jar libraries
sourcePaths = [expandPath("opennlp-tools-1.5.0\opennlp-tools-1.5.0.jar"),expandPath("opennlp-tools-1.5.0\lib\maxent-3.0.0.jar"),expandPath("opennlp-tools-1.5.0\lib\jwnl-1.3.3.jar")];
javaloader = createObject("component", "javaloader.JavaLoader").init(sourcePaths);
// load our model (here english model)
// you can create your own model using the TrainerTool
inputFile = ExpandPath("en-sent.bin");
modelIn = createObject("java", "java.io.FileInputStream").init(inputFile);
model = javaloader.create("opennlp.tools.sentdetect.SentenceModel").init(modelIn);
// let's try the sentence detector
sentenceDetector = javaloader.create("opennlp.tools.sentdetect.SentenceDetectorME").init(model);
sentences = sentenceDetector.sentDetect("I love working with Java in ColdFusion! CF rocks, really! But sometimes working with Java libraries is a bit tricky :-)");
</cfscript>
<cfdump var="#sentences#">
Have fun! :-)
No Java expert here either , but I did get POI to work by following Rays instructions here There's two articles. He covers setting up Javaloader
You issue may just be in the path to the JAR. Also be sure that you are passing the path to the JAR file as a string in an array.
Tip 1: You do not need to place the file in your java folder. Being able to place the JAR file in any directory (application root perhaps), is what JavaLoader gives you the power to do. Otherwise you might as well not use JavaLoader and just place the JAR files into the JVM classpath.
Tip 2: Be sure that initialize JavaLoader into the server scope, as it will reduce your overhead dramatically.
I'm trying to generate some LaTeX code which from thereon should generate PDF documents.
Currently, I'm using the Django templating system for dynamically creating the code, but I have no idea on as how to move on from here. I understand that I could save the code in a .tex file, and use subprocess to run pdflatex for generating the PDF. But I had so much trouble escaping the LaTeX code in "plain" Python that I decided to use the Django templating system. Is there a way that I could somehow maybe pipe the output produced by Django to pdflatex? The code produced is working properly, it's just that I do not know what to do with it.
Thanks in advance
I was tackling the same issue in a project I had previously worked on, and instead of piping the output, I created temporary files in a temporary folder, since I was worried about handling the intermediate files LaTeX produces. This is the code I used (note that it's a few years old, from when I was still new to Python/Django; I'm sure I could come up with something better if I was writing this today, but this definitely worked for me):
import os
from subprocess import call
from tempfile import mkdtemp, mkstemp
from django.template.loader import render_to_string
# In a temporary folder, make a temporary file
tmp_folder = mkdtemp()
os.chdir(tmp_folder)
texfile, texfilename = mkstemp(dir=tmp_folder)
# Pass the TeX template through Django templating engine and into the temp file
os.write(texfile, render_to_string('tex/base.tex', {'var': 'whatever'}))
os.close(texfile)
# Compile the TeX file with PDFLaTeX
call(['pdflatex', texfilename])
# Move resulting PDF to a more permanent location
os.rename(texfilename + '.pdf', dest_folder)
# Remove intermediate files
os.remove(texfilename)
os.remove(texfilename + '.aux')
os.remove(texfilename + '.log')
os.rmdir(tmp_folder)
return os.path.join(dest_folder, texfilename + '.pdf')
The dest_folder variable is usually set to somewhere in the media directory, so that the PDF can then be served statically. The value returned is the path to the file on disk. The logic of what its URL would be is handled by whatever function sets the dest_folder.