@@ -157,24 +157,24 @@ The SHA-256 hash algorithm is used for generating the signature. ECDSA signature
157
157
You can use your usual code to sign documents with ECDSA and to verify signatures:
158
158
159
159
``` cs
160
- public void Sign (string cert , string inputPdfFile , string outFile )
160
+ private static void Sign (string cert , string inputPdfFile , string signedPdfFile )
161
161
{
162
- using (Document document = new Document (inputPdfFile ))
162
+ using (var document = new Aspose . Pdf . Document (inputPdfFile ))
163
163
{
164
- using (PdfFileSignature signature = new PdfFileSignature (document ))
164
+ using (var signature = new Aspose . Pdf . Facades . PdfFileSignature (document ))
165
165
{
166
- PKCS7Detached pkcs = new PKCS7Detached (cert , " 12345" );
166
+ var pkcs = new Aspose . Pdf . Forms . PKCS7Detached (cert , " 12345" );
167
167
signature .Sign (1 , true , new System .Drawing .Rectangle (300 , 100 , 400 , 200 ), pkcs );
168
- signature .Save (outFile );
168
+ signature .Save (signedPdfFile );
169
169
}
170
170
}
171
171
}
172
172
173
- public static void Verify (string fileName )
173
+ private static void Verify (string signedPdfFile )
174
174
{
175
- using (Document document = new Document (fileName ))
175
+ using (var document = new Aspose . Pdf . Document (signedPdfFile ))
176
176
{
177
- using (PdfFileSignature signature = new PdfFileSignature (document ))
177
+ using (var signature = new Aspose . Pdf . Facades . PdfFileSignature (document ))
178
178
{
179
179
var sigNames = signature .GetSignNames ();
180
180
foreach (var sigName in sigNames )
@@ -190,31 +190,31 @@ public static void Verify(string fileName)
190
190
Sometimes, it is necessary to crop an image before inserting it into a PDF. We have added an overloaded version of the ` AddImage() ` method to support adding cropped images:
191
191
192
192
``` cs
193
- var imagePath = " " ;
194
- var resultPdfPath = " " ;
195
-
196
- using (Document document = new Document ())
193
+ private static void InsertCroppedImageToPdf (string imageFile , string resultPdf )
197
194
{
198
- using (Stream imgStream = File . OpenRead ( imagePath ))
195
+ using (var document = new Aspose . Pdf . Document ( ))
199
196
{
200
- // Define the rectangle where the image will be placed on the PDF page
201
- Rectangle imageRect = new Rectangle (17 . 62 , 65 . 25 , 602 . 62 , 767 . 25 );
197
+ using (Stream imgStream = File .OpenRead (imageFile ))
198
+ {
199
+ // Define the rectangle where the image will be placed on the PDF page
200
+ var imageRect = new Aspose .Pdf .Rectangle (17 . 62 , 65 . 25 , 602 . 62 , 767 . 25 );
202
201
203
- // Crop the image to half its original width and height
204
- var w = imageRect .Width / 2 ;
205
- var h = imageRect .Height / 2 ;
206
- Rectangle bbox = new Rectangle (imageRect .LLX , imageRect .LLY , imageRect .LLX + w , imageRect .LLY + h );
202
+ // Crop the image to half its original width and height
203
+ var w = imageRect .Width / 2 ;
204
+ var h = imageRect .Height / 2 ;
205
+ var bbox = new Aspose . Pdf . Rectangle (imageRect .LLX , imageRect .LLY , imageRect .LLX + w , imageRect .LLY + h );
207
206
208
- // Add a new page to the document
209
- Page page = document .Pages .Add ();
207
+ // Add a new page to the document
208
+ var page = document .Pages .Add ();
210
209
211
- // Insert the cropped image onto the page, specifying the original position (imageRect)
212
- // and the cropping area (bbox)
213
- page .AddImage (imgStream , imageRect , bbox );
214
- }
210
+ // Insert the cropped image onto the page, specifying the original position (imageRect)
211
+ // and the cropping area (bbox)
212
+ page .AddImage (imgStream , imageRect , bbox );
213
+ }
215
214
216
- // Save the document to the specified file path
217
- document .Save (resultPdfPath );
215
+ // Save the document to the specified file path
216
+ document .Save (resultPdf );
217
+ }
218
218
}
219
219
```
220
220
@@ -232,28 +232,30 @@ try
232
232
}
233
233
catch (Exception ex )
234
234
{
235
- PdfException .GenerateCrashReport (new CrashReportOptions (ex ));
235
+ Aspose . Pdf . PdfException .GenerateCrashReport (new Aspose . Pdf . CrashReportOptions (ex ));
236
236
}
237
237
```
238
238
239
239
Extracting an PDF document layer elements and saving into new PDF stream are available from now. In PDF documents, layers (also known as Optional Content Groups or OCGs) are used for various purposes, primarily to manage and control the visibility of content within the document. This functionality is particularly useful in design, engineering, and publishing. For example: blueprint aspects, complex diagram components, language versions of the same content.
240
240
241
241
``` cs
242
- var documentPath = " " ;
243
- var resultPdfPath = " " ;
244
-
245
- var inputDocument = new Document ( documentPath );
246
- var inputPage = inputDocument .Pages [1 ];
242
+ private static void ExtractPdfLayer ( string inputPdfPath , string outputPdfName )
243
+ {
244
+ using ( var inputDocument = new Aspose . Pdf . Document ( inputPdfPath ))
245
+ {
246
+ var inputPage = inputDocument .Pages [1 ];
247
247
248
- var layers = inputPage .Layers ;
248
+ var layers = inputPage .Layers ;
249
249
250
- foreach (var layer in layers )
251
- {
252
- var outputPdf = string .Format (" {0}_{1}.pdf" , resultPdfPath , layer .Id );
250
+ foreach (var layer in layers )
251
+ {
252
+ var extractedLayerPdfName = string .Format (" {0}_{1}.pdf" , outputPdfName , layer .Id );
253
253
254
- using (var stream = File .Create (outputPdf ))
255
- {
256
- layer .Save (stream );
254
+ using (var stream = File .Create (extractedLayerPdfName ))
255
+ {
256
+ layer .Save (stream );
257
+ }
258
+ }
257
259
}
258
260
}
259
261
```
@@ -263,19 +265,21 @@ The `GraphicalPdfComparer` class is added for the graphic comparison of PDF docu
263
265
The following code snippet demonstrates the graphic comparison of two PDF documents and saves an image with the differences into the resultant PDF document:
264
266
265
267
``` cs
266
- var firstDocumentPath = " " ;
267
- var secondDocumentPath = " " ;
268
- var resultPdfPath = " " ;
269
-
270
- using (Document doc1 = new Document (firstDocumentPath ), doc2 = new Document (secondDocumentPath ))
268
+ private static void PdfGraphicComparison (string firstDocumentPath , string secondDocumentPath , string comparisonResultPdfPath )
271
269
{
272
- GraphicalPdfComparer comparer = new GraphicalPdfComparer ( )
270
+ using ( var firstDocument = new Aspose . Pdf . Document ( firstDocumentPath ) )
273
271
{
274
- Threshold = 3 . 0 ,
275
- Color = Color .Red ,
276
- Resolution = new Resolution (300 )
277
- };
278
- comparer .CompareDocumentsToPdf (doc1 , doc2 , resultPdfPath );
272
+ using (var secondDocument = new Aspose .Pdf .Document (secondDocumentPath ))
273
+ {
274
+ var comparer = new Aspose .Pdf .Comparison .GraphicalComparison .GraphicalPdfComparer ()
275
+ {
276
+ Threshold = 3 . 0 ,
277
+ Color = Color .Red ,
278
+ Resolution = new Resolution (300 )
279
+ };
280
+ comparer .CompareDocumentsToPdf (firstDocument , secondDocument , comparisonResultPdfPath );
281
+ }
282
+ }
279
283
}
280
284
```
281
285
@@ -284,29 +288,31 @@ API implemented for integrating FileFormat.HEIC and Aspose.PDF. The HEIC (High-E
284
288
To convert HEIC images to PDF user should add the reference to ` FileFormat.HEIC ` NuGet package and use the following code snippet:
285
289
286
290
``` cs
287
- var heicImagePath = " iphone_photo.heic" ;
288
- var resultPdfPath = " iphone_photo.pdf" ;
289
-
290
- using (var fs = new FileStream (heicImagePath , FileMode .Open ))
291
+ private static void HeicToPdf (string heicImagePath , string resultPdfPath )
291
292
{
292
- HeicImage image = HeicImage .Load (fs );
293
- var pixels = image .GetByteArray (PixelFormat .Rgb24 );
294
- var width = (int )image .Width ;
295
- var height = (int )image .Height ;
293
+ using (var fs = new FileStream (heicImagePath , FileMode .Open ))
294
+ {
295
+ var image = FileFormat .Heic .Decoder .HeicImage .Load (fs );
296
+ var pixels = image .GetByteArray (FileFormat .Heic .Decoder .PixelFormat .Rgb24 );
297
+ var width = (int )image .Width ;
298
+ var height = (int )image .Height ;
296
299
297
- var document = new Document ();
298
- Page page = document .Pages .Add ();
299
- Aspose .Pdf .Image asposeImage = new Aspose .Pdf .Image ();
300
- asposeImage .BitmapInfo = new BitmapInfo (pixels , width , height , BitmapInfo .PixelFormat .Rgb24 );
301
- page .PageInfo .Height = height ;
302
- page .PageInfo .Width = width ;
303
- page .PageInfo .Margin .Bottom = 0 ;
304
- page .PageInfo .Margin .Top = 0 ;
305
- page .PageInfo .Margin .Right = 0 ;
306
- page .PageInfo .Margin .Left = 0 ;
307
-
308
- page .Paragraphs .Add (asposeImage );
309
- document .Save (resultPdfPath );
300
+ using (var document = new Aspose .Pdf .Document ())
301
+ {
302
+ var page = document .Pages .Add ();
303
+ var asposeImage = new Aspose .Pdf .Image ();
304
+ asposeImage .BitmapInfo = new Aspose .Pdf .BitmapInfo (pixels , width , height , Aspose .Pdf .BitmapInfo .PixelFormat .Rgb24 );
305
+ page .PageInfo .Height = height ;
306
+ page .PageInfo .Width = width ;
307
+ page .PageInfo .Margin .Bottom = 0 ;
308
+ page .PageInfo .Margin .Top = 0 ;
309
+ page .PageInfo .Margin .Right = 0 ;
310
+ page .PageInfo .Margin .Left = 0 ;
311
+
312
+ page .Paragraphs .Add (asposeImage );
313
+ document .Save (resultPdfPath );
314
+ }
315
+ }
310
316
}
311
317
```
312
318
0 commit comments