diff --git a/Document-Processing/PDF/PDF-Library/javascript/Annotations.md b/Document-Processing/PDF/PDF-Library/javascript/Annotations.md index 3e7366ed3..099a8f047 100644 --- a/Document-Processing/PDF/PDF-Library/javascript/Annotations.md +++ b/Document-Processing/PDF/PDF-Library/javascript/Annotations.md @@ -22,7 +22,7 @@ let document: PdfDocument = new PdfDocument(); // Adds a new page to the PDF let page: PdfPage = document.addPage(); // Creates a new popup annotation -let popup = new PdfPopupAnnotation( +let popup: PdfPopupAnnotation = new PdfPopupAnnotation( 'Test popup annotation', { x: 10, y: 40, width: 30, height: 30 }, { @@ -42,6 +42,7 @@ document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Creates a new PDF document var document = new ej.pdf.PdfDocument(); // Adds a new page to the PDF @@ -76,7 +77,7 @@ let document: PdfDocument = new PdfDocument(data); // Access the first page let page: PdfPage = document.getPage(0); // Creates a new popup annotation -let popup = new PdfPopupAnnotation( +let popup: PdfPopupAnnotation = new PdfPopupAnnotation( 'Test popup annotation', { x: 10, y: 40, width: 30, height: 30 }, { @@ -96,6 +97,7 @@ document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -134,7 +136,7 @@ let document: PdfDocument = new PdfDocument(); // Adds a new page to the PDF let page: PdfPage = document.addPage(); // Creates a file link annotation -let fileLink = new PdfFileLinkAnnotation( +let fileLink: PdfFileLinkAnnotation = new PdfFileLinkAnnotation( { x: 100, y: 150, width: 120, height: 18 }, 'logo.png', { @@ -142,7 +144,7 @@ let fileLink = new PdfFileLinkAnnotation( author: 'Syncfusion', subject: 'File Link Annotation', color: { r: 0, g: 0, b: 255 }, - action: "app.alert('Launching file');" + action: "app.alert('Launching file')" }); // Adds annotation to the page page.annotations.add(fileLink); @@ -153,6 +155,7 @@ document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Creates a new PDF document var document = new ej.pdf.PdfDocument(); // Adds a new page to the PDF @@ -163,7 +166,7 @@ text:'Open attachment', author:'Syncfusion', subject:'File Link Annotation', color:{r:0,g:0,b:255}, -action:"app.alert('Launching file');" +action:"app.alert('Launching file')" }); // Adds annotation to the page page.annotations.add(fileLink); @@ -186,7 +189,7 @@ let document: PdfDocument = new PdfDocument(data); // Access the first page let page: PdfPage = document.getPage(0); // Creates a file link annotation -let fileLink = new PdfFileLinkAnnotation( +let fileLink: PdfFileLinkAnnotation = new PdfFileLinkAnnotation( { x: 100, y: 150, width: 120, height: 18 }, 'logo.png', { @@ -194,7 +197,7 @@ let fileLink = new PdfFileLinkAnnotation( author: 'Syncfusion', subject: 'File Link Annotation', color: { r: 0, g: 0, b: 255 }, - action: "app.alert('Launching file');" + action: "app.alert('Launching file')" }); // Adds annotation to the page page.annotations.add(fileLink); @@ -205,6 +208,7 @@ document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -215,7 +219,7 @@ text:'Open attachment', author:'Syncfusion', subject:'File Link Annotation', color:{r:0,g:0,b:255}, -action:"app.alert('Launching file');" +action:"app.alert('Launching file')" }); // Adds annotation to the page page.annotations.add(fileLink); @@ -240,7 +244,7 @@ let document: PdfDocument = new PdfDocument(); // Adds a new page to the PDF let page: PdfPage = document.addPage(); // Create new free text annotation -let freeText = new PdfFreeTextAnnotation({ x: 250, y: 260, width: 180, height: 80 }, +let freeText: PdfFreeTextAnnotation = new PdfFreeTextAnnotation({ x: 250, y: 260, width: 180, height: 80 }, { text: 'Free Text with Callout', annotationIntent: PdfAnnotationIntent.freeTextCallout, @@ -263,6 +267,7 @@ document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Creates a new PDF document var document = new ej.pdf.PdfDocument(); // Adds a new page to the PDF @@ -302,7 +307,7 @@ let document: PdfDocument = new PdfDocument(data); // Access the first page let page: PdfPage = document.getPage(0); // Create new free text annotation -let freeText = new PdfFreeTextAnnotation({ x: 250, y: 260, width: 180, height: 80 }, +let freeText: PdfFreeTextAnnotation = new PdfFreeTextAnnotation({ x: 250, y: 260, width: 180, height: 80 }, { text: 'Free Text with Callout', annotationIntent: PdfAnnotationIntent.freeTextCallout, @@ -325,6 +330,7 @@ document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -388,6 +394,7 @@ document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Creates a new PDF document var document = new ej.pdf.PdfDocument(); // Adds a new page to the PDF @@ -548,6 +555,7 @@ document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -580,7 +588,7 @@ let document: PdfDocument = new PdfDocument(); // Add a new page to the PDF let page: PdfPage = document.addPage(); // Create an ink annotation -let annotation = new PdfInkAnnotation( +let annotation: PdfInkAnnotation = new PdfInkAnnotation( { x: 50, y: 100, width: 200, height: 150 }, [ { x: 60, y: 120 }, @@ -610,12 +618,13 @@ let annotation = new PdfInkAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Create a new PDF document var document = new ej.pdf.PdfDocument(); // Add a new page to the PDF @@ -640,7 +649,7 @@ var annotation = new ej.pdf.PdfInkAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -658,7 +667,7 @@ let document: PdfDocument = new PdfDocument(data); // Access the first page let page: PdfPage = document.getPage(0); // Create an ink annotation -let annotation = new PdfInkAnnotation( +let annotation: PdfInkAnnotation = new PdfInkAnnotation( { x: 50, y: 100, width: 200, height: 150 }, [ { x: 60, y: 120 }, @@ -688,12 +697,13 @@ let annotation = new PdfInkAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -718,7 +728,7 @@ var annotation = new ej.pdf.PdfInkAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -738,7 +748,7 @@ let document: PdfDocument = new PdfDocument(); // Adds a new page to the PDF let page: PdfPage = document.addPage(); // Create a new popup annotation -let annotation = new PdfPopupAnnotation('Review this paragraph', +let annotation: PdfPopupAnnotation = new PdfPopupAnnotation('Review this paragraph', {x: 10, y: 40, width: 30, height: 30}, { author: 'Reviewer', @@ -753,12 +763,13 @@ let annotation = new PdfPopupAnnotation('Review this paragraph', // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Create a new PDF document var document = new ej.pdf.PdfDocument(); // Adds a new page to the PDF @@ -776,7 +787,7 @@ var annotation = new ej.pdf.PdfPopupAnnotation('Review this paragraph',{x:10,y:4 // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -793,7 +804,7 @@ import {PdfDocument, PdfPage, PdfPopupAnnotation, PdfPopupIcon, PdfAnnotationSta let document: PdfDocument = new PdfDocument(data); // Access the first page let page: PdfPage = document.getPage(0); -let annotation = new PdfPopupAnnotation('Review this paragraph', +let annotation: PdfPopupAnnotation = new PdfPopupAnnotation('Review this paragraph', {x: 10, y: 40, width: 30, height: 30}, { author: 'Reviewer', @@ -808,12 +819,13 @@ author: 'Reviewer', // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -831,7 +843,7 @@ var annotation = new ej.pdf.PdfPopupAnnotation('Review this paragraph',{x:10,y:4 // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -851,7 +863,7 @@ let document: PdfDocument = new PdfDocument(); // Adds a new page to the PDF let page: PdfPage = document.addPage(); // Create a new attachment annotation -let annotation = new PdfAttachmentAnnotation( +let annotation: PdfAttachmentAnnotation = new PdfAttachmentAnnotation( { x: 300, y: 200, width: 30, height: 30 }, 'Nature.jpg', imageData, @@ -861,12 +873,13 @@ let annotation = new PdfAttachmentAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Create a new PDF document var document = new ej.pdf.PdfDocument(); // Adds a new page to the PDF @@ -887,7 +900,7 @@ var annotation = new ej.pdf.PdfAttachmentAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -905,7 +918,7 @@ let document: PdfDocument = new PdfDocument(data); // Access the first page let page: PdfPage = document.getPage(0); // Create a new attachment annotation -let annotation = new PdfAttachmentAnnotation( +let annotation: PdfAttachmentAnnotation = new PdfAttachmentAnnotation( { x: 300, y: 200, width: 30, height: 30 }, 'Nature.jpg', imageData, @@ -915,12 +928,13 @@ let annotation = new PdfAttachmentAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -941,7 +955,7 @@ var annotation = new ej.pdf.PdfAttachmentAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -965,12 +979,13 @@ let annotation: PdfUriAnnotation = new PdfUriAnnotation({ x: 100, y: 150, width: // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Create a new PDF document var document = new ej.pdf.PdfDocument(); // Adds a new page to the PDF @@ -980,7 +995,7 @@ var annotation = new ej.pdf.PdfUriAnnotation({x:100,y:150,width:200,height:100}, // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -1002,12 +1017,13 @@ let annotation: PdfUriAnnotation = new PdfUriAnnotation({ x: 100, y: 150, width: // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -1017,7 +1033,7 @@ var annotation = new ej.pdf.PdfUriAnnotation({x:100,y:150,width:200,height:100}, // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -1037,9 +1053,9 @@ let document: PdfDocument = new PdfDocument(); // Adds a new page to the PDF let page: PdfPage = document.addPage(); // Create new document link annotation -let annotation = new PdfDocumentLinkAnnotation( +let annotation: PdfDocumentLinkAnnotation = new PdfDocumentLinkAnnotation( { x: 80, y: 100, width: 120, height: 18 }, - new PdfDestination({page, location: { x: 0, y: 0 }, mode: PdfDestinationMode.fitToPage}), + new PdfDestination(page, { x: 0, y: 0 }, {mode: PdfDestinationMode.fitToPage}), { color: { r: 0, g: 128, b: 0 }, opacity: 1, border: new PdfAnnotationBorder({ width: 1, hRadius: 0, vRadius: 0, style: PdfBorderStyle.solid })} @@ -1047,12 +1063,13 @@ color: { r: 0, g: 128, b: 0 }, opacity: 1, // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Create a new PDF document var document = new ej.pdf.PdfDocument(); // Adds a new page to the PDF @@ -1060,13 +1077,13 @@ var page = document.addPage(); // Create new document link annotation var annotation = new ej.pdf.PdfDocumentLinkAnnotation( {x:80,y:100,width:120,height:18}, - new ej.pdf.PdfDestination({page:page,location:{x:0,y:0},mode:ej.pdf.PdfDestinationMode.fitToPage}), + new ej.pdf.PdfDestination(page:page,{x:0,y:0},{mode:ej.pdf.PdfDestinationMode.fitToPage}), {color:{r:0,g:128,b:0},opacity:1,border:new ej.pdf.PdfAnnotationBorder({width:1,hRadius:0,vRadius:0,style:ej.pdf.PdfBorderStyle.solid})} ); // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -1086,7 +1103,7 @@ let page: PdfPage = document.getPage(0); // Create new document link annotation let annotation = new PdfDocumentLinkAnnotation( { x: 80, y: 100, width: 120, height: 18 }, - new PdfDestination({page, location: { x: 0, y: 0 }, mode: PdfDestinationMode.fitToPage}), + new PdfDestination(page, { x: 0, y: 0 }, { mode: PdfDestinationMode.fitToPage}), { color: { r: 0, g: 128, b: 0 }, opacity: 1, border: new PdfAnnotationBorder({ width: 1, hRadius: 0, vRadius: 0, style: PdfBorderStyle.solid })} @@ -1094,12 +1111,13 @@ color: { r: 0, g: 128, b: 0 }, opacity: 1, // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -1107,9 +1125,9 @@ var page = document.getPage(0); // Create new document link annotation var annotation = new ej.pdf.PdfDocumentLinkAnnotation( { x: 80, y: 100, width: 120, height: 18 }, - new ej.pdf.PdfDestination({ - page: page, - location: { x: 0, y: 0 }, + new ej.pdf.PdfDestination( + page, + { x: 0, y: 0 },{ mode: ej.pdf.PdfDestinationMode.fitToPage }), { @@ -1126,7 +1144,7 @@ var annotation = new ej.pdf.PdfDocumentLinkAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -1152,18 +1170,18 @@ borderColor: { r: 255, g: 0, b: 0}, repeatText: true, overlayText: 'Sample Overlay', font: document.embedFont(PdfFontFamily.helvetica, 10, PdfFontStyle.regular), - textColor: { r: 0, g: 0, b: 0}, - appearanceFillColor: { r: 255, g: 255, b: 255} + textColor: { r: 0, g: 0, b: 0} }); // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Create a new PDF document var document = new ej.pdf.PdfDocument(); // Adds a new page to the PDF @@ -1176,14 +1194,13 @@ var annotation = new ej.pdf.PdfRedactionAnnotation( repeatText: true, overlayText: 'Sample Overlay', font: document.embedFont(ej.pdf.PdfFontFamily.helvetica, 10, ej.pdf.PdfFontStyle.regular), - textColor: { r: 0, g: 0, b: 0 }, - appearanceFillColor: { r: 255, g: 255, b: 255 } + textColor: { r: 0, g: 0, b: 0 } } ); // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -1207,18 +1224,18 @@ borderColor: { r: 255, g: 0, b: 0}, repeatText: true, overlayText: 'Sample Overlay', font: document.embedFont(PdfFontFamily.helvetica, 10, PdfFontStyle.regular), - textColor: { r: 0, g: 0, b: 0}, - appearanceFillColor: { r: 255, g: 255, b: 255} + textColor: { r: 0, g: 0, b: 0} }); // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -1231,14 +1248,13 @@ var annotation = new ej.pdf.PdfRedactionAnnotation( repeatText: true, overlayText: 'Sample Overlay', font: document.embedFont(ej.pdf.PdfFontFamily.helvetica, 10, ej.pdf.PdfFontStyle.regular), - textColor: { r: 0, g: 0, b: 0 }, - appearanceFillColor: { r: 255, g: 255, b: 255 } + textColor: { r: 0, g: 0, b: 0 } } ); // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -1264,12 +1280,13 @@ annotation.color = { r: 0, g: 0, b: 0}; // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Create a new PDF document var document = new ej.pdf.PdfDocument(); // Adds a new page to the PDF @@ -1281,7 +1298,7 @@ annotation.color = { r: 0, g: 0, b: 0 }; // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -1305,12 +1322,13 @@ annotation.color = { r: 0, g: 0, b: 0}; // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -1322,7 +1340,7 @@ annotation.color = { r: 0, g: 0, b: 0 }; // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -1343,7 +1361,7 @@ let document: PdfDocument = new PdfDocument(); let page: PdfPage = document.addPage(); // Create a new text markup annotation // Create a new text markup annotation -let annotation = new PdfTextMarkupAnnotation('Water Mark', {x: 0, y: 0, width: 0, height: 0}, { +let annotation: PdfTextMarkupAnnotation = new PdfTextMarkupAnnotation('Water Mark', {x: 0, y: 0, width: 0, height: 0}, { boundsCollection: [{ x: 50, y: 200, width: 120, height: 14}, { x: 50, y: 215, width: 90, height: 14}], textMarkupType: PdfTextMarkupAnnotationType.underline, author: 'Syncfusion', subject: 'Annotation', textMarkUpColor: { r: 0, g: 128, b: 255}, innerColor: { r: 0, g: 0, b: 255}, opacity: 0.5, @@ -1352,12 +1370,13 @@ boundsCollection: [{ x: 50, y: 200, width: 120, height: 14}, { x: 50, y: 215, wi // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Create a new PDF document var document = new ej.pdf.PdfDocument(); // Adds a new page to the PDF @@ -1388,8 +1407,9 @@ var annotation = new ej.pdf.PdfTextMarkupAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document +document.destroy(); {% endhighlight %} {% endtabs %} @@ -1405,8 +1425,7 @@ let document: PdfDocument = new PdfDocument(data); // Access the first page let page: PdfPage = document.getPage(0); // Create a new text markup annotation -// Create a new text markup annotation -let annotation = new PdfTextMarkupAnnotation('Water Mark', {x: 0, y: 0, width: 0, height: 0}, { +let annotation: PdfTextMarkupAnnotation = new PdfTextMarkupAnnotation('Water Mark', {x: 0, y: 0, width: 0, height: 0}, { boundsCollection: [{ x: 50, y: 200, width: 120, height: 14}, { x: 50, y: 215, width: 90, height: 14}], textMarkupType: PdfTextMarkupAnnotationType.underline, author: 'Syncfusion', subject: 'Annotation', textMarkUpColor: { r: 0, g: 128, b: 255}, innerColor: { r: 0, g: 0, b: 255}, opacity: 0.5, @@ -1415,12 +1434,13 @@ boundsCollection: [{ x: 50, y: 200, width: 120, height: 14}, { x: 50, y: 215, wi // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -1451,7 +1471,7 @@ var annotation = new ej.pdf.PdfTextMarkupAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -1471,7 +1491,7 @@ let document: PdfDocument = new PdfDocument(); // Adds a new page to the PDF let page: PdfPage = document.addPage(); // Create a new rectangle annotation with bounds -let annotation = new PdfRectangleAnnotation({ x: 50, y: 80, width: 200, height: 100 }, { +let annotation: PdfRectangleAnnotation = new PdfRectangleAnnotation({ x: 50, y: 80, width: 200, height: 100 }, { text: 'Rect', author: 'Syncfusion', subject: 'Rectangle Annotation', color: { r: 255, g: 0, b: 0 }, innerColor: { r: 255, g: 240, b: 240 }, @@ -1481,12 +1501,13 @@ text: 'Rect', author: 'Syncfusion', subject: 'Rectangle Annotation', // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Create a new PDF document var document = new ej.pdf.PdfDocument(); // Adds a new page to the PDF @@ -1512,7 +1533,7 @@ var annotation = new ej.pdf.PdfRectangleAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -1530,7 +1551,7 @@ let document: PdfDocument = new PdfDocument(data); // Access the first page let page: PdfPage = document.getPage(0); // Create a new square annotation with bounds -let annotation = new PdfRectangleAnnotation({ x: 50, y: 80, width: 200, height: 100 }, { +let annotation: PdfRectangleAnnotation = new PdfRectangleAnnotation({ x: 50, y: 80, width: 200, height: 100 }, { text: 'Rect', author: 'Syncfusion', subject: 'Rectangle Annotation', color: { r: 255, g: 0, b: 0 }, innerColor: { r: 255, g: 240, b: 240 }, @@ -1540,12 +1561,13 @@ text: 'Rect', author: 'Syncfusion', subject: 'Rectangle Annotation', // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -1571,7 +1593,7 @@ var annotation = new ej.pdf.PdfRectangleAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -1591,7 +1613,7 @@ let document: PdfDocument = new PdfDocument(); // Adds a new page to the PDF let page: PdfPage = document.addPage(); // Create a new polygon annotation with bounds -let annotation = new PdfPolygonAnnotation( +let annotation: PdfPolygonAnnotation = new PdfPolygonAnnotation( [{ x: 100, y: 300 }, { x: 150, y: 200 }, { x: 300, y: 200 }, { x: 350, y: 300 }, { x: 300, y: 400 }, { x: 150, y: 400 }], { text: 'Polygon', author: 'Syncfusion', subject: 'Polygon Annotation', @@ -1603,12 +1625,13 @@ text: 'Polygon', author: 'Syncfusion', subject: 'Polygon Annotation', // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Create a new PDF document var document = new ej.pdf.PdfDocument(); // Adds a new page to the PDF @@ -1641,7 +1664,7 @@ var annotation = new ej.pdf.PdfPolygonAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -1659,7 +1682,7 @@ let document: PdfDocument = new PdfDocument(data); // Access the first page let page: PdfPage = document.getPage(0); // Create a new polygon annotation with bounds -let annotation = new PdfPolygonAnnotation( +let annotation: PdfPolygonAnnotation = new PdfPolygonAnnotation( [{ x: 100, y: 300 }, { x: 150, y: 200 }, { x: 300, y: 200 }, { x: 350, y: 300 }, { x: 300, y: 400 }, { x: 150, y: 400 }], { text: 'Polygon', author: 'Syncfusion', subject: 'Polygon Annotation', @@ -1671,12 +1694,13 @@ text: 'Polygon', author: 'Syncfusion', subject: 'Polygon Annotation', // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -1709,7 +1733,7 @@ var annotation = new ej.pdf.PdfPolygonAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -1729,7 +1753,7 @@ let document: PdfDocument = new PdfDocument(); // Adds a new page to the PDF let page: PdfPage = document.addPage(); // Create a new circle annotation with circle bounds -let annotation = new PdfCircleAnnotation({ x: 50, y: 100, width: 120, height: 120 }, { +let annotation: PdfCircleAnnotation = new PdfCircleAnnotation({ x: 50, y: 100, width: 120, height: 120 }, { text: 'Diameter', author: 'Syncfusion', color: { r: 255, g: 0, b: 0}, @@ -1741,12 +1765,13 @@ text: 'Diameter', // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Create a new PDF document var document = new ej.pdf.PdfDocument(); // Adds a new page to the PDF @@ -1773,7 +1798,7 @@ var annotation = new ej.pdf.PdfCircleAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document {% endhighlight %} @@ -1790,7 +1815,7 @@ let document: PdfDocument = new PdfDocument(data); // Access the first page let page: PdfPage = document.getPage(0); // Create a new circle annotation with circle bounds -let annotation = new PdfCircleAnnotation({ x: 50, y: 100, width: 120, height: 120 }, { +let annotation: PdfCircleAnnotation = new PdfCircleAnnotation({ x: 50, y: 100, width: 120, height: 120 }, { text: 'Diameter', author: 'Syncfusion', color: { r: 255, g: 0, b: 0}, @@ -1802,12 +1827,13 @@ text: 'Diameter', // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -1837,7 +1863,7 @@ var annotation = new ej.pdf.PdfCircleAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -1857,7 +1883,7 @@ let document: PdfDocument = new PdfDocument(); // Adds a new page to the PDF let page: PdfPage = document.addPage(); // Create a new ellipse annotation with bounds -let annotation = new PdfEllipseAnnotation({ x: 80, y: 120, width: 160, height: 100 }, { +let annotation: PdfEllipseAnnotation = new PdfEllipseAnnotation({ x: 80, y: 120, width: 160, height: 100 }, { text: 'Ellipse', author: 'Syncfusion', subject: 'Ellipse Annotation', color: { r: 0, g: 128, b: 255}, innerColor: { r: 220, g: 240, b: 255}, @@ -1867,12 +1893,13 @@ text: 'Ellipse', author: 'Syncfusion', subject: 'Ellipse Annotation', // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Create a new PDF document var document = new ej.pdf.PdfDocument(); // Adds a new page to the PDF @@ -1898,7 +1925,7 @@ var annotation = new ej.pdf.PdfEllipseAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -1916,7 +1943,7 @@ let document: PdfDocument = new PdfDocument(data); // Access the first page let page: PdfPage = document.getPage(0); // Create a new ellipse annotation with bounds -let annotation = new PdfEllipseAnnotation({ x: 80, y: 120, width: 160, height: 100 }, { +let annotation: PdfEllipseAnnotation = new PdfEllipseAnnotation({ x: 80, y: 120, width: 160, height: 100 }, { text: 'Ellipse', author: 'Syncfusion', subject: 'Ellipse Annotation', color: { r: 0, g: 128, b: 255}, innerColor: { r: 220, g: 240, b: 255}, @@ -1926,12 +1953,13 @@ text: 'Ellipse', author: 'Syncfusion', subject: 'Ellipse Annotation', // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -1957,7 +1985,7 @@ var annotation = new ej.pdf.PdfEllipseAnnotation( // Add annotation to the page page.annotations.add(annotation); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -1970,10 +1998,68 @@ This example demonstrates how to access a measurement annotation from a PDF page Common types of measurement annotations include: -* Line - Represents a straight distance between two points. -* Circle - Used to measure circular dimensions. -* Square - Defines rectangular or square measurements. -* Angle - Displays angular measurements between two intersecting lines. +* Line - Represents a straight distance between two points.(distance) +* Circle - Used to measure circular dimensions.(Radius) +* Square - Defines rectangular or square measurements.(Area) +* Angle - Displays angular measurements between two intersecting lines.(degrees) + +{% tabs %} +{% highlight typescript tabtitle="TypeScript" %} +import {PdfDocument, PdfPage, PdfLineAnnotation, PdfAnnotationLineEndingStyle, PdfLineEndingStyle, PdfAnnotationCaption, PdfLineCaptionType, PdfMeasurementUnit} from '@syncfusion/ej2-pdf'; + +// Creates a new PDF document +let document: PdfDocument = new PdfDocument(); +// Adds a new page to the PDF +let page: PdfPage = document.addPage(); +// Creates a new line annotation. +let lineAnnotation: PdfLineAnnotation = new PdfLineAnnotation({ x: 80, y: 420 }, { x: 150, y: 420 }, { + text: 'Line Annotation', + author: 'Syncfusion', + color: { r: 255, g: 0, b: 0 }, + innerColor: { r: 255, g: 255, b: 0 }, + lineEndingStyle: new PdfAnnotationLineEndingStyle({ begin: PdfLineEndingStyle.circle, end: PdfLineEndingStyle.diamond }), + opacity: 0.5, + measurementUnit: PdfMeasurementUnit.centimeter +}); +// Assigns the line caption type +lineAnnotation.caption = new PdfAnnotationCaption({ cap: true, type: PdfLineCaptionType.inline }); +// Adds annotation to the page +page.annotations.add(lineAnnotation); +// Saves and download the PDF document +document.save('output.pdf'); +// Destroy the document +document.destroy(); + +{% endhighlight %} +{% highlight javascript tabtitle="JavaScript" %} + +// Creates a new PDF document +var document = new ej.pdf.PdfDocument(); +// Adds a new page to the PDF +var page = document.addPage(); +// Creates a new line annotation. +var lineAnnotation = new ej.pdf.PdfLineAnnotation({x:80,y:420},{x:150,y:420},{ +text:'Line Annotation', +author:'Syncfusion', +color:{r:255,g:0,b:0}, +innerColor:{r:255,g:255,b:0}, +lineEndingStyle:new ej.pdf.PdfAnnotationLineEndingStyle({begin:ej.pdf.PdfLineEndingStyle.circle,end:ej.pdf.PdfLineEndingStyle.diamond}), +opacity:0.5, +measurementUnit: PdfMeasurementUnit.centimeter +}); +// Assigns the line caption type +lineAnnotation.caption = new ej.pdf.PdfAnnotationCaption({cap:true,type:ej.pdf.PdfLineCaptionType.inline}); +// Adds annotation to the page +page.annotations.add(lineAnnotation); +// Saves and download the PDF document +document.save('output.pdf'); +// Destroy the document +document.destroy(); + +{% endhighlight %} +{% endtabs %} + +The following code snippet explains how to add a measurement annotation in an existing PDF document. {% tabs %} {% highlight typescript tabtitle="TypeScript" %} @@ -1984,16 +2070,19 @@ let document: PdfDocument = new PdfDocument(data); // Access the first page let page: PdfPage = document.getPage(0); // Access the annotation at index 0 -let annotation: PdfLineAnnotation = page.annotations.at(0) PdfLineAnnotation; +let annotation: PdfLineAnnotation = page.annotations.at(0) as PdfLineAnnotation; // Sets the measurement unit of line measurement annoation as centimeter annotation.unit = PdfMeasurementUnit.centimeter; +// Sets the flag to have measurement dictionary of the line annotation. +annotation.measure = true; // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -2003,9 +2092,10 @@ var annotation = page.annotations.at(0); // Sets the measurement unit of line measurement annotation as centimeter if (annotation instanceof ej.pdf.PdfLineAnnotation) { annotation.unit = ej.pdf.PdfMeasurementUnit.centimeter; + annotation.measure = true; } // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -2028,16 +2118,16 @@ let page: PdfPage = document.getPage(0); let annotation: PdfPopupAnnotation = page.annotations.at(0) as PdfPopupAnnotation; // Modified its properties annotation.text = 'Popup annotation'; -annotation.color = { r: 0, g: 128, b: 255} -; +annotation.color = { r: 0, g: 128, b: 255}; annotation.opacity = 0.5; // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Access the first page @@ -2051,7 +2141,7 @@ if (annotation instanceof ej.pdf.PdfPopupAnnotation) { annotation.opacity = 0.5; } // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -2074,8 +2164,10 @@ let page: PdfPage = document.getPage(0); let annotation: PdfAnnotation = page.annotations.at(0); // Remove an annotation from the collection page.annotations.remove(annotation); +// Remove an annotation with specific index +page.annotations.removeAt(1); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -2089,8 +2181,10 @@ var page = document.getPage(0); var annotation = page.annotations.at(0); // Remove an annotation from the collection page.annotations.remove(annotation); +// Remove an annotation with specific index +page.annotations.removeAt(1); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); @@ -2134,58 +2228,67 @@ document.destroy(); {% endhighlight %} {% endtabs %} +N> Setting `document.flatten = true;` flattens all interactive elements in the PDF, converting form fields and annotations into static content throughout the entire document. + ## Importing annotations -This example demonstrates how to import annotations into a PDF document using the PdfDocument. `importAnnotations` method. +This example demonstrates how to import annotations into a PDF document using the PdfDocument. `importAnnotations` method. The DataFormat enum specifies the format of the annotation data being imported, such as FDF, XFDF, JSON, or XML. {% tabs %} {% highlight typescript tabtitle="TypeScript" %} import {PdfDocument, DataFormat} from '@syncfusion/ej2-pdf'; // Load the base PDF document from resources -let pdfDocument: PdfDocument = new PdfDocument(data); +let document: PdfDocument = new PdfDocument(data); // Imports annotations from to the PDF document. document.importAnnotations('annotations.json', DataFormat.json); // Save the PDF document -pdfDocument.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load the base PDF document from resources -var pdfDocument = new ej.pdf.PdfDocument(data); +var document = new ej.pdf.PdfDocument(data); // Import annotations into the PDF document -pdfDocument.importAnnotations('annotations.json', ej.pdf.DataFormat.json); +document.importAnnotations('annotations.json', ej.pdf.DataFormat.json); // Save the PDF document -pdfDocument.save('Output.pdf'); +document.save('output.pdf'); // Close the document -pdfDocument.destroy(); +document.destroy(); {% endhighlight %} {% endtabs %} ## Exporting annotations -This example demonstrates how to export annotations from a PDF document using the PdfDocument.exportAnnotations method. +This example demonstrates how to export annotations from a PDF document using the PdfDocument.exportAnnotations method. The DataFormat enum specifies the format of the annotation data being exported, such as FDF, XFDF, JSON, or XML. {% tabs %} {% highlight typescript tabtitle="TypeScript" %} -import {PdfDocument} from '@syncfusion/ej2-pdf'; +import {PdfDocument, PdfAnnotationExportSettings, DataFormat} from '@syncfusion/ej2-pdf'; // Load an existing PDF document let document: PdfDocument = new PdfDocument(data); -// Exports the annotations from the PDF document. -let data: Uint8Array = document.exportAnnotations(); -// Close the document +// Sets export data format as JSON for annotation export settings +let settings: PdfAnnotationExportSettings = new PdfAnnotationExportSettings(); +settings.dataFormat = DataFormat.json; +// Export annotations to JSON format +let jsonData = document.exportAnnotations('annotations.json', settings); +// Destroy the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); -// Export the annotations from the PDF document -var data = document.exportAnnotations(); +// Sets export data format as JSON for annotation export settings +var settings = new ej.pdf.PdfAnnotationExportSettings(); +settings.dataFormat = ej.pdf.DataFormat.json; +// Export annotations to JSON format +var jsonData = document.exportAnnotations('annotations.json', settings); // Close the document document.destroy(); diff --git a/Document-Processing/PDF/PDF-Library/javascript/Bookmarks.md b/Document-Processing/PDF/PDF-Library/javascript/Bookmarks.md index ed93592c3..e22d3e98f 100644 --- a/Document-Processing/PDF/PDF-Library/javascript/Bookmarks.md +++ b/Document-Processing/PDF/PDF-Library/javascript/Bookmarks.md @@ -7,101 +7,59 @@ documentation: UG --- # Bookmarks in JavaScript PDF library -Syncfusion® PDF provides support to insert, remove and modify the bookmarks in the PDF Document. +Syncfusion® PDF provides support to insert, remove, and modify the bookmarks in the PDF Document. -## Adding Bookmarks in a PDF +## Adding bookmarks to a PDF This example demonstrates how to add bookmarks to a PDF document using the `PdfBookmark` class. Bookmarks provide an easy way to navigate through different sections of a PDF file. {% tabs %} -{% highlight javascript tabtitle="TypeScript" %} -import {PdfDocument, PdfPage, PdfBookmarkBase, PdfDestination} from '@syncfusion/ej2-pdf'; +{% highlight typescript tabtitle="TypeScript" %} +import {PdfDocument, PdfPage, PdfBookmarkBase, PdfBookmark, PdfDestination} from '@syncfusion/ej2-pdf'; // Create a new PDF document let document: PdfDocument = new PdfDocument(); -// Add page +// Add a page let page: PdfPage = document.addPage(); // Get the bookmarks let bookmarks: PdfBookmarkBase = document.bookmarks; -// Add a new outline to the PDF document +// Add a new bookmark to the PDF document let bookmark: PdfBookmark = bookmarks.add('Introduction'); // Sets destination to the bookmark bookmark.destination = new PdfDestination(page, { x: 100, y: 200 }); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Create a new PDF document var document = new ej.pdf.PdfDocument(); -// Add page +// Add a page var page = document.addPage(); // Get the bookmarks var bookmarks = document.bookmarks; -// Add a new outline to the PDF document +// Add a new bookmark to the PDF document var bookmark = bookmarks.add('Introduction'); // Set destination to the bookmark bookmark.destination = new ej.pdf.PdfDestination(page, { x: 100, y: 200 }); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% endtabs %} -## Adding Bookmarks in an existing PDF document - -This example demonstrates how to add bookmarks to an existing PDF document using the `PdfBookmark` class. This allows you to enhance navigation in already created PDF document. - -{% tabs %} -{% highlight javascript tabtitle="TypeScript" %} -import {PdfDocument, PdfPage, PdfBookmarkBase, PdfDestination} from '@syncfusion/ej2-pdf'; - -// Load an existing PDF document -let document: PdfDocument = new PdfDocument(data); -// Get page -let page: PdfPage = document.getPage(0); -// Get the bookmarks -let bookmarks: PdfBookmarkBase = document.bookmarks; -// Gets the bookmark at the specified index -let bookmark: PdfBookmark = bookmarks.at(0) as PdfBookmark; -// Set the destination -bookmark.destination = new PdfDestination(page, { x: 100, y: 200 }); -// Save the document -document.save('Output.pdf'); -// Close the document -document.destroy(); - -{% endhighlight %} -{% highlight javascript tabtitle="JavaScript" %} -// Load an existing PDF document -var document = new ej.pdf.PdfDocument(data); -// Get page -var page = document.getPage(0); -// Get the bookmarks -var bookmarks = document.bookmarks; -// Get the bookmark at the specified index -var bookmark = bookmarks.at(0); -// Set the destination -bookmark.destination = new ej.pdf.PdfDestination(page, { x: 100, y: 200 }); -// Save the document -document.save('Output.pdf'); -// Close the document -document.destroy(); - -{% endhighlight %} -{% endtabs %} - -## Inserting Bookmarks in an existing PDF +## Inserting bookmarks into an existing PDF This example demonstrates how to insert bookmarks at a specific position in an existing PDF document using the `PdfBookmark` class. This feature allows precise control over bookmark order. {% tabs %} -{% highlight javascript tabtitle="TypeScript" %} -import {PdfDocument, PdfPage, PdfBookmarkBase, PdfDestination} from '@syncfusion/ej2-pdf'; +{% highlight typescript tabtitle="TypeScript" %} +import {PdfDocument, PdfPage, PdfBookmark, PdfBookmarkBase, PdfDestination} from '@syncfusion/ej2-pdf'; // Load an existing PDF document let document: PdfDocument = new PdfDocument(data); @@ -109,40 +67,41 @@ let document: PdfDocument = new PdfDocument(data); let page: PdfPage = document.getPage(0) as PdfPage; // Get the bookmarks let bookmarks: PdfBookmarkBase = document.bookmarks; -// Add a new outline to the PDF document +// Add a new bookmark at the specified bookmark index let bookmark: PdfBookmark = bookmarks.add('Introduction', 1); // Sets destination to the bookmark bookmark.destination = new PdfDestination(page, { x: 100, y: 200 }); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Get the first page var page = document.getPage(0); // Get the bookmarks var bookmarks = document.bookmarks; -// Add a new outline to the PDF document +// Add a new bookmark at the specified bookmark index var bookmark = bookmarks.add('Introduction', 1); // Set destination to the bookmark bookmark.destination = new ej.pdf.PdfDestination(page, { x: 100, y: 200 }); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% endtabs %} -## Removing Bookmarks from an existing PDF +## Removing bookmarks from an existing PDF This example demonstrates how to remove bookmarks from an existing PDF document using the `PdfBookmark` class. {% tabs %} -{% highlight javascript tabtitle="TypeScript" %} +{% highlight typescript tabtitle="TypeScript" %} import {PdfDocument, PdfPage, PdfBookmarkBase} from '@syncfusion/ej2-pdf'; // Load an existing PDF document @@ -154,12 +113,13 @@ let bookmarks: PdfBookmarkBase = document.bookmarks; // Remove specified bookmark from the document. bookmarks.remove('Introduction'); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Get the first page @@ -169,58 +129,55 @@ var bookmarks = document.bookmarks; // Remove specified bookmark from the document bookmarks.remove('Introduction'); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% endtabs %} -## Removing Bookmark from the document at the specified index +## Removing a bookmark from the document at a specified index This example demonstrates how to remove bookmarks from the document at the specific index using the `PdfBookmark` class. {% tabs %} -{% highlight javascript tabtitle="TypeScript" %} -import {PdfDocument, PdfPage, PdfBookmarkBase} from '@syncfusion/ej2-pdf'; +{% highlight typescript tabtitle="TypeScript" %} +import {PdfDocument, PdfBookmarkBase} from '@syncfusion/ej2-pdf'; // Load an existing PDF document let document: PdfDocument = new PdfDocument(data); -// Get the first page -let page: PdfPage = document.getPage(0) as PdfPage; // Get the bookmarks let bookmarks: PdfBookmarkBase = document.bookmarks; // Remove the bookmark from the document at the index 1. bookmarks.remove(1); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); -// Get the first page -var page = document.getPage(0); // Get the bookmarks var bookmarks = document.bookmarks; // Remove the bookmark from the document at index 1 bookmarks.remove(1); // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% endtabs %} -## Removing all the Bookmark from the collection +## Removing all bookmarks from the collection -This example demonstrates how to removes all the bookmarks from the collection using the `PdfBookmark` class. +This example demonstrates how to removes all bookmarks from the collection using the `PdfBookmark` class. {% tabs %} -{% highlight javascript tabtitle="TypeScript" %} +{% highlight typescript tabtitle="TypeScript" %} import {PdfDocument, PdfBookmarkBase} from '@syncfusion/ej2-pdf'; // Load an existing PDF document @@ -229,52 +186,56 @@ let document: PdfDocument = new PdfDocument(data); let bookmarks: PdfBookmarkBase = document.bookmarks; // Remove all the bookmark from the collection. bookmarks.clear(); -// Get count after removal of all outlines. +// // Get the count after removal of all bookmarks let count: number = bookmarks.count; // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Destroy the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Get the bookmarks var bookmarks = document.bookmarks; // Remove all the bookmarks from the collection bookmarks.clear(); -// Get count after removal of all outlines +// // Get the count after removal of all bookmarks var count = bookmarks.count; // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Destroy the document document.destroy(); {% endhighlight %} {% endtabs %} -## Bookmark page index in an existing PDF document +## Getting a bookmark's page index in an existing PDF document This example demonstrates how to retrieve the page index associated with a bookmark in an existing PDF document using the `PdfBookmark` class. This helps identify the exact location of the bookmark. {% tabs %} -{% highlight javascript tabtitle="TypeScript" %} +{% highlight typescript tabtitle="TypeScript" %} import {PdfDocument, PdfBookmarkBase} from '@syncfusion/ej2-pdf'; // Load an existing PDF document let document: PdfDocument = new PdfDocument(data); // Get bookmarks -let bookmarks: PdfBookmarkBase = document.bookmarks; -// Get bookmark at the specified index -let pageIndex: number = bookmarks.destination.pageIndex; +let bookmarks: PdfBookmarkBase = document.bookmarks; +// Get the first bookmark (or any specific one) +let bookmark = bookmarks.at(0); +// Get the page index of the bookmark's destination +let pageIndex: number = bookmark.destination.pageIndex; // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); {% endhighlight %} {% highlight javascript tabtitle="JavaScript" %} + // Load an existing PDF document var document = new ej.pdf.PdfDocument(data); // Get bookmarks @@ -284,7 +245,7 @@ var bookmark = bookmarks.at(0); // Get the page index of the bookmark's destination var pageIndex = bookmark.destination.pageIndex; // Save the document -document.save('Output.pdf'); +document.save('output.pdf'); // Close the document document.destroy(); diff --git a/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-angular.md b/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-angular.md index c9e755322..0c6aeb345 100644 --- a/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-angular.md +++ b/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-angular.md @@ -8,7 +8,7 @@ documentation: ug keywords: angular create pdf, angular generate pdf, angular pdf library, ej2 pdf angular, JavaScript --- -# Create or Generate PDF file in Angular application +# Create or generate PDF file in Angular application The Syncfusion® JavaScript PDF library is used to create, read, and edit PDF documents. This library also offers functionality to merge, split, stamp, fill forms, and secure PDF files. @@ -23,7 +23,7 @@ To install the latest Angular CLI globally use the following command. npm install -g @angular/cli ``` -N> Use the command **npm install --save @angular/cli@12.0.2** to install the Angular CLI version 12.0.2 +N> To install a specific Angular CLI version, use: **npm install --save @angular/cli@12.0.2** ## Create an Angular Application @@ -36,7 +36,7 @@ cd my-app ## Installing Syncfusion® JavaScript PDF package -All the available JS 2 packages are published in `npmjs.com` registry. +All Syncfusion® JS 2 packages are published in `npmjs.com` registry. * To install PDF component, use the following command. @@ -44,8 +44,14 @@ All the available JS 2 packages are published in `npmjs.com` registry. npm install @syncfusion/ej2-pdf --save ``` N> For data extraction features, you need to install the `@syncfusion/ej2-pdf-data-extract` package as an add-on. +* Copy the contents of the openjpeg folder from ./node_modules/@syncfusion/ej2-pdf-data-extract/dist to the public directory using the command: +```bash +cp -R ./node_modules/@syncfusion/ej2-pdf-data-extract/dist/openjpeg ./src/assets/openjpeg +``` +* Confirm that there is an `openjpeg` directory within your src/assets directory if you are extracting images from PDFs. +* Ensure your server serves .wasm files with the Content-Type: application/wasm MIME type (Angular dev server handles this by default; configure your production server accordingly). -## Create a PDF document using TypeScript +## Create a PDF document * Add a simple button to `app.component.html` and attach a click handler that uses the TypeScript PDF API to create a new PDF document. @@ -66,7 +72,7 @@ N> For data extraction features, you need to install the `@syncfusion/ej2-pdf-da {% tabs %} {% highlight ts tabtitle="~/app.component.ts" %} -import { PdfDocument, PdfPage, PdfStandardFont, PdfBrush } from '@syncfusion/ej2-pdf'; +import { PdfDocument, PdfGraphics, PdfPage, PdfFontFamily, PdfFontStyle, PdfFont, PdfBrush } from '@syncfusion/ej2-pdf'; {% endhighlight %} {% endtabs %} @@ -82,7 +88,7 @@ document.getElementById('normalButton').onclick = (): void => { // Get graphics from the page const graphics: PdfGraphics = page.graphics; // Set font - const font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 36, PdfFontStyle.regular); + const font: PdfFont = document.embedFont(PdfFontFamily.helvetica, 36, PdfFontStyle.regular); // Create a new black brush const brush = new PdfBrush({r: 0, g: 0, b: 0}); // Draw text @@ -99,7 +105,7 @@ document.getElementById('normalButton').onclick = (): void => { Use the following command to run the application in browser. -```javascript +```bash ng serve --open ``` diff --git a/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-asp-net-core.md b/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-asp-net-core.md index 7fa08b1cb..8affa95eb 100644 --- a/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-asp-net-core.md +++ b/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-asp-net-core.md @@ -10,11 +10,11 @@ keywords: .net core create pdf, edit pdf, merge, pdf form, fill form, digital si # Create or Generate PDF in ASP.NET Core -The Syncfusion® JavaScript PDF library is used to create, read, and edit PDF documents. This library also offers functionality to merge, split, stamp, forms, and secure PDF files. +The Syncfusion® JavaScript PDF library is used to create, read, and edit PDF documents. This library also offers functionality to merge, split, stamp, fill forms, and secure PDF files. This guide explains how to integrate the JavaScript PDF library into an ASP.NET Core application. -## Integrate PDF library into an ASP.NET Core application +## Integrate the PDF library into an ASP.NET Core application Step 1: Start Visual Studio and select **Create a new project**. Step 2: In the **Create a new project** dialog, select **ASP.NET Core Web App**. @@ -24,7 +24,7 @@ Step 3: In the **Configure your new project** dialog, enter the project name and Step 4: In the **Additional information** dialog, select a .NET LTS version (for example, **.NET 8.0 (Long-term Support)**) and then select **Create**. ![ASP.NET Core PDF creation3](Getting_started_images/Asp-net-core-creation3.png) -Step 5: **Add script reference** : Add the required scripts using the CDN inside the `` of `~/Views/Shared/_Layout.cshtml` as follows: +Step 5: **Add script reference**: Add the required scripts using the CDN inside the `` of `~/Views/Shared/_Layout.cshtml` as follows: {% tabs %} {% highlight cshtml tabtitle="~/_Layout.cshtml" %} @@ -39,12 +39,12 @@ N> Check out the following topics for including script references in an ASP.NET * [CDN](https://ej2.syncfusion.com/aspnetcore/documentation/common/adding-script-references#cdn-reference) * [NPM Package](https://ej2.syncfusion.com/aspnetcore/documentation/common/adding-script-references#node-package-manager-npm) * [CRG](https://ej2.syncfusion.com/aspnetcore/documentation/common/custom-resource-generator) -N> And ensure the application includes an `openjpeg` folder under `wwwroot` (or a publicly accessible static path). This folder must contain the `openjpeg.js` and `openjpeg.wasm` files, along with the PDF file to extract images. Keep these in the same static content area as `ej2.min.js`. +And ensure the application includes an `openjpeg` folder under `wwwroot` (or a publicly accessible static path). This folder must contain the `openjpeg.js` and `openjpeg.wasm` files, along with the PDF file to extract images. Keep these in the same static content area as `ej2.min.js`. -Step 6: **Create a PDF document** : Add the script in `~/Views/Home/Index.cshtml` by creating a button and attaching a click event that uses the JavaScript PDF API to generate a PDF document. +Step 6: **Create a PDF document**: Add the script in `~/Views/Home/Index.cshtml` by creating a button and attaching a click event that uses the JavaScript PDF API to generate a PDF document. {% tabs %} -{% highlight cshtml tabtitle="~/Index.cshtml" %} +{% highlight cshtml tabtitle="~/Views/Home/Index.cshtml" %}

Create PDF document

Click the button to generate and download a PDF.

@@ -66,7 +66,7 @@ Step 6: **Create a PDF document** : Add the script in `~/Views/Home/Index.cshtml // Draw text graphics.drawString('Hello World!!!', font, {x: 20, y: 20, width: graphics.clientSize.width - 20, height: 60}, brush); // Save and download PDF - pdf.save('Output.pdf'); + pdf.save('output.pdf'); // Destroy the PDF document instance pdf.destroy(); }); @@ -75,9 +75,9 @@ Step 6: **Create a PDF document** : Add the script in `~/Views/Home/Index.cshtml {% endhighlight %} {% endtabs %} -step 7: **Build the project** : Click on Build > Build Solution or press Ctrl + Shift + B to build the project. +step 7: **Build the project**: Click on Build > Build Solution or press Ctrl + Shift + B to build the project. -Step 8: **Run the project** : Click the Start button (green arrow) or press F5 to run the app. +Step 8: **Run the project**: Click the Start button (green arrow) or press F5 to run the app. By executing the program, you will generate the following PDF document. diff --git a/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-asp-net-mvc.md b/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-asp-net-mvc.md index ab4cfb54d..566b347bd 100644 --- a/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-asp-net-mvc.md +++ b/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-asp-net-mvc.md @@ -14,7 +14,7 @@ The Syncfusion® JavaScript PDF library is used to create, read, a This guide explains how to integrate the JavaScript PDF library into an ASP.NET Core MVC application. -## Integrate PDF library into an ASP.NET MVC application +## Integrate PDF library into an ASP.NET MVC Core application Step 1: Start Visual Studio and select **Create a new project**. Step 2: Create a new ASP.NET MVC Web Application project. @@ -24,7 +24,7 @@ Step 3: Choose the target framework. Step 4: Select Web Application pattern (MVC) for the project and then select **Create** button. ![ASP.NET Core MVC PDF creation3](Getting_started_images/Asp-net-mvc-creation3.png) -Step 5: **Add script reference** : Add the required scripts using the CDN inside the `` of `~/Views/Shared/_Layout.cshtml` as follows: +Step 5: **Add script reference**: Add the required scripts using the CDN inside the `` of `~/Views/Shared/_Layout.cshtml` as follows: {% tabs %} {% highlight cshtml tabtitle="~/_Layout.cshtml" %} @@ -36,9 +36,13 @@ Step 5: **Add script reference** : Add the required scripts using the CDN inside {% endhighlight %} {% endtabs %} -N> And ensure the application includes an `openjpeg` folder under `Scripts` (or a publicly accessible static path). This folder must contain the `openjpeg.js` and `openjpeg.wasm` files, along with the PDF file to extract images. Keep these in the same static content area as `ej2.min.js`. +N> Check out the following topics for including script references in an ASP.NET MVC application to enable PDF creation using the Syncfusion® JavaScript PDF library: +* [CDN](https://ej2.syncfusion.com/aspnetmvc/documentation/common/adding-script-references) +* [NPM Package](https://ej2.syncfusion.com/aspnetmvc/documentation/common/adding-script-references#node-package-manager-npm) +* [CRG](https://ej2.syncfusion.com/aspnetmvc/documentation/common/custom-resource-generator) +And ensure the application includes an `openjpeg` folder under `Scripts` (or a publicly accessible static path). This folder must contain the `openjpeg.js` and `openjpeg.wasm` files, along with the PDF file to extract images. Keep these in the same static content area as `ej2.min.js`. -Step 6: **Create a PDF document** : Add the script in `~/Views/Home/Index.cshtml` by creating a button and attaching a click event that uses the JavaScript PDF API to generate a PDF document. +Step 6: **Create a PDF document**: Add the script in `~/Views/Home/Index.cshtml` by creating a button and attaching a click event that uses the JavaScript PDF API to generate a PDF document. {% tabs %} {% highlight cshtml tabtitle="~/Index.cshtml" %} @@ -63,7 +67,7 @@ Step 6: **Create a PDF document** : Add the script in `~/Views/Home/Index.cshtml // Draw text graphics.drawString('Hello World!!!', font, {x: 20, y: 20, width: graphics.clientSize.width - 20, height: 60}, brush); // Save and download PDF - pdf.save('Output.pdf'); + pdf.save('output.pdf'); // Destroy the PDF document instance pdf.destroy(); }); @@ -72,10 +76,10 @@ Step 6: **Create a PDF document** : Add the script in `~/Views/Home/Index.cshtml {% endhighlight %} {% endtabs %} -Step 7: **Build the project** : Click on Build > Build Solution or press Ctrl + Shift + B to build the project. +Step 7: **Build the project**: Click on Build > Build Solution or press Ctrl + Shift + B to build the project. -Step 8: **Run the project** : Click the Start button (green arrow) or press F5 to run the app. +Step 8: **Run the project**: Click the Start button (green arrow) or press F5 to run the app. -By executing the program, you will generate the following PDF document. +When you run the application and click the button, it generates the following PDF document. ![ASP.NET Core MVC PDF output](Getting_started_images/Output.png) diff --git a/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-javascript.md b/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-javascript.md index a1c972f74..faff07cce 100644 --- a/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-javascript.md +++ b/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-javascript.md @@ -10,13 +10,13 @@ keywords: javascript, pdf, script # Create or Generate PDF file in JavaScript -The Syncfusion® JS 2 for JavaScript (global script) is an ES5 formatted pure JavaScript framework which can be directly used in latest web browsers. +Syncfusion® JS 2 (global script) is an ES5-formatted JavaScript library that works directly in modern web browsers. -## Component Initialization with CDN link for script and style reference +## Component initialization with CDN links -Step 1: Create an app folder `my-app` for the JS 2 JavaScript components. +Step 1: Create a folder named `my-app` for your project. -Step 2: The JS 2 component's global scripts and styles are already hosted in the below CDN link formats. +Step 2: The JS 2 global scripts and styles are hosted on the CDN in the following formats. **Syntax:** > Script: `https://cdn.syncfusion.com/ej2/{Version}/dist/{PACKAGE_NAME}.min.js` @@ -39,7 +39,12 @@ Step 3: Create a HTML page (index.html) in `my-app` location and add the CDN lin {% endhighlight %} {% endtabs %} -Step 4: **Create a PDF document** : Add the script in `index.html` by creating a button and attaching a click event that uses the JavaScript PDF API to generate a PDF document. +N> For image/data extraction features, install and deploy the openjpeg runtime. Place an openjpeg folder alongside your index.html (or any publicly accessible static path) containing: +* `openjpeg.js` +* `openjpeg.wasm` +Ensure your server serves .wasm files with the Content-Type: application/wasm MIME type. This is not required for basic PDF creation. + +Step 4: **Create a PDF document**: Add the script in `index.html` by creating a button and attaching a click event that uses the JavaScript PDF API to generate a PDF document. {% tabs %} {% highlight html tabtitle="~/Index.html" %} @@ -73,12 +78,6 @@ Step 4: **Create a PDF document** : Add the script in `index.html` by creating a {% endhighlight %} {% endtabs %} -N> For the JavaScript platform, place the **openjpeg** folder in the same location as your `index.html` file. Ensure that your application includes an `openjpeg` folder under `Scripts` (or any publicly accessible static path). This folder must contain the following: -* `openjpeg.js` -* `openjpeg.wasm` - -Along with the PDF file from which you want to extract images. Keep these files in the same static content area as `ej2.min.js` to ensure proper loading. - By executing the program, you will get the PDF document as follows. ![Output PDF document](Getting_started_images/Output.png) \ No newline at end of file diff --git a/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-react.md b/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-react.md index 7316f44d8..b22d7fefb 100644 --- a/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-react.md +++ b/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-react.md @@ -12,30 +12,29 @@ keywords: javascript, pdf, script, react The Syncfusion® JavaScript PDF library is used to create, read, and edit PDF documents. This library also offers functionality to merge, split, stamp, fill forms, and secure PDF files. -This guide explains how to integrate the JavaScript PDF library into an React application. +This guide explains how to integrate the JavaScript PDF library into a React application. ## Installing Syncfusion® JavaScript PDF package -All the available JS 2 packages are published in `npmjs.com` registry. +All Syncfusion JS 2 packages are published in `npmjs.com` registry. -* To install PDF component, use the following command. +* To install the PDF library, use the following command. ```bash npm install @syncfusion/ej2-pdf --save ``` -N> For data extraction features, you need to install the `@syncfusion/ej2-pdf-data-extract` package as an add-on. - +N> For image/data extraction features, you need to install the `@syncfusion/ej2-pdf-data-extract` package as an add-on. * Copy the contents of the openjpeg folder from ./node_modules/@syncfusion/ej2-pdf-data-extract/dist to the public directory using the command: ```bash cp -R ./node_modules/@syncfusion/ej2-pdf-data-extract/dist/openjpeg public/openjpeg ``` -* Confirm that there is an 'openjpeg' directory within your public directory, if you extracting images from PDF. -* Validate that your server has been configured to utilize the Content-Type: application/wasm MIME type. Additional information can be found in the [Troubleshooting](./troubleshooting/troubleshooting) section. +* Confirm that there is an 'openjpeg' directory within your public directory if you are extracting images from PDFs. +* Ensure your server serves .wasm files with the Content-Type: application/wasm MIME type. -**Create a PDF document** : Add the script in `App.jsx` by creating a button and attaching a click event that uses the JavaScript PDF API to generate a PDF document. +**Create a PDF document**: Add the script in `App.jsx` by creating a button and attaching a click event that uses the JavaScript PDF API to generate a PDF document. {% tabs %} -{% highlight jsx tabtitle="~/App.jsx" %} +{% highlight html tabtitle="~/App.jsx" %} import React from 'react'; export default function App() { diff --git a/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-typescript.md b/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-typescript.md index 10a2f269d..3edfd0016 100644 --- a/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-typescript.md +++ b/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-typescript.md @@ -14,16 +14,30 @@ The Syncfusion® TypeScript PDF library is used to create, read, a This guide explains how to integrate the TypeScript PDF library into an TypeScript application. +## Installing the Syncfusion TypeScript PDF package + +All Syncfusion JS 2 packages are published in `npmjs.com` registry. + +* To install the PDF library, use the following command. + +```bash +npm install @syncfusion/ej2-pdf --save +``` +N> For image/data extraction features, install the `@syncfusion/ej2-pdf-data-extract` add-on. Place an openjpeg folder alongside your built static assets (for example, under public or dist) containing: +* openjpeg.js +* openjpeg.wasm +Ensure your server serves .wasm files with the Content-Type: application/wasm MIME type. This is not required for basic PDF creation. + ## Dependencies The following list of dependencies are required to use the `TypeScript PDF library` component in your application. -```typescript +```text |-- @syncfusion/ej2-compression |-- @syncfusion/ej2-base ``` -## Create a PDF document using TypeScript. +## Create a PDF document using TypeScript * Add a simple button to `index.html` and attach a click handler that uses the TypeScript PDF API to create a new PDF document. @@ -40,17 +54,11 @@ The following list of dependencies are required to use the `TypeScript PDF libra {% endhighlight %} {% endtabs %} -N> For the TypeScript platform, place the **openjpeg** folder in the same location as your `index.html` file. Ensure that your application includes an `openjpeg` folder under `Scripts` (or any publicly accessible static path). This folder must contain the following: -* `openjpeg.js` -* `openjpeg.wasm` - -Along with the PDF file from which you want to extract images. Keep these files in the same static content area as `ej2.min.js` to ensure proper loading. - * Include the following namespaces in `index.ts` file. {% tabs %} {% highlight ts tabtitle="index.ts" %} -import { PdfDocument, PdfPage, PdfStandardFont, PdfFontFamily, PdfPen, PdfFontStyle, PdfBrush } from '@syncfusion/ej2-pdf'; +import { PdfDocument, PdfGraphics, PdfPage, PdfFont, PdfFontFamily, PdfFontStyle, PdfBrush } from '@syncfusion/ej2-pdf'; {% endhighlight %} {% endtabs %} @@ -66,13 +74,13 @@ document.getElementById('normalButton').onclick = (): void => { // Get graphics from the page let graphics: PdfGraphics = page.graphics; // Set font - let font: PdfStandardFont = pdf.embedFont(PdfFontFamily.helvetica, 36, PdfFontStyle.regular); + let font: PdfFont = pdf.embedFont(PdfFontFamily.helvetica, 36, PdfFontStyle.regular); // Create a new black brush let brush = new PdfBrush({r: 0, g: 0, b: 0}); // Draw text graphics.drawString('Hello World!!!', font, {x: 20, y: 20, width: graphics.clientSize.width - 20, height: 60}, brush); // Save and download PDF - pdf.save('Output.pdf'); + pdf.save('output.pdf'); // Destroy the PDF document instance pdf.destroy(); }; @@ -83,7 +91,7 @@ document.getElementById('normalButton').onclick = (): void => { The quickstart project is configured to compile and run in the browser. Use the following command to start the application: -```javascript +````bash npm start ``` diff --git a/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-vue.md b/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-vue.md index 49269bf01..262259ec3 100644 --- a/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-vue.md +++ b/Document-Processing/PDF/PDF-Library/javascript/Create-PDF-document-vue.md @@ -36,30 +36,29 @@ When creating a new project, choose the option `Default ([Vue 2] babel, es-lint) ![Vue 2 project](Getting_started_images/vue2-terminal.png) -Once the `quick start` project is set up with default settings, proceed to add Syncfusion® components to the project. +Once the `quick start` project is set up with default settings, proceed to add Syncfusion® components to the project. * **Installing Syncfusion® JavaScript PDF package** -All the available JS 2 packages are published in `npmjs.com` registry. +All Syncfusion JS 2 packages are published in `npmjs.com` registry. -* To install PDF component, use the following command. +* To install the PDF library, use the following command. ```bash npm install @syncfusion/ej2-pdf --save ``` -N> For data extraction features, you need to install the `@syncfusion/ej2-pdf-data-extract` package as an add-on. - +N> For image/data extraction features, you need to install the `@syncfusion/ej2-pdf-data-extract` package as an add-on. * Copy the contents of the openjpeg folder from ./node_modules/@syncfusion/ej2-pdf-data-extract/dist to the public directory using the command: ```bash cp -R ./node_modules/@syncfusion/ej2-pdf-data-extract/dist/openjpeg public/js/openjpeg ``` -* Confirm that there is an 'openjpeg' directory within your public directory, if you extracting images from PDF. -* Validate that your server has been configured to utilize the Content-Type: application/wasm MIME type. Additional information can be found in the [Troubleshooting](./troubleshooting/troubleshooting) section. +* Confirm that there is an 'openjpeg' directory within your public directory if you are extracting images from PDFs. +* Ensure your server serves .wasm files with the Content-Type: application/wasm MIME type. -* **Create a PDF document** : Add the script in `App.vue` by creating a button and attaching a click event that uses the JavaScript PDF API to generate a PDF document. +* **Create a PDF document**: Add the script in `App.vue` by creating a button and attaching a click event that uses the JavaScript PDF API to generate a PDF document. {% tabs %} -{% highlight vue tabtitle="~/App.vue" %} +{% highlight html tabtitle="~/App.vue" %}