GithubHelp home page GithubHelp logo

Comments (8)

Serthys avatar Serthys commented on June 15, 2024

Have you tried running the sample?
Here's the sample permalink.

from dxf-parser.

thedanieljk avatar thedanieljk commented on June 15, 2024

I'm able to get the sample working but can't get things to work in my liferay tomcat server.

from dxf-parser.

Serthys avatar Serthys commented on June 15, 2024

On the sample the parser is instanced like this:

var parser = new DxfParser();

Have you tried that?

from dxf-parser.

thedanieljk avatar thedanieljk commented on June 15, 2024

I've tried that, that gives me Uncaught ReferenceError: DxfParser is not defined at window.onload

For reference, the end goal is to securely display a dxf from a url using three-dxf. The sample that worked was from three-dxf.

from dxf-parser.

Serthys avatar Serthys commented on June 15, 2024

I managed to get a working example, I've never user javascript modules like this so it took me a while.

The index on the same is the same as the same here except for the import of the dxf-parser.js.
I load the dxf-parser.js on index.js, import de module there and set the window.DxfParser value so the index.hml can use it.
The dxf-parser.js on the sample is made by running npm run build with a change on the webpack.config.js. I changed the property libraryExport: 'default' to libraryExport: 'this'.

from dxf-parser.

thedanieljk avatar thedanieljk commented on June 15, 2024

Thank you very much for your help. I believe the issue came from my lack of understanding of webpack. Changing to libraryTarget:'this' appears to solve my problem.

Relevant code in case someone comes wants to read a dxf from a URL:

<script src="/html/portlet/document_library/js/dxf-parser.js"></script>
	<script type="text/javascript">
							var request = new XMLHttpRequest();
							var fileText;
							request.open('GET', document.getElementById('file_to_show').getAttribute('data-file-location'), true);
							request.responseType = 'blob';
							request.onload = function() {
							    var reader = new FileReader();
							    reader.readAsDataURL(request.response);
							    reader.onload =  function(e){
							        fileText = e.target.result;
							        fileText = atob(fileText.substr(fileText.indexOf(',')+1));
							        var parser = new window.DxfParser();
									var dxf = null;
									try {
										dxf = parser.parseSync(fileText);
									} catch(err) {
										return console.error(err.stack);
									}
									console.log('Success!');
									console.log("DXF JSON:" + JSON.stringify(dxf,null,4));```

from dxf-parser.

Serthys avatar Serthys commented on June 15, 2024

You are welcome, remember to close the issue if it's already solved.

from dxf-parser.

bzuillsmith avatar bzuillsmith commented on June 15, 2024

Thanks for helping with this @Serthys

I was last working toward modularizing this library to work better with react, angular or other module-oriented libraries. Sorry I have not been very responsive. Been a bit overwhelmed between work and moving. :)

from dxf-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.