mercoledì, gennaio 17, 2007

How to insert a 2D DataMatrix in a pdf using IEC16022Sharp and iTextSharp

A very simple example:

Document doc = new Document(new Rectangle(0, 0, 595, 842));
FileStream os = new FileStream("DataMatrixout.pdf", FileMode.Create, FileAccess.Write);
PdfWriter writer = PdfWriter.GetInstance(doc, os);
doc.Open();
doc.NewPage();
doc.Add(new Paragraph("IEC16022Sharp simple test"));
DataMatrix dm = new DataMatrix("This is a test with iTextSharp and Iec16022Sharp");

// Add image to document
Image img1 = Image.GetInstance(dm.Image, ImageFormat.Bmp);
doc.Add(img1);

// Add image to Pdf direct content
Image img2 = Image.GetInstance(dm.Image, ImageFormat.Bmp);
img2.SetAbsolutePosition(300, 700);
writer.DirectContent.AddImage(img2);

doc.Close();




http://sourceforge.net/projects/iec16022sharp/
http://itextsharp.sourceforge.net/

Nessun commento: