This is a migrated thread and some comments may be shown as answers.

Insert a vector graphic or PDF as image

4 Answers 592 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
Niklas
Top achievements
Rank 1
Niklas asked on 06 Sep 2017, 02:38 PM
I create a barcode using the barcode library from DevExpress. It can export the barcode in various raster image formats (PNG, JPEG, ...), in vector graphic formats (WMF and EMF) or as a separate PDF file.

Currently I export a JPEG and add it to Telerik RadPdfProcessing using:
myBlock.InsertImage(new ImageSource(myJpegImageStream, ImageQuality.High));

Of course, the image quality is not optimal, because the raster graphics are lossy when zooming. Is there any way to insert a vector graphic or the PDF as described above in a RadPdfProcessing Block/FixedContentEditor? If RadPdfProcessing does not support WMF or EMF, but a different vector graphic format, which a WMF or EMF can be converted to, it would be OK for me to convert the WMF/EMF to this other format.

Using a PdfStreamWriter to manipulate the PDF created by RadPdfProcessing afterwards may be an option, but not a very nice one, because the image is not part of the document flow.

4 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 08 Sep 2017, 03:18 PM
Hello Niklas,

You may take a look at this CreateDocumentWithImages Github SDK example which shows different approaches for inserting images in PDF file with RadPdfProcessing. For lossless images export, you may take a look at the code exporting RGBA PNG image with FlateDecode compression and the code exporting Dualtone PNG image with FlateDecode compression. Actually, the scenario with the Dualtone PNG image seems similar to the barcode which is also a monochrome picture. If you open the exported PDF file in Adobe Reader and take a closer look at the page with the title "This is Dualtone PNG image encoded with FlateDecode." then you will notice that no matter how much you zoom the square dots of the monochrome balloon picture are not blurred. This is because the picture is exported in lossless format with FlateDecode compression.

As for exporting vector graphics in a PDF file with Block class - you may draw the desired vector content in a FormSource class instance using FixedContentEditor. Sample code for this may be seen in this "Adding Content to FormSource Object" documentation section. The FormSource object may then be inserted in a Block class instance using the InsertForm method. This allows the vector graphics of flow with the rest of the Block content.

I hope this information is helpful.

Regards,
Deyan
Progress Telerik

0
Niklas
Top achievements
Rank 1
answered on 11 Sep 2017, 01:24 PM

Thanks!

So inserting a PDF *inside* a PDF page is not possible using RadPdfProcessing?

0
Niklas
Top achievements
Rank 1
answered on 11 Sep 2017, 02:11 PM

"As for exporting vector graphics in a PDF file with Block class - you may draw the desired vector content"

Unfortunately, that does not help me. I want to insert the barcode, which I have in a vector graphics format (EMF, WMF), into the PDF generated by RadPdfProcessing.

0
Deyan
Telerik team
answered on 14 Sep 2017, 11:43 AM
Hello Niklas,

I am attaching two sample projects showing different approaches for inserting vector barcode content with PdfProcessing.

The first project is in the attached archive "BarcodeWithPdfFont.zip". This demo generally shows that the barcode content can actually be generated using an appropriate font file. When you draw the barcode text with the corresponding font it is displayed in the PDF file as a barcode. You may additionally notice that when you export the barcode you may later select it in the PDF file and when you copy and paste it in Notepad, for instance, you will be able to read the barcode text. In order to test this demo, you need to download a font called "free3of9" and install it on your machine. This font file may found for free download when searching it on the web (for example I have found it on the following link). On the attached screenshot "install-free3of9-font-using-windowsFontViewer.png" you may see the install button which should be available when you double-click the font file. If your application cannot rely on the font file being installed on the machine, you can alternatively register the font data through FontRepository class. This can be achieved by making the font file resource to your project and passing the file's byte array to FontRepository's RegisterFont method. More information on fonts you may find on this link to fonts documentation article.

The second project I am attaching may be found in the archive "ConvertRadFixedPageToFormSource.zip". This project shows how to import the barcode from existing PDF file and then insert it as FormSource class instance in order to flow with the rest of the Block content. The conversion between RadFixedPage and FormSource may be seen in the ConvertPageContentToFormSource method which simply moves all the page content to a newly created form source instance. 

Both demos are console applications and at the end of their execution, they open the result PDF file so that you may see it with the default PDF viewer on your machine.

I hope this helps.

Regards,
Deyan
Progress Telerik

Tags
PdfProcessing
Asked by
Niklas
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Niklas
Top achievements
Rank 1
Share this question
or