Skip to content

Commit 6faa270

Browse files
committed
999358-ug: Added feedback changes.
1 parent bcbd5c2 commit 6faa270

10 files changed

Lines changed: 173 additions & 564 deletions

File tree

Binary file not shown.

Document-Processing/PDF/PDF-Library/javascript/FormFields.md

Lines changed: 90 additions & 521 deletions
Large diffs are not rendered by default.

Document-Processing/PDF/PDF-Library/javascript/HyperLinks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This example demonstrates how to create a web link annotation in a PDF document
1515

1616
{% tabs %}
1717
{% highlight typescript tabtitle="TypeScript" %}
18-
import { PdfDocument, PdfPage, PdfStringFormat, PdfStandardFont, PdfFontFamily, PdfTextWebLinkAnnotation, PdfFontStyle } from '@syncfusion/ej2-pdf';
18+
import { PdfDocument, PdfPage, PdfStringFormat, PdfStandardFont, PdfFontFamily, PdfTextWebLinkAnnotation, PdfFontStyle, Size } from '@syncfusion/ej2-pdf';
1919

2020
// Load an existing PDF document
2121
let document: PdfDocument = new PdfDocument();

Document-Processing/PDF/PDF-Library/javascript/Image-Extraction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This code demonstrates how to extract embedded images and their metadata from a
1717

1818
{% tabs %}
1919
{% highlight typescript tabtitle="TypeScript" %}
20-
import { PdfDocument } from '@syncfusion/ej2-pdf';
20+
import { PdfDocument, Size } from '@syncfusion/ej2-pdf';
2121
import { PdfDataExtractor, PdfEmbeddedImage} from '@syncfusion/ej2-pdf-data-extract';
2222

2323
// Load an existing PDF document

Document-Processing/PDF/PDF-Library/javascript/Images.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ let document: PdfDocument = new PdfDocument(data);
7070
let page: PdfPage = document.getPage(0);
7171
// Get graphics from the page
7272
let graphics: PdfGraphics = page.graphics;
73-
// Load the image (base64 / uint8array)
73+
// Load the image (base64 / Uint8Array)
7474
let image: PdfImage = new PdfBitmap('/9j/4AAQSkZJRgABAQEAkACQAAD/4....QB//Z');
7575
// Draw the image.
7676
image.draw(graphics, { x: 10, y: 10});

Document-Processing/PDF/PDF-Library/javascript/PDF-pages.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ document.destroy();
6666
// Create a new PDF document
6767
var document = new ej.pdf.PdfDocument();
6868
// Define page settings with margins
69-
var settings = new ej.pdf.PdfPageSettings({margins: new PdfMargins(50)});
69+
var settings = new ej.pdf.PdfPageSettings({margins: new ej.pdf.PdfMargins(50)});
7070
// Add a page
7171
var page = document.addPage(settings);
7272
// Save the document
@@ -106,9 +106,7 @@ const page1: PdfPage = section1.addPage();
106106
const g1: PdfGraphics = page1.graphics;
107107
const rectPen = new PdfPen({ r: 0, g: 0, b: 0 }, 1); // black 1pt outline
108108
g1.drawRectangle({ x: 60, y: 80, width: 200, height: 120 }, rectPen);
109-
// SECTION 1: Second page draw rectangle (A4 landscape)
110-
const section2: PdfSection = document.addSection(settingsA4Portrait);
111-
const page2: PdfPage = section2.addPage();
109+
const page2: PdfPage = section1.addPage();
112110
const g2: PdfGraphics = page2.graphics;
113111
g2.drawRectangle({ x: 80, y: 100, width: 250, height: 150 }, rectPen);
114112
//Prepare font once for text pages
@@ -118,9 +116,9 @@ const font: PdfStandardFont = document.embedFont(
118116
PdfFontStyle.regular
119117
);
120118
const textBrush = new PdfBrush({ r: 0, g: 0, b: 0 }); // black text
121-
// SECTION 3: Third page draw string (A5 portrait, 30pt margins)
122-
const section3: PdfSection = document.addSection(settingsA5Portrait);
123-
const page3: PdfPage = section3.addPage();
119+
// SECTION 2: Third page draw string (A5 portrait, 30pt margins)
120+
const section2: PdfSection = document.addSection(settingsA5Portrait);
121+
const page3: PdfPage = section2.addPage();
124122
const g3: PdfGraphics = page3.graphics;
125123
g3.drawString(
126124
'Hello from A5 Portrait with 30pt margins!',
@@ -129,16 +127,14 @@ g3.drawString(
129127
textBrush,
130128
new PdfStringFormat(PdfTextAlignment.left)
131129
);
132-
// SECTION 4: Fourth page draw string (A5 portrait, 30pt margins)
133-
const section4: PdfSection = document.addSection(settingsA5Portrait);
134-
const page4: PdfPage = section4.addPage();
130+
const page4: PdfPage = section2.addPage();
135131
const g4: PdfGraphics = page4.graphics;
136132
g4.drawString(
137133
'Hello from A5 Portrait with 30pt margins!',
138134
font,
139135
{ x: 60, y: 90, width: 400, height: 50 },
140136
textBrush,
141-
new PdfStringFormat(PdfTextAlignment.left)
137+
new PdfStringFormat(PdfTextAlignment.left)
142138
);
143139
// Save the PDF
144140
document.save('Output.pdf');
@@ -307,7 +303,7 @@ document.destroy();
307303
{% endhighlight %}
308304
{% endtabs %}
309305

310-
## Rotating a PDF page
306+
## Add rotated PDF pages
311307

312308
This example demonstrates how to rotate a PDF page using the `rotation` property of the `PdfPageSettings` class. The property accepts a value from the `PdfRotationAngle` enumeration, such as angle180, to specify the rotation angle applied to the page.
313309

@@ -391,7 +387,7 @@ document.destroy();
391387
{% endhighlight %}
392388
{% endtabs %}
393389

394-
## Insert a duplicate Page at a specific index
390+
## Insert a duplicate page at a specific index
395391

396392
Duplicates a page from a source PDF and inserts it into the destination document at the specified index using `PdfPageImportOptions.targetIndex`. This is useful for reusing or cloning content across documents or within the same document.
397393

Document-Processing/PDF/PDF-Library/javascript/Split-Documents.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The PDF library allows splitting the pages of an existing PDF document into mult
1717
{% tabs %}
1818
{% highlight typescript tabtitle="TypeScript" %}
1919
import { PdfDocument, PdfDocumentSplitEventArgs} from '@syncfusion/ej2-pdf';
20+
import { Save } from '@syncfusion/ej2-file-utils';
2021

2122
// Load an existing PDF document
2223
let document: PdfDocument = new PdfDocument(data);

Document-Processing/PDF/PDF-Library/javascript/Text-Extraction.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,22 @@ let document: PdfDocument = new PdfDocument(data);
141141
let extractor: PdfDataExtractor = new PdfDataExtractor(document);
142142
// Extract `TextLine` from the PDF document.
143143
let textLines: Array<TextLine> = extractor.extractTextLines({ startPageIndex: 0, endPageIndex: document.pageCount-1});
144+
// Iterate through each text line in the collection
144145
textLines.forEach((textLine: TextLine) => {
145-
// Gets the bounds of the text line.
146-
let lineBounds: Rectangle = textLine.bounds;
146+
// Gets the bounds of the text line.
147+
let lineBounds: Rectangle = textLine.bounds;
148+
// Gets the single line of extracted text from the PDF page.
149+
let line: string = textLine.text;
150+
// Gets the page index of the text line extracted.
151+
let pageIndex: number = textLine.pageIndex;
152+
// Gets the collection of text words extracted from a specified page in a PDF document.
153+
let words: TextWord[] = textLine.words;
154+
// Gets the name of the font used for a particular line of text.
155+
let fontName: string = textLine.fontName;
156+
// Gets the font style used for a particular line of text.
157+
let fontStyle: PdfFontStyle = textLine.fontStyle;
158+
// Gets the font size used for a particular line of text.
159+
let fontSize: number = textLine.fontSize;
147160
});
148161
// Save the document
149162
document.save('output.pdf');
@@ -159,9 +172,22 @@ var document = new ej.pdf.PdfDocument(data);
159172
var extractor = new ej.pdfdataextract.PdfDataExtractor(document);
160173
// Extract `TextLine` from the PDF document.
161174
var textLines = extractor.extractTextLines({ startPageIndex: 0, endPageIndex: document.pageCount-1});
175+
// Iterate through each text line in the collection
162176
textLines.forEach((textLine) => {
163-
// Gets the bounds of the text line.
164-
var lineBounds = textLine.bounds;
177+
// Gets the bounds of the text line.
178+
var lineBounds = textLine.bounds;
179+
// Gets the single line of extracted text from the PDF page.
180+
var line = textLine.text;
181+
// Gets the page index of the text line extracted.
182+
var pageIndex = textLine.pageIndex;
183+
// Gets the collection of text words extracted from a specified page in a PDF document.
184+
var words = textLine.words;
185+
// Gets the name of the font used for a particular line of text.
186+
var fontName = textLine.fontName;
187+
// Gets the font style used for a particular line of text.
188+
var fontStyle = textLine.fontStyle;
189+
// Gets the font size used for a particular line of text.
190+
var fontSize = textLine.fontSize;
165191
});
166192
// Save the document
167193
document.save('output.pdf');

Document-Processing/PDF/PDF-Library/javascript/Text.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ let page: PdfPage = document.addPage();
6767
// Get graphics from the page
6868
let graphics: PdfGraphics = page.graphics;
6969
// Save the current graphics state and apply transformations
70-
graphics.save();
70+
let state: PdfGraphicsState = graphics.save();
7171
graphics.translateTransform({ x: 100, y: 50});
7272
graphics.rotateTransform(45);
7373
// Set font
7474
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 10, PdfFontStyle.regular);
7575
// Draw text
7676
graphics.drawString('Hello World', font, { x: 10, y: 20, width: 100, height: 200}, new PdfBrush({r: 0, g: 0, b: 255}));
77+
// Restore the graphics state
78+
graphics.restore(state);
7779
// Save the document
7880
document.save('Output.pdf');
7981
// Close the document
@@ -87,13 +89,15 @@ var page = document.addPage();
8789
// Get graphics from the page
8890
var graphics = page.graphics;
8991
// Save the current graphics state and apply transformations
90-
graphics.save();
92+
var state = graphics.save();
9193
graphics.translateTransform({ x: 100, y: 50 });
9294
graphics.rotateTransform(45);
9395
// Set font
9496
var font = document.embedFont(ej.pdf.PdfFontFamily.helvetica, 10, ej.pdf.PdfFontStyle.regular);
9597
// Draw text
9698
graphics.drawString('Hello World', font, { x: 10, y: 20, width: 100, height: 200 }, new ej.pdf.PdfBrush({ r: 0, g: 0, b: 255 }));
99+
// Restore the graphics state
100+
graphics.restore(state);
97101
// Save the document
98102
document.save('Output.pdf');
99103
// Close the document
@@ -159,7 +163,7 @@ let document: PdfDocument = new PdfDocument();
159163
// Add a page
160164
let page: PdfPage = document.addPage();
161165
// Set font
162-
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 10);
166+
let font: PdfStandardFont = document.embedFont(PdfFontFamily.helvetica, 10, PdfFontStyle.regular);
163167
// Draw text
164168
page.graphics.drawString('Hello World', font, { x: 10, y: 20, width: 100, height: 200}, new PdfBrush({r: 0, g: 0, b: 255}));
165169
// Save the document
@@ -173,7 +177,7 @@ var document = new ej.pdf.PdfDocument();
173177
// Add a page
174178
var page = document.addPage();
175179
// Set font
176-
var font = document.embedFont(ej.pdf.PdfFontFamily.helvetica, 10);
180+
var font = document.embedFont(ej.pdf.PdfFontFamily.helvetica, 10, ej.pdf.PdfFontStyle.regular);
177181
// Draw text
178182
page.graphics.drawString('Hello World', font, { x: 10, y: 20, width: 100, height: 200 }, new ej.pdf.PdfBrush({ r: 0, g: 0, b: 255 }));
179183
// Save the document
@@ -233,7 +237,7 @@ let document: PdfDocument = new PdfDocument();
233237
// Add a page
234238
let page: PdfPage = document.addPage();
235239
// Set font
236-
let font: PdfCjkStandardFont = document.embedFont(PdfCjkFontFamily.heiseiMinchoW3, 10);
240+
let font: PdfCjkStandardFont = document.embedFont(PdfCjkFontFamily.heiseiMinchoW3, 10, PdfFontStyle.regular);
237241
// Draw text
238242
page.graphics.drawString('こんにちは世界', font, { x: 10, y: 20, width: 100, height: 200}, new PdfBrush({r: 0, g: 0, b: 255}));
239243
// Save the document
@@ -247,7 +251,7 @@ var document = new ej.pdf.PdfDocument();
247251
// Add a page
248252
var page = document.addPage();
249253
// Set font
250-
var font = document.embedFont(ej.pdf.PdfCjkFontFamily.heiseiMinchoW3, 10);
254+
var font = document.embedFont(ej.pdf.PdfCjkFontFamily.heiseiMinchoW3, 10, ej.pdf.PdfFontStyle.regular);
251255
// Draw text
252256
page.graphics.drawString('こんにちは世界', font, { x: 10, y: 20, width: 100, height: 200 }, new ej.pdf.PdfBrush({ r: 0, g: 0, b: 255 }));
253257
// Save the document

Document-Processing/PDF/PDF-Library/javascript/Watermarks.md

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -333,17 +333,23 @@ Remove a watermark annotation from the page's annotation collection using the `P
333333
{% tabs %}
334334
{% highlight typescript tabtitle="TypeScript" %}
335335
import { PdfDocument, PdfPage, PdfAnnotation} from '@syncfusion/ej2-pdf';
336-
337336
// Load an existing PDF document
338337
let document: PdfDocument = new PdfDocument(data);
339-
// Access first page
340-
let page: PdfPage = document.getPage(0);
341-
// Get the first annotation is a watermark
342-
let annotation: PdfAnnotation = page.annotations.at(0);
343-
// Remove an annotation
344-
page.annotations.remove(annotation);
345-
// Removes an annotation from the page at the specified index
346-
page.annotations.removeAt(1);
338+
// Loop through all pages in the PDF document
339+
for (let pageIndex = 0; pageIndex < document.pageCount; pageIndex++) {
340+
// Get the current page by its index
341+
const page: PdfPage = document.getPage(pageIndex);
342+
// Iterate through the annotations on the page in reverse order
343+
for (let i: number = page.annotations.count - 1; i >= 0; i--) {
344+
// Get the annotation at the current index
345+
const annotation: PdfAnnotation = page.annotations.at(i);
346+
// Check if the annotation is a watermark annotation
347+
if (annotation instanceof PdfWatermarkAnnotation) {
348+
// Remove the watermark annotation from the page
349+
page.annotations.removeAt(i);
350+
}
351+
}
352+
}
347353
// Save the document
348354
document.save('output.pdf');
349355
// Destroy the document
@@ -354,14 +360,21 @@ document.destroy();
354360

355361
// Load an existing PDF document
356362
var document = new ej.pdf.PdfDocument(data);
357-
// Access first page
358-
var page = document.getPage(0);
359-
// Get the first annotation is a watermark
360-
var annotation = page.annotations.at(0);
361-
// Remove an annotation
362-
page.annotations.remove(annotation);
363-
// Removes an annotation from the page at the specified index
364-
page.annotations.removeAt(1);
363+
// Loop through all pages in the PDF document
364+
for (var pageIndex = 0; pageIndex < document.pageCount; pageIndex++) {
365+
// Get the current page by its index
366+
var page = document.getPage(pageIndex);
367+
// Iterate through the annotations on the page in reverse order
368+
for (var i = page.annotations.count - 1; i >= 0; i--) {
369+
// Get the annotation at the current index
370+
var annotation = page.annotations.at(i);
371+
// Check if the annotation is a watermark annotation
372+
if (annotation instanceof ej.pdf.PdfWatermarkAnnotation) {
373+
// Remove the watermark annotation from the page
374+
page.annotations.removeAt(i);
375+
}
376+
}
377+
}
365378
// Save the document
366379
document.save('output.pdf');
367380
// Destroy the document

0 commit comments

Comments
 (0)