Skip to content

Commit 9522aa7

Browse files
author
KB Bot
committed
Added new kb article add-barcode-to-pdf-telerik
1 parent b4a9e24 commit 9522aa7

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
## Solution
23+
24+
To add a barcode to a PDF document, consider using the [WinForms BarcodeView]({%slug barcodeview-overview%}):
25+
26+
1\. First, [generate an image of the barcode](https://docs.telerik.com/devtools/winforms/controls/barcodeview/how-to/export-to-image).
27+
28+
2\. Then, add the image to the PDF document. Here is a sample code snippet:
29+
30+
```csharp
31+
Telerik.WinControls.UI.Barcode.QRCode qrCode1 = new Telerik.WinControls.UI.Barcode.QRCode();
32+
RadBarcodeView radBarcodeView = new RadBarcodeView();
33+
radBarcodeView.BindingContext = new BindingContext();
34+
qrCode1.Version = 1;
35+
radBarcodeView.Symbology = qrCode1;
36+
radBarcodeView.Text = "radBarcodeView1";
37+
radBarcodeView.Value = "1234567";
38+
radBarcodeView.Invalidate();
39+
System.Drawing.Image img = radBarcodeView.ExportToImage(200, 200);
40+
string imageFilePath = "barcodeImage.png";
41+
img.Save(imageFilePath, System.Drawing.Imaging.ImageFormat.Png);
42+
43+
RadFixedDocument fixedDocument = new RadFixedDocument();
44+
RadFixedDocumentEditor documentEditor = new RadFixedDocumentEditor(fixedDocument);
45+
FileStream fileStream = new FileStream(imageFilePath, FileMode.Open);
46+
Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource _imageSource = new Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource(fileStream);
47+
documentEditor.InsertImageInline(_imageSource);
48+
documentEditor.InsertLineBreak();
49+
documentEditor.Dispose();
50+
PdfFormatProvider provider = new PdfFormatProvider();
51+
string outputFilePath = "output.pdf";
52+
File.Delete(outputFilePath);
53+
using (Stream output = File.OpenWrite(outputFilePath))
54+
{
55+
provider.Export(fixedDocument, output);
56+
}
57+
Process.Start(new ProcessStartInfo() { FileName = outputFilePath, UseShellExecute = true });
58+
```
59+
60+
## Notes
61+
62+
- 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%}).
63+
64+
## See Also
65+
66+
- [RadPdfProcessing Documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/overview)
67+
- [Exporting BarcodeView to Image](https://docs.telerik.com/devtools/winforms/controls/barcodeview/how-to/export-to-image)
68+
- [Generating a Barcode Image outside WinForms]({%slug barcodeview-generating-image-console-app%})
69+

0 commit comments

Comments
 (0)