Grails wkhtmltopdf plugin: no pdf output - pdf

i am trying use the Grails wkhtmltopdf plugin (https://github.com/quorak/grails-wkhtmltopdf), but i can't get a rendered pdf file. Only the gsp template is shown instead.
What I have done so far:
This is the link, which calls the action in the Controller:
<g:link action="downloadQuestionnaire" id="${questionnaireInstance?.id}">Download questionnaire</g:link>
This is the action in the Controller:
def downloadQuestionnaire = {
def questionnaire = Questionnaire.get(params.id)
render( filename:"File ${questionnaire.id}.pdf",
view:'/templates/pdf/_questionnaire.gsp',
model:[questionnaireInstance: questionnaire],
marginLeft:20,
marginTop:35,
marginBottom:20,
marginRight:20,
headerSpacing:10,
)
}
_questionnaire.gsp is the template, which should be rendered as pdf.
In config.groovy
grails.plugin.wkhtmltox.binary = "/usr/local/bin/wkhtmltopdf"
and i checked, that wkhtmltopdf ist working correctly.
To my understanding of the wkhtmltopdf plugin, the template _questionnaire.gsp should be rendered as pdf available to download.
But in my case, the gsp-template is shown with the data of the questionnaireInstance.
There are no error messages at all.
Any ideas, how to get the pdf output?

add pdf: 'application/x-pdf' to grails.mime.types in Config.groovy
grails.mime.types = [
all: '*/*',
....,
pdf: 'application/x-pdf'
]
and try to call controller/action.pdf or custom your g:link tag into this
<g:link action="downloadQuestionnaire" id="${questionnaireInstance?.id}.pdf">Download questionnaire</g:link>
hope it help.

Related

How can I add Font Awesome support to Ckeditor5?

I am trying to add Font Awesome support to Ckeditor5-inline and it just removes the "i" tags from HTML when I go in Edit mode.
First download font awesome if you haven't already then
1. Extract the downloaded file (fontawesome.zip) Copy the "fontawesome"
2. folder to "ckeditor/plugins/" folder Open the file
3. "ckeditor/config.js"
configure that like this and clear your browser's cache
config.extraPlugins = 'fontawesome';
config.contentsCss = 'path/to/your/font-awesome.css';
config.allowedContent = true;
In your HTML's section add this code:
<script>CKEDITOR.dtd.$removeEmpty['span'] = false;</script>
after that you can Use toolbargroupname: "FontAwesome" in your toolbar like this
config.toolbar = [
{ name: 'insert', items: [ 'FontAwesome', 'Source' ] }
];
as you commented your are using Django Integration in Django CMS
Django CMS enables adding text-based content to a site using CKEditor which is integrated through the module called djangocms_text_ckeditor. In that module is a static folder and settings.py file, which are setup in a manner that enables fully customizing CKEditor.
you can check here for Django Integration

How to display PDF file on yii2

I have a audit table and audit_report field.Field type is text .I saved pdf files into folder and saved name to database.I tried to display the pdf on view page. but the box with image sign only getting. I could display jpeg and png files nicely.How to display PDF on view page of yii2 framework.
This would work,
return Yii::$app->response->sendFile($completePath, $filename, ['inline'=>true]);
Input the function with third param as array of value 'inline'=>true to open the file within the browser window.
See the documentation here sendFile()
You could add a button that opens the file in a new tab, but make it link to an action in your controller that returns the file instead of the direct path to the file:
In your view:
<?= Html::a('PDF', [
'controller/pdf',
'id' => $model->id,
], [
'class' => 'btn btn-primary',
'target' => '_blank',
]); ?>
In your controller:
public function actionPdf($id) {
$model = ModelClass::findOne($id);
// This will need to be the path relative to the root of your app.
$filePath = '/your/file/path';
// Might need to change '#app' for another alias
$completePath = Yii::getAlias('#app'.$filePath.'/'.$model->fileName);
return Yii::$app->response->sendFile($completePath, $model->fileName);
}
Aliases - Key Concepts - The Definitive Guide to Yii 2.0
Although the question has been answered there is one thing that needs to be addressed if you have the file content/stream instead of the file path, like for instance you are using Dropbox API and you receive a stream from the API and want to display that file instead of forcing the browser to download.
For this case you can use the sendContentAsFile when attempting to display the PDF file in the browser you will need to specify the mimeType option too along with the "inline"=>true because the default mimeType value is set to application/octet-stream which is used to download a file and to display inline in browser you need to change it to application/pdf.
return Yii::$app->response->sendContentAsFile(
$fileContent,
$filename,
['inline' => true, 'mimeType' => 'application/pdf']
);

Ember view to display a PDF

In one of my views I would like to display a PDF, which is accesible via URL. This should be done without opening an extra tab in the browser, and without downloading the PDF (to view it outside the browser). It should be visible embedded within the Ember application.
What I have in mind is:
Use the URL to get the PDF and make it accessible to the ember application.
Use a special "PDF view" to display the PDF.
Is this possible? What options do I have to display an embedded PDF in an Ember application?
Displaying a PDF is not really related to ember, because to view a PDF you need a PDF plugin installed in your browser (which is mostly installed by default depending by the browser).
That said, a possible solution I could imagine could be to create a custom ember view with the tagName iframe on which you set the src attribute to the link referring to the PDF.
Example:
App.PDFView = Ember.View.extend({
tagName: 'iframe',
attributeBindings: ['src', 'width', 'height', 'frameborder'],
src: 'pdffile.pdf',
width: 800,
height: 600,
frameborder: 0
});
I've also used width, height and frameborder only for convenience so you can control some of the iframe's attributes easily from within ember. Here a working demo.
You can also go with something more elaborated and use a js lib like http://pdfobject.com/ which you then initialize in your view's didInsertElement hook:
App.PDFView = Ember.View.extend({
src: 'pdffile.pdf',
width: 800,
height: 600,
didInsertElement: function() {
new PDFObject({
url: this.get('src'),
width: this.get('width'),
height: this.get('height')}
).embed(this.get('elementId'));
}
});
(haven't tested the latter, but you get the point)
And then use this App.PDFView like a normal ember view in your templates.
{{view App.PDFView}}
Or your can set the src, width & height directly from within your template like
{{view App.PDFView src="pdffile.pdf" width="600" height="800"}}
Hope it helps.
You can certainly leverage the Ember PDFJS Addon by doing:
ember install ember-pdfjs
The README on GitHub describes the installation and use cases.
In short, the addon provides your Ember project with a component, pdf-document, which you can use in your HTMLBars template like so:
{{pdf-document src=[model.src]}}
... there are other permutations of what src can be (including a string file path, resource URI, or Uint8Array buffer).
If you don't see a feature that you need, please suggest in the Issues.

wicked_pdf footer not working

I've got little problem with wicked_pdf footer render.
Here is my render method:
def invoice
render pdf: "#{#order.number}.pdf",
footer: { html: { template: "admin/orders/invoice_footer.html" } },
margin: { bottom: 25 }
end
PDF render works OK, but there is no footer template. I tried different margins in wicked settings, but with no success.
Just had this same issue, the problem seemed to be that my wkhtmltopdf install did not generate the footers as requested.
The version I had was installed via the Ubuntu repository, I un-installed this and downloaded a pre-built version as described here and now it works fine:
https://github.com/mileszs/wicked_pdf/wiki/Getting-Started-Installing-wkhtmltopdf
I did run into the same problem and it was a problem with the partial not being rendered.
So this answer https://stackoverflow.com/a/19323701/784318 did work for me:
So I changed my code from this:
options = {
header: {html: {template: 'shared/_header', layout: nil}},
}
To this:
options = {
header: {content: render_to_string('shared/_header', layout: nil)},
}

Problem with using Uploadify

I have been trying to implement uploadify in my rails 3.1 app. And I followed the step mentioned here. And here is my code:
{my form code here}
- arr = []
- request.env['HTTP_COOKIE'].each_char{|c| arr.push(c[0].to_s)}
- #session = arr.join("x")
= #sermon_path = sermons_path
:javascript
$('#sermon_sermon').uploadify({
uploader: '/uploadify.swf',
script: '#{#sermon_path}',
cancelImg: 'cancel.png',
buttonText: 'Browse',
auto: true,
scriptData: { 'session_encoded': '#{#session}'}
})
This did showed uploadify button to select file to upload, but when the file is selected nothing happens. It doesn't even shows the uploaded file and no response is sent back to server.
Any help would be highly appreciated.
I newer use uploadify except in a php project but may be this other tutorial can help you. On github there is a working example and an other but with rails 2.3.4 or you can simply try this gem.