Skip to content

Commit 3fdd25b

Browse files
committed
994201-dev: Added 3 file changes.
1 parent 05c6c94 commit 3fdd25b

File tree

4 files changed

+101
-386
lines changed

4 files changed

+101
-386
lines changed
Lines changed: 34 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
---
2-
title: Working with EJ2 Images | Syncfusion
3-
description: This section explains how to add and replace images in the EJ2 PDF document using Essential PDF. It supports both raster and vector images.
2+
title: Working with Images | Syncfusion
3+
description: This section explains how to add and replace images in the PDF document using Essential PDF. It supports both raster and vector images.
44
platform: document-processing
55
control: PDF
66
documentation: UG
77
domainurl: ##DomainURL##
88
---
99

10-
# Working with EJ2 images using various options
10+
# Working with images using various options
1111

1212
Essential<sup>&reg;</sup> PDF supports both raster and vector images.
1313

14-
Images are supported through the `PdfImage` class, which is an abstract base class that provides the common functionality for `PdfBitmap` class.
14+
Images are supported through the `PdfImage` class, which is an abstract base class that provides the common functionality for `PdfBitmap` class.
1515

16-
## Inserting an EJ2 image in a new document
16+
## Inserting an image in a new document
1717

1818
The following raster images are supported in Essential<sup>&reg;</sup> PDF.
1919

@@ -30,44 +30,24 @@ The following raster images are supported in Essential<sup>&reg;</sup> PDF.
3030
This example demonstrates how to add an image to a PDF document using the `PdfBitmap` class and the `draw` method of the `PdfImage` class. The image is loaded from a file and drawn at the specified coordinates on the page.
3131

3232
{% tabs %}
33-
{% highlight ts tabtitle="index.ts" %}
33+
{% highlight c# tabtitle="TypeScript" %}
3434

35-
// Create and render button
36-
let button: Button = new Button();
37-
button.appendTo('#normalbtn');
35+
import { PdfDocument, PdfPage, PdfImage, PdfGraphics, PdfBitmap } from '@syncfusion/ej2-pdf';
3836

39-
// Handle click event
40-
button.element.onclick = async () => {
41-
console.log('Start PDF Creation');
42-
createPdf();
43-
};
44-
45-
// Function to create PDF
46-
function createPdf() {
4737
// Create a new PDF document
4838
let document: PdfDocument = new PdfDocument();
49-
// Add a new section to the document
50-
let section: PdfSection = document.addSection();
51-
// Add a page to the section
52-
let page: PdfPage = section.addPage();
39+
// Add a page
40+
let page: PdfPage = document.addPage();
5341
// Get graphics from the page
54-
let graphics = page.graphics;
42+
let graphics: PdfGraphics = page.graphics;
5543
// Load the image
56-
let image: PdfImage = new PdfBitmap('Image.jpg');
44+
let image: PdfImage = new PdfBitmap('/9j/4AAQSkZJRgABAQEAkACQAAD/4....QB//Z');
5745
// Draw the image.
58-
image.draw(graphics, 0,0);
46+
image.draw(graphics, {x: 10, y: 10});
5947
// Save the document
6048
document.save('Output.pdf');
6149
// Close the document
6250
document.destroy();
63-
}
64-
65-
{% endhighlight %}
66-
{% highlight html tabtitle="index.html" %}
67-
68-
<div class="row">
69-
<button id="normalbtn">Create PDF</button>
70-
</div>
7151

7252
{% endhighlight %}
7353
{% endtabs %}
@@ -77,94 +57,24 @@ function createPdf() {
7757
This example demonstrates how to insert an image into an existing PDF document using the `PdfBitmap` class and the `draw` method of the `PdfImage` class. The image is loaded from a file and rendered at the specified position on the selected page.
7858

7959
{% tabs %}
80-
{% highlight ts tabtitle="index.ts" %}
81-
82-
// Create and render button
83-
let button: Button = new Button();
84-
button.appendTo('#normalbtn');
60+
{% highlight c# tabtitle="TypeScript" %}
8561

86-
// Handle click event
87-
button.element.onclick = async () => {
88-
console.log('Start PDF Creation');
89-
createPdf();
90-
};
62+
import { PdfDocument, PdfPage, PdfGraphics, PdfImage, PdfBitmap } from '@syncfusion/ej2-pdf';
9163

92-
// Function to create PDF
93-
function createPdf() {
9464
// Load an existing PDF document
95-
let document: PdfDocument = new PdfDocument('input.pdf');
65+
let document: PdfDocument = new PdfDocument(data, password);
9666
// Access first page
9767
let page: PdfPage = document.getPage(0);
9868
// Get graphics from the page
99-
let graphics = page.graphics;
100-
// Load the image
101-
let image: PdfImage = new PdfBitmap('Image.jpg');
102-
// Draw the image.
103-
image.draw(graphics, 0,0);
104-
// Save the document
105-
document.save('Output.pdf');
106-
// Close the document
107-
document.destroy();
108-
}
109-
110-
{% endhighlight %}
111-
{% highlight html tabtitle="index.html" %}
112-
113-
<div class="row">
114-
<button id="normalbtn">Create PDF</button>
115-
</div>
116-
117-
{% endhighlight %}
118-
{% endtabs %}
119-
120-
## Image Pagination
121-
122-
This example demonstrates how to enable image pagination in a PDF document using the `PdfLayoutFormat` class. By setting the `break` property to PdfLayoutBreakType.fitPage and the `layout` property to PdfLayoutType.paginate, the image is automatically split across multiple pages when it exceeds the page size.
123-
124-
{% tabs %}
125-
{% highlight ts tabtitle="index.ts" %}
126-
127-
// Create and render button
128-
let button: Button = new Button();
129-
button.appendTo('#normalbtn');
130-
131-
// Handle click event
132-
button.element.onclick = async () => {
133-
console.log('Start PDF Creation');
134-
createPdf();
135-
};
136-
137-
// Function to create PDF
138-
function createPdf() {
139-
// Create a new PDF document
140-
let document: PdfDocument = new PdfDocument();
141-
// Add a new section to the document
142-
let section: PdfSection = document.addSection();
143-
// Add a page to the section
144-
let page: PdfPage = section.addPage();
145-
// Get graphics from the page
146-
let graphics = page.graphics;
69+
let graphics: PdfGraphics = page.graphics;
14770
// Load the image
148-
let image: PdfImage = new PdfBitmap('Image.jpg');
149-
// Create a layout for drawing
150-
let pageLayout: PdfLayoutFormat = new PdfLayoutFormat();
151-
// Set the layout break type for drawing
152-
pageLayout.break = PdfLayoutBreakType.fitPage;
153-
pageLayout.Layout = PdfLayoutType.paginate;
71+
let image: PdfImage = new PdfBitmap('/9j/4AAQSkZJRgABAQEAkACQAAD/4....QB//Z');
15472
// Draw the image.
155-
image.draw(graphics, 20, 20, pageLayout);
73+
image.draw(graphics, {x: 10, y: 10});
15674
// Save the document
15775
document.save('Output.pdf');
15876
// Close the document
15977
document.destroy();
160-
}
161-
162-
{% endhighlight %}
163-
{% highlight html tabtitle="index.html" %}
164-
165-
<div class="row">
166-
<button id="normalbtn">Create PDF</button>
167-
</div>
16878

16979
{% endhighlight %}
17080
{% endtabs %}
@@ -174,49 +84,29 @@ function createPdf() {
17484
This example demonstrates how to apply clipping and manage graphics state in a PDF document using the `PdfGraphics` class. The `save` and `restore` methods preserve the current graphics state, while the `setClip` method defines a clipping region to restrict drawing operations, ensuring precise control over rendering.
17585

17686
{% tabs %}
177-
{% highlight ts tabtitle="index.ts" %}
178-
179-
// Create and render button
180-
let button: Button = new Button();
181-
button.appendTo('#normalbtn');
87+
{% highlight c# tabtitle="TypeScript" %}
18288

183-
// Handle click event
184-
button.element.onclick = async () => {
185-
console.log('Start PDF Creation');
186-
createPdf();
187-
};
89+
import { PdfDocument, PdfPage, PdfGraphics, PdfImage, PdfBitmap, PdfGraphicsState, PdfFillMode } from '@syncfusion/ej2-pdf';
18890

189-
// Function to create PDF
190-
function createPdf() {
19191
// Create a new PDF document
19292
let document: PdfDocument = new PdfDocument();
193-
// Add a new section to the document
194-
let section: PdfSection = document.addSection();
195-
// Add a page to the section
196-
let page: PdfPage = section.addPage();
93+
// Add a page
94+
let page: PdfPage = document.addPage();
19795
// Get graphics from the page
198-
let graphics = page.graphics;
96+
let graphics: PdfGraphics = page.graphics;
19997
// Load the image— only the part within the clipping region will be visible
200-
let image: PdfImage = new PdfBitmap('Image.jpg');
98+
let image: PdfImage = new PdfBitmap('/9j/4AAQSkZJRgABAQEAkACQAAD/4....QB//Z');
20199
// Save the current graphics state (to restore later)
202100
let state: PdfGraphicsState = graphics.save();
203-
graphics.setClip( [50, 50, 200, 100] );
101+
graphics.setClip({x: 0, y: 0, width: 50, height: 12}, PdfFillMode.alternate );
204102
// Draw the image.
205-
image.draw(graphics, 20, 20);
103+
image.draw(graphics, {x: 10, y: 10});
206104
// Restore the graphics state to remove the clipping region
207105
graphics.restore(state);
208106
// Save the document
209107
document.save('Output.pdf');
210108
// Close the document
211109
document.destroy();
212-
}
213-
214-
{% endhighlight %}
215-
{% highlight html tabtitle="index.html" %}
216-
217-
<div class="row">
218-
<button id="normalbtn">Create PDF</button>
219-
</div>
220110

221111
{% endhighlight %}
222112
{% endtabs %}
@@ -226,54 +116,34 @@ function createPdf() {
226116
This example demonstrates how to apply transparency and rotation to an image in a PDF document using the `PdfGraphics` class. Transparency can be controlled through the graphics state, while rotation is applied by transforming the graphics context before drawing the image, enabling advanced visual effects in the document.
227117

228118
{% tabs %}
229-
{% highlight ts tabtitle="index.ts" %}
119+
{% highlight c# tabtitle="TypeScript" %}
230120

231-
// Create and render button
232-
let button: Button = new Button();
233-
button.appendTo('#normalbtn');
121+
import { PdfDocument, PdfPage, PdfGraphics, PdfImage, PdfBitmap, PdfGraphicsState } from '@syncfusion/ej2-pdf';
234122

235-
// Handle click event
236-
button.element.onclick = async () => {
237-
console.log('Start PDF Creation');
238-
createPdf();
239-
};
240-
241-
// Function to create PDF
242-
function createPdf() {
243123
// Create a new PDF document
244124
let document: PdfDocument = new PdfDocument();
245-
// Add a new section to the document
246-
let section: PdfSection = document.addSection();
247-
// Add a page to the section
248-
let page: PdfPage = section.addPage();
125+
// Add a page
126+
let page: PdfPage = document.addPage();
249127
// Get graphics from the page
250-
let graphics = page.graphics;
128+
let graphics: PdfGraphics = page.graphics;
251129
// Load the image— only the part within the clipping region will be visible
252-
let image: PdfImage = new PdfBitmap('Image.jpg');
130+
let image: PdfImage = new PdfBitmap('/9j/4AAQSkZJRgABAQEAkACQAAD/4....QB//Z');
253131
// Save the current graphics state (to restore later)
254132
let state: PdfGraphicsState = graphics.save();
255133
//Translate the coordinate system to the required position
256-
graphics.translateTransform(20, 100);
134+
graphics.translateTransform({x: 100, y: 100});
257135
//Apply transparency
258136
graphics.setTransparency(0.5);
259137
//Rotate the coordinate system
260138
graphics.rotateTransform(-45);
261139
// Draw the image.
262-
image.draw(graphics, 20, 20);
140+
image.draw(graphics,{x: 10, y: 20});
263141
// Restore the graphics state to remove the clipping region
264142
graphics.restore(state);
265143
// Save the document
266144
document.save('Output.pdf');
267145
// Close the document
268146
document.destroy();
269-
}
270-
271-
{% endhighlight %}
272-
{% highlight html tabtitle="index.html" %}
273-
274-
<div class="row">
275-
<button id="normalbtn">Create PDF</button>
276-
</div>
277147

278148
{% endhighlight %}
279149
{% endtabs %}

0 commit comments

Comments
 (0)