Skip to content

Commit 20db9ce

Browse files
Merge pull request #440 from telerik/new-kb-add-barcode-to-pdf-telerik-a0d9d6ea723f4386b2ea87cd3eb19a21
Added new kb article add-barcode-to-pdf-telerik
2 parents b4a9e24 + 704d4a7 commit 20db9ce

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: Adding a Barcode to a PDF Document using PdfProcessing and the WinForms BarcodeView
3+
description: Learn how to generate a barcode and incorporate it into a PDF document using Telerik products.
4+
type: how-to
5+
page_title: How to Add a Barcode to a PDF with PdfProcessing and the WinForms BarcodeView
6+
slug: add-barcode-to-pdf-telerik
7+
tags: radpdfprocessing, document processing, barcode, pdf, telerik reporting, winforms, barcodeview
8+
res_type: kb
9+
ticketid: 1657503
10+
---
11+
12+
## Environment
13+
14+
| Version | Product | Author |
15+
| --- | --- | ---- |
16+
| 2024.2.426| RadPdfProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)|
17+
18+
## Description
19+
20+
Learn how to generate a PDF document and add a barcode to it.
21+
22+
![Pdf with Barcodes](images/pdf-with-barcodes.png)
23+
24+
## Solution
25+
26+
To add a barcode to a PDF document, consider using the [WinForms BarcodeView]({%slug barcodeview-overview%}):
27+
28+
1\. First, [generate an image of the barcode]({%slug barcodeview-export-to-image%}).
29+
30+
2\. Then, add the [image to the PDF document]({%slug pdf-from-images-with-radfixeddocumenteditor%}). Here is a sample code snippet:
31+
32+
```csharp
33+
Telerik.WinControls.UI.Barcode.QRCode qrCode1 = new Telerik.WinControls.UI.Barcode.QRCode();
34+
RadBarcodeView radBarcodeView = new RadBarcodeView();
35+
radBarcodeView.BindingContext = new BindingContext();
36+
qrCode1.Version = 1;
37+
radBarcodeView.Symbology = qrCode1;
38+
radBarcodeView.Text = "radBarcodeView1";
39+
radBarcodeView.Value = "1234567";
40+
radBarcodeView.Invalidate();
41+
System.Drawing.Image img = radBarcodeView.ExportToImage(200, 200);
42+
string imageFilePath = "barcodeImage.png";
43+
img.Save(imageFilePath, System.Drawing.Imaging.ImageFormat.Png);
44+
45+
RadFixedDocument fixedDocument = new RadFixedDocument();
46+
RadFixedDocumentEditor documentEditor = new RadFixedDocumentEditor(fixedDocument);
47+
FileStream fileStream = new FileStream(imageFilePath, FileMode.Open);
48+
Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource _imageSource = new Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource(fileStream);
49+
documentEditor.InsertImageInline(_imageSource);
50+
documentEditor.InsertLineBreak();
51+
documentEditor.Dispose();
52+
PdfFormatProvider provider = new PdfFormatProvider();
53+
string outputFilePath = "output.pdf";
54+
File.Delete(outputFilePath);
55+
using (Stream output = File.OpenWrite(outputFilePath))
56+
{
57+
provider.Export(fixedDocument, output);
58+
}
59+
Process.Start(new ProcessStartInfo() { FileName = outputFilePath, UseShellExecute = true });
60+
```
61+
62+
## Notes
63+
64+
- The WinForms BarcodeView method is suitable for applications where a barcode image can be generated and saved before adding it to the PDF: [Generating a Bar Code Image outside WinForms]({%slug barcodeview-generating-image-console-app%}).
65+
66+
## See Also
67+
68+
- [RadPdfProcessing Documentation]({%slug radpdfprocessing-overview%})
69+
- [WinForms BarcodeView]({%slug barcodeview-overview%})
70+
- [Exporting BarcodeView to Image]({%slug barcodeview-export-to-image%})
71+
- [Generating a Barcode Image outside WinForms]({%slug barcodeview-generating-image-console-app%})
72+
17.6 KB
Loading

libraries/radpdfprocessing/model/image.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,4 @@ The Image class exposes also the **GetBitmapSource()** method, enabling you to o
7979
* [Adding Images with a Shadow in PDF Documents]({%slug add-shadow-image-radpdfprocessing%})
8080
* [Splitting a Large Image Across Multiple PDF Pages]({%slug split-export-large-image-multiple-pdf-pages-radpdfprocessing%})
8181
* [Change file size of a PDF with images through ImageCompression and ImageQuality]({%slug pdfprocessing-change-file-size-through-image-quality-and-compression%})
82+
* [Adding a Barcode to a PDF Document using PdfProcessing and the WinForms BarcodeView]({%slug add-barcode-to-pdf-telerik%})

0 commit comments

Comments
 (0)