Is there a way to export the PowerPoint? - javascript

I wanna export GoJs diagrams to Microsoft Office PowerPoint. so examined it, but I couldn't get a good result.
Is there a good way to do it?

Currently, jpeg image type is supported.
myDiagram.makeImage({
scale: 1,
background: "AntiqueWhite",
type: "image/jpeg"
});
The following image is a jpeg created with an AntiqueWhite background specified.
Please refer to documentation in this page for more information.

I found the best way.
Gojs can't export to PowerPoint, but I can get diagram objects.
Using that object, write an intermediate json file.
We grasp the state of diagram from that json and create a PowerPoint using apache poi.
apache poi https://poi.apache.org/
thanks.

Related

How can I read a file's metadata in Node.js, beyond what the fs.statSync provides without using a library?

This is a topic where I can't seem to find the answer on the Node.js docs (I know it's possible because of libraries like exif), nor can I find an answer on the internet without everyone saying to just use a library.
I don't want to use a library, so I want to do this natively and learn more about reading file metadata, and maybe eventually updating the metadata too while building my own mini-tool.
If I run something like fs.statSync() I can get generic metadata that returns in the Stats object; but, in my case, I'm looking for all the other metadata, NOT just the basic file info like size, birthtime, etc.
I want the other metadata like dimensions, date taken, and especially things you'd see in image, video, or audio files.
Maybe there's something like:
const deepMetaData = fs.readFileSync().getMetaDataAsString();
console.info(/Date Taken/.test(deepMetaData)); // true
or
const deepMetaData = fs.createReadStream().buffer().toString();
const dateTaken = deepMetaData.match(/Date Taken: (\d{4}-\d{2}-\d{2})/)[1];
console.info(dateTaken);
If I need to work with buffers, streams, whatever, instead of a string output, that's cool too. Ideally something synchronous. So if there's a simple example someone could provide of how to read that kind of meta data without a library, I'll at least be able to look up the methods used from that to understand more later and leverage the docs associated with whatever approach. Thank you!
Nodejs fs functions like fs.statSync() provide OS level metadata on the file only (such as createDate, modificationDate, file size, etc...). These are properties of the file in the file system. These do NOT have anything at all to do with the actual data of the file itself.
When you talk about EXIF (for a photo), this is parsed from the file data itself. To know about that type of data, you must read and parse at least the beginning of the file and you must be able to recognize and understand all the different file formats that you might encounter. For photos, this would include JPEG, PNG, HEIC, GIF, etc... Each of those have different file formats and will require unique code for understanding the metadata embedded in the file.
Nodejs does not have support for any of that built-in.
So, it will take custom code for each file type. If you further want to include other types of files like videos, you need to extend your list of different file types you can read, parse and understand. For the depth of files you're talking about this is a big job, particular when it comes to testing against all the different variants of files and metadata that exist out in the wild.
I personally would be fine with implementing my own code for one particular file type like JPEG, but if I was tasked with supporting dozens of types of files and particularly if tasked with supporting the wide range of video file formats, I'd immediately seek out help from existing libraries that have already done all the time consuming work to research, write and test how to properly read and understand all the variants.
I know it's possible because of libraries like exif
This is an example of a library that reads the beginning of the image file, parses it according to the expected format and knows how to interpret all the possible tags that can be in the EXIF header and what they all mean.
So if there's a simple example someone could provide of how to read that kind of meta data without a library
Go study the code for the EXIF library and see how it works. If you're going to implement it yourself, that's how you have to do it. I'm still not sure why you'd avoid using working libraries if they already exist. That is one of the biggest advantages of the nodejs ecosystem - you can build on all the open source code that already exists without reimplementing it all from scratch yourself and spend your coding time on parts of your problem that someone else has not already implemented.
how would one read that metadata using node?
You literally have to read the data from the file (usually at the start of the file). You can use any of the mechanisms that the fs module provides. For example, you can use fs.createReadStream() and then stream in the file, parsing and interpreting it as data arrives and then stop the stream when you get past the end of the metadata. Of, you can open a file handle using fs.open() and use fs.read() to read chunks of the file until you have read enough to have all the metadata.
You HAVE an example sitting right in front of you of code that does this in the EXIF library on NPM that you already seem to know about. Just go examine its code. The code is ALL there.
I'm just looking for a simple answer on getting that info, even if it's a blob of strings.
This is perhaps your main problem. There is no simple answer to get that info and it doesn't just exist as a blob of strings. These files are sometimes binary files (for space efficiency reasons). You have to learn how to read and parse binary data. Go study the code in the EXIF library and see what it is already doing and you can learn from that. There is no better example to start with.
But, for a simple example using the heic filetype, this will grab the first 5000 characters of the file's metadata, which can then be searched:
const fileDescriptor = fs.openSync(absPathToHeicPhoto);
const charCount = 5000;
const buffer = Buffer.alloc(charCount);
const headerBytes = fs.readSync(fileDescriptor, buffer, 0, charCount);
const bufferAsStr = buffer.toString('utf8', 0, charCount);
console.info(/\d{4}:\d{2}:\d{2}/.test(bufferAsStr));
FYI, I looked at the code for this EXIF library on NPM and it's poorly implemented. It uses fs.readFile() to load the ENTIRE image into RAM (even though it only needs a fraction of the data at the start of the file). This is a poor implementation for this reason (memory and disk inefficient).
But, it does have a method called processImage and one called extractExifData that process the binary data of the file to parse out the EXIF info. These are links to its actual code. You can start learning there.
FYI, as a photographer, I use a command line program called exiftool that will dump exif info to stdout or to a file for many images. As a different approach, you could just run that tool from your nodejs program (using the child_process module and capture its output and use that output, letting it do the hard work you just operate on the generated output.

How can I export image in Excel using Javascript?

One of my requirement is I want to export image and store inside excel using javascript.
I am using export excel using saveAs(blob, filename) and I am able to export javascript data into the excel but I could not able to export image? There is no any server side.
Any body has any idea over this
You can use xlsx library https://www.npmjs.com/package/xlsx
$("[id$=mybutton]").click(function(e) {
window.open('data:application/vnd.ms-excel,' + encodeURIComponent( $('div[id$=image]').html()));
e.preventDefault();
});
Demo https://jsfiddle.net/viethien/dfb3n2x1/11
There is a JS library to create excel. I haven't tried it though. https://github.com/stephenliberty/excel-builder.js However, it should be fairly trivial to loop through your JSON and create a CSV file, which will ultimately open in excel. That might work better depending on your needs.
But to be clear, when you say store an image, do you mean a link to an image, or a base64 text of an image? The latter would be huge and probably break excel in some way.
Other Resources:
https://www.grapecity.com/blogs/how-to-importexport-excel-files-using-javascript-and-spread-sheets

How to write excel file with chart using js-xlsx

Using SheetJS js-xlsx "xlsx": "0.15.1" js is there a way to write excel file with chart.
Basically I want to export html page that contains chart into an excel file.
HTML page is getting exported successfully but the chart in the page is not getting displayed.
Here is the code I have used
let wb =XLSX.utils.book_new();
let element: any = document.getElementById('page1');
let ws = XLSX.utils.table_to_sheet(element);
XLSX.utils.book_append_sheet(wb,ws,'page1');
Are you using the Community build or the Pro?
As stated here, The Community build reflects the data cached in charts as worksheets. Other chart-related features, including writing and reading metadata, are included in the Pro compendium.
Remember to include your work as Chartsheet, just in case. It will continue to render it as a Worksheet if you are using the community version, but it will help us to understand the desired behavior that you are seeking.
If you provide more reference for the code, maybe we can show you some shortcuts to make it work.

How to embedded font inside the .pptx file

I am creating a .pptx file using ASPOSE.Slides. I am trying to a embed font using Aspose, but it's not working because of some issues. Therefore i am searching for an alternative option to achieve the same functionality.
I want to embed my custom font in a .pptx file. Can you please provide suggestions for embedding fonts inside MS Power Point using Apache poi or other.
Please don't give the answers for static or local system.
As it was stated above you can do it easily without Apache.
Official site
You can view/add/delete the font by accessing C:\Windows\Fonts
#Bhagyashree,
Aspose.Slides allows you to embed the fonts inside presentation. I suggest you to please try using following sample code on your end to serve the purpose.
String dataDir = Utils.getDataDir(AddEmbeddedFonts.class);
Presentation pres=new Presentation(dataDir+"");
IFontData[] allFonts = pres.getFontsManager().getFonts();
IFontData[] embeddedFonts = pres.getFontsManager().getEmbeddedFonts();
for (IFontData font : except(allFonts, embeddedFonts))
{
pres.getFontsManager().addEmbeddedFont(font,EmbedFontCharacters.All);
}
pres.save("saved.pptx",SaveFormat.Pptx);
Please feel free to share if there is any issue incurring on your end.
I am working as Support developer/ Evangelist at Aspose.
With POI 4.1.0 (which will be released by approx. Feb. 2019), I've also added font embedding capabilities in Apache POI too. The provided methods are only the "half story", as you can't simply add .ttf/.otf files.
For the conversion of True-Type (.ttf) or Open-Type (.otf) fonts to Office-compatible EOT/MTX fonts, I'm using sfntly. The snftly classes aren't provided as maven artifacts yet and I don't like to import the whole chunk into POI nor release my repackaged version of googles code under my name, therefore you need to clone and adapt my example project.
For adding a MTX font stream to a slideshow (HSLF or XSLF, i.e. SlideShow is their common interface) you would call:
org.apache.poi.sl.usermodel.SlideShow.addFont(InputStream fontData)
For font subsetting, you would need the used codepoints, which can be extracted by:
org.apache.poi.sl.extractor.SlideShowExtractor.getCodepoints(String typeface, Boolean italic, Boolean bold)
For getting information about a MTX font data stream, there's a new helper class:
org.apache.poi.common.usermodel.fonts.FontHeader
I don't know how to change it with Apache, but you can easily change it with powerpoint ...

Javascript equivalent for the technique called behind editors like Nodes Editor of Blender

I need to know how this type of dynamic connections is called between the "nodes":
Image source: https://orange.blender.org/wp-content/themes/orange/images/blog/noodles.jpg
Also does someone know a javascript library for generating these nodes with connections?
This is called "Directed Acyclic Graph". You should have a look at the Raphaƫl Library. Especially this example.

Categories

Resources