To show multiple languages in a single PDF while using jsPDF library - jspdf

I have a requirement to show multiple languages in a single PDF. We are using jsPDF library.
i tried with different methods
Method 1 :
var doc = new jsPDF()
doc.text(10, 10, 'This is a test')
doc.setLanguage("en-US")
doc.save('english.pdf')
Method 2
doc.addFont("test/reference/MouhitsuBold.ttf", "Mouhitsu", "bold");
doc.setFont("Mouhitsu", "bold");
Both methods are not working for me.
Anyone who developed this scenario in your project please do the help.

Related

Display jsPDF in browser window

I am just starting to use jsPDF and I think it may actually work (after attempting a zillion different ways to produce PDFs in my Quasar/Electron desktop application that have not worked).
Is there a way to display the PDF in the application window?
this.doc = new jsPDF({
orientation: "landscape",
unit: "in",
format: [4, 2]
})
this.doc.text(this.dogArray[0].dogCallName, 1, 1)
this.doc.save("test.pdf")
That works and I can save the PDF, but I'd also like to be able to display the generated PDF in the Electron browser window. I can console.log out this.doc, and I can display it on the window, but it's just a bunch of string info.
Is there something like doc.view("file.pdf") that can be used? I'm looking through the jsPDF documentation but I'm not seeing what I'm looking for.
I want to be able to see the PDF like the author shows on his Demo Website

Kubeflow Pipelines How can we create static HTML visualization with embedded iFrame using inline storage?

I am wondering how could I create a simple static HTML visualization for kubeflow pipelines using inline storage?
My use case is I'd like to pass a string with raw html containing a simple iframe.
The sample from the doc does not work for me (kfp sdk v1).
Here is the doc I followed : https://www.kubeflow.org/docs/components/pipelines/sdk/output-viewer/#web-app
Thanks
UPDATE:
I tested the Output[HTML] from kfp sdk v2 and it works but I came across other issues.
First of all, Kubeflow html viewer creates an iframe with blank src and srcdoc="your static html". This made it impossible to use an iframe in your html as you'd have a nested iframe (the parent from the html viewer and the nested one from your actual html).
Solution :
I found a solution that works on KFP SDK v1 and v2 for all use cases, I used markdown visualization instead of HTML visualization. Since markdown supports inline HTML, I was able to directly paste my html to the markdown output. Compared to using HTML visualization, this supports iframe.
Here is some code to illustrate the solution :
from kfp.components import create_component_from_func
def markdown_vis(mlpipeline_ui_metadata_path: kfp.components.OutputPath()):
import json
metadata = {
'outputs' : [
{
'storage': 'inline',
'source': f"<iframe src=\"https://www.google.ca/\" frameborder=\"0\" allowFullScreen=\"true\" width=\"950\" height=\"600\"/>",
'type': 'markdown',
}]
}
with open(mlpipeline_ui_metadata_path, 'w') as metadata_file:
json.dump(metadata, metadata_file)
markdown_op = create_component_from_func(markdown_vis)
I also tested the doc and it works :
KFP V1 Doc : https://www.kubeflow.org/docs/components/pipelines/sdk/output-viewer/#markdown-1
KFP V2 Doc : https://www.kubeflow.org/docs/components/pipelines/sdk/output-viewer/#markdown

Getting paperjs to work in an electron app

Another learning project in the works... I am trying to use paperjs in an electron app.
According to the instructions, I think I should be using paper-jsdom (please correct me if I'm wrong). BTW, I am using TypeScript if that makes a difference. I have an HTML document with nothing but an empty <canvas> and a <script> tag referencing this:
import paper, {Color, Point, Path} from 'paper-jsdom'
window.onload = (): void => {
let canvas = document.getElementById("workspace") as HTMLCanvasElement;
paper.setup(canvas);
let path = new Path();
path.strokeColor = Color.random();
let start = new Point(100, 100);
path.moveTo(start);
path.lineTo(start.add(new Point(200, -50)));
paper.view.update();
};
So right off the bat I get:
Uncaught TypeError: paper_jsdom_1.Path is not a constructor
Ugh... So I tried a few random things (it's late, I'm tired...) and changing my import to:
import paper from 'paper'
import {Color, Point, Path} from 'paper-jsdom'
works, or at least the code above works.
Am I supposed to be importing some things from 'paper' and others from 'paper-jsdom'? What is the correct way to use paperjs in an electron app?
Unfortunately paper-jsdom doesn't seem to have any type info for TS.
Thanks!!
Since you are using Paper.js in the renderer process of Electron, you are using it in the browser context and not in Node.js context so you should use the common paper package which relies on browser Canvas API (and not paper-jsdom which targets browserless usage).
So you should be able to use Paper.js as you would for a website.
From your code example, I see that you are using TypeScript so you can have a look at this simple quickstart project that I made to play with Paper.js and TypeScript.
It uses this kind of import:
import * as paper from 'paper';
And then access Paper.js classes through the imported paper object:
new paper.Path.Circle({
center : paper.view.center,
radius : 50,
fillColor: 'orange',
});
Edit
Here is a repository showing the simplest way of using Paper.js in an Electron app.

"document" in mozilla extension js modules?

I am building Firefox extension, that creates single XMPP chat connection, that can be accessed from all tabs and windows, so I figured, that only way to to this, is to create connection in javascript module and include it on every browser window. Correct me if I am wrong...
EDIT: I am building traditional extension with xul overlays, not using sdk, and talking about those modules: https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules
So I copied Strophe.js into js module. Strophe.js uses code like this:
/*_Private_ function that creates a dummy XML DOM document to serve as
* an element and text node generator.
*/
[---]
if (document.implementation.createDocument === undefined) {
doc = this._getIEXmlDom();
doc.appendChild(doc.createElement('strophe'));
} else {
doc = document.implementation
.createDocument('jabber:client', 'strophe', null);
}
and later uses doc.createElement() to create xml(or html?) nodes.
All worked fine, but in module I got error "Error: ReferenceError: document is not defined".
How to get around this?
(Larger piece of exact code: http://pastebin.com/R64gYiKC )
Use the hiddenDOMwindow
Cu.import("resource://gre/modules/Services.jsm");
var doc = Services.appShell.hiddenDOMWindow.document;
It sounds like you might not be correctly attaching your content script to the worker page. Make sure that you're using something like tabs.attach() to attach one or more content scripts to the worker page (see documentation here).
Otherwise you may need to wait for the DOM to load, waiting for the entire page to load
window.onload = function ()
{
Javascript code goes here
}
Should take at least diagnose that issue (even if the above isn't the best method to use in production). But if I had to wager, I'd say that you're not attaching the content script.

Page header required on exported file excel or pdf

I have a web application and i need to export a list to a .xlsx or .pdf format. During exporting the page, page should contain the page header of the company along with the list. How is it possible? I am doing this project in grails. Is there any plugin which would make this possible. I've already tried Export Plugin in Grails, it does not have that facility.
we are currently creating some exports to PDF with Grails. The reports contain also tables and different logos in the header.
We are using the itext library which fits pretty good our requirements. You have to be aware that the newer itext versions are not open source.
Here is a sample code snippet:
Document document = new Document(PageSize.A4)
def baos= new ByteArrayOutputStream(30)
def dos= new DataOutputStream(baos)
PdfWriter writer = PdfWriter.getInstance(document, dos)
PageNumberEventHelper events = new PageNumberEventHelper()
writer.setBoxSize("art", new Rectangle(36, 54, 559, 788))
writer.setPageEvent(events);
Font titleFont = new Font(Font.UNDEFINED, 22, Font.BOLD)
document.open()
// render title
document.addTitle(getMessage('pricelist.title', [(new Date()).format('dd.MM.yyyy')]));
document.add(new Paragraph(getMessage('pricelist.title', [(new Date()).format('dd.MM.yyyy')]), titleFont))
document.add(new Paragraph(' '))
...
document.close()
try jasper plugin, you can make you own style output

Resources