Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: TextField is not a constructor #3041

Closed
kantsverma opened this issue Dec 18, 2020 · 5 comments
Closed

Uncaught TypeError: TextField is not a constructor #3041

kantsverma opened this issue Dec 18, 2020 · 5 comments

Comments

@kantsverma
Copy link

kantsverma commented Dec 18, 2020

Feature requests, bug reports etc. are very welcome as issues. But questions are directed to stackoverflow with the tag jspdf.

If you are facing issues with utf-8 characters, please refer to #2677.

Note that bug reports should follow these guidelines:

  1. A bug should be reported as an mcve
  2. Make sure code is properly indented and formatted (Use ``` around code blocks)
  3. Provide a runnable example.
  4. Try to make sure and show in your issue that the issue is actually related to jspdf and not your framework of choice your setup.

Below is my code you can run this.

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>jsPDF - AcroForm</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="description" content="">
	<meta name="author" content="">
	<!-- Latest compiled and minified CSS -->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
	<body>
		<div class="container">
			Test PDF <button onclick="generate()">GENERATE PDF </button>
		</div> <!-- /container -->
		<!-- Scripts down here -->
	    <script   src="http://raw.githack.com/MrRio/jsPDF/master/examples/js/jquery/jquery-1.7.1.min.js"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js" ></script>
		
		<script type="text/javascript">
		   function generate()
		   {
			console.log('Inside generate');
			const doc = new jsPDF('p', 'mm', 'a4');
			var TextField = jsPDF.AcroForm;	
			doc.text("TextField:", 10, 145);
			var textField = new TextField();
			textField.Rect = [50, 140, 30, 10];
			textField.multiline = true;
			textField.value =
			  "The quick brown fox ate the lazy mouse The quick brown fox ate the lazy mouse The quick brown fox ate the lazy mouse"; //
			textField.fieldName = "TestTextBox";
			doc.addField(textField);
			
			 doc.save('test.pdf');   
			/* global jsPDF */
		   }
		</script>
		<!-- Code editor -->

		<script src="http://raw.githack.com/MrRio/jsPDF/master/examples/js/ace.js" type="text/javascript" charset="utf-8"></script>

		<!-- Scripts in development mode -->
		<script src="http://raw.githack.com/MrRio/jsPDF/master/examples/js/pdfobject.min.js" ></script>
		<script src="http://raw.githack.com/MrRio/jsPDF/master/examples/js/editor.js" ></script>
	</body>
</html>

@kantsverma kantsverma changed the title Uncaught TypeError: jsPDF.AcroFormTextField is not a constructor Uncaught TypeError: TextField is not a constructor Dec 18, 2020
@HackbrettXXX
Copy link
Collaborator

If you read carefully: var TextField = jsPDF.AcroForm this can obviously not work. This should be var TextField = jsPDF.AcroForm.TextField;.

@kantsverma
Copy link
Author

kantsverma commented Dec 21, 2020

Thank you for your response but still not working you can try with above code. new error is "Uncaught TypeError: Cannot read property 'TextField' of undefined"

@HackbrettXXX
Copy link
Collaborator

I just saw you use a really old version of jsPDF. Please update to a 2.x version. This should fix the issue.

@kantsverma
Copy link
Author

@HackbrettXXX thank you i resolved that now i have problem with render html from html to pdf below code is not working.
var element = $('.product-single__description').html();
doc.html(element, {
callback: function (pdf) {
console.log('Inside callback');
doc.save('html.pdf');
},
x: 105,
y: 120
});

@HackbrettXXX
Copy link
Collaborator

Note that bug reports should follow these guidelines:

A bug should be reported as an mcve
Make sure code is properly indented and formatted (Use ``` around code blocks)
Provide a runnable example.
Try to make sure and show in your issue that the issue is actually related to jspdf and not your framework of choice your setup.

If you want us to help you please provide us with all the necessary information, such as: what exactly goes wrong? Are there any exceptions? Maybe attach the created PDF file. etc...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants