public QRCodeTagWorker(IElementNode element, ProcessorContext context) { // Retrieve all necessary properties to create the barcode IDictionary <EncodeHintType, Object> hints = new Dictionary <EncodeHintType, object>(); // Character set string charset = element.GetAttribute("charset"); if (CheckCharacterSet(charset)) { hints[EncodeHintType.CHARACTER_SET] = charset; } // Error-correction level string errorCorrection = element.GetAttribute("errorcorrection"); if (CheckErrorCorrectionAllowed(errorCorrection)) { ErrorCorrectionLevel errorCorrectionLevel = GetErrorCorrectionLevel(errorCorrection); hints[EncodeHintType.ERROR_CORRECTION] = errorCorrectionLevel; } // Create the QR-code qrCode = new BarcodeQRCode("placeholder", hints); }
public static void AddQRCode(this PdfContentByte pdfContentByte, float x, float y, string text, int size) { var image = new BarcodeQRCode(text, size, size, null).GetImage(); image.SetAbsolutePosition(x, y); pdfContentByte.AddImage(image); }
public void CreatePdf(PdfDocument pdfDocument, Document document, bool isLast) { document.SetLeftMargin(100); Barcode128 b = new Barcode128(pdfDocument); b.SetCodeType(Barcode128.CODE128); b.SetCode(ID); PdfFormXObject bobject = b.CreateFormXObject(pdfDocument); BarcodeQRCode qr = new BarcodeQRCode(ID); document.Add(new Paragraph(String.Format("{0} {1} {2}", Testee.Surname, Testee.Forename, Testee.Birthday.ToString("yyyy-MM-dd"))).SetFontSize(25).SetPaddingBottom(10)); document.Add(new Paragraph("ID:")); document.Add(new Paragraph(ID).SetFontSize(40)); document.Add(new Paragraph("ID NICHT DOPPELT SCANNEN").SetFontColor(ColorConstants.RED).SetBold().SetPaddingBottom(20)); //document.Add(new Image(bobject).SetAutoScale(true)); Div d = new Div(); d.SetWidth(UnitValue.CreatePercentValue(33)); d.Add(new Image(bobject).SetAutoScale(true)); d.SetMarginBottom(20); document.Add(d); Div q = new Div(); q.SetWidth(UnitValue.CreatePercentValue(50)); q.Add(new Image(qr.CreateFormXObject(pdfDocument)).SetAutoScale(true)); document.Add(q); if (!isLast) { document.Add(new AreaBreak()); } //document.Close(); }
protected override void MakePdf(string outPdf) { // step 1 Document document = new Document(new Rectangle(340, 842)); // step 2 PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(outPdf, FileMode.Create)); // step 3 document.Open(); // step 4 PdfContentByte cb = writer.DirectContent; String str = "\u6D4B"; document.Add(new Paragraph("QR code unicode")); IDictionary <EncodeHintType, Object> hints = new Dictionary <EncodeHintType, object>(); hints[EncodeHintType.CHARACTER_SET] = "UTF-8"; BarcodeQRCode q = new BarcodeQRCode(str, 100, 100, hints); document.Add(q.GetImage()); // step 5 document.Close(); }
private static Paragraph GenerateParagraphForQRCode(string name, string jmbg, string medication, string description) { Paragraph qrPahragraph = new Paragraph(); iTextSharp.text.pdf.BarcodeQRCode qrcode = new BarcodeQRCode(name + " \n " + jmbg + " \n " + DateTime.Today + " \n " + medication + " \n " + description, 200, 200, null); iTextSharp.text.Image image = qrcode.GetImage(); qrPahragraph.Add(image); return(qrPahragraph); }
/// <summary> /// 二维码 /// </summary> /// <param name="text"></param> /// <param name="x"></param> /// <param name="y"></param> public void QRCode(string text, int x, int y) { var qr = new BarcodeQRCode(text, 100, 100, null); var img = qr.GetImage(); var pos = Transform(x, y); img.SetAbsolutePosition(pos.X, pos.Y); Canvas.AddImage(img); }
private void AddQRCode(PdfContentByte ContentByte, string msg, float x, float y, int Margin = 5) { BarcodeQRCode qrcode = new BarcodeQRCode(msg, 1, 1, null); Image image = qrcode.GetImage(); x = x - (image.Width + Margin); y = y + Margin; image.SetAbsolutePosition(x, y); ContentByte.AddImage(image); }
// Генерация нового QR-кода по считанной из файла информации public iTextSharp.text.Image QRGenerate(string QRFileContent) { BarcodeQRCode QRCode = new BarcodeQRCode(QRFileContent, 90, 90, null); iTextSharp.text.Image QRCodeImage = QRCode.GetImage(); //QRCodeImage.SetDpi(1300, 1300); return(QRCodeImage); }
void AgregarQR() { string QR = string.Format("http://www.cochabamba2018.bo/Acreditacion/{0}/{1}", this.EventoId, this.PersonaId); BarcodeQRCode bcq = new BarcodeQRCode(QR, 10, 10, null); iTextSharp.text.Image codigoQR = iTextSharp.text.Image.GetInstance(bcq.GetImage()); codigoQR.Alignment = iTextSharp.text.Image.UNDERLYING; codigoQR.ScaleToFit(65, 65); codigoQR.SetAbsolutePosition(210f, 136f); doc.Add(codigoQR); }
public byte[] AgregarQRsAPDF(byte[] bytes, String contenidoQR, List <int> listaPaginaImagen, List <int> listaTamEscalasImagen, List <float> listaPosicionesX, List <float> listaPosicionesY) { PdfReader reader = new PdfReader(bytes); BarcodeQRCode barcodeQRCode; Image codeQRImage; using (MemoryStream ms = new MemoryStream()) { PdfStamper stamp = new PdfStamper(reader, ms); try { //stamp.AcroFields.SetField("texto5", csv);--ACA se debe agregar el nuevo codigo CSV Dictionary <EncodeHintType, Object> qrParam = new Dictionary <EncodeHintType, Object>(); qrParam[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.M; qrParam[EncodeHintType.CHARACTER_SET] = "UTF-8"; //codeQRImage.ScaleAbsolute(100f,100f); //codeQRImage.SetAbsolutePosition(doc.PageSize.Width - 36f - 128f, doc.PageSize.Height - 36f - 686.6f);//216 //foreach (float escala in listaTamEscalasImagen) { for (int i = 0; i < listaTamEscalasImagen.Count; i++) { barcodeQRCode = new BarcodeQRCode(contenidoQR, listaTamEscalasImagen.ElementAt(i), listaTamEscalasImagen.ElementAt(i), qrParam); codeQRImage = barcodeQRCode.GetImage(); //codeQRImage.ScaleAbsolute(listaTamEscalasImagen.ElementAt(i), listaTamEscalasImagen.ElementAt(i)); codeQRImage.SetAbsolutePosition(listaPosicionesX.ElementAt(i), listaPosicionesY.ElementAt(i)); //codeQRImage.Rotate(); //codeQRImage.Rotate(); //codeQRImage.Rotation = (float)Math.PI / 2; //angulo en radianes, osea esto equivale a 90 grados // codeQRImage.RotationDegrees = 90f; PdfContentByte content = stamp.GetOverContent(listaPaginaImagen.ElementAt(i)); //imprimo en la 1 pagina content.AddImage(codeQRImage); } //codeQRImage.ScaleAbsolute(75, 75); //escala el tamaño de la imagen //codeQRImage.SetAbsolutePosition(420, 115); } catch (Exception e) { throw new Exception("no se pudieron agregar las imagenes de Qr al pdf"); } stamp.FormFlattening = true; //recien aca cierro el pdf para que no puedan editarse los campos llenables del pdf stamp.Close(); //cierro el pdf reader.Close(); ms.Close(); byte[] Bytes = ms.ToArray(); return(Bytes); } }
private Image generarQR(string contenido, int ancho = 100, int alto = 100) { // genero el codigo QR BarcodeQRCode qr = new BarcodeQRCode(contenido, 1000, 1000, null); // obtengo la imagen del QR Image imagenQR = qr.GetImage(); // redimensiono la imagen imagenQR.ScaleAbsolute(ancho, alto); return(imagenQR); }
//2.3 //print QRcode in button field private void _GenQRCode(PdfStamper stamper, string FieldName, string QrCodeContent) { AcroFields form = stamper.AcroFields; PushbuttonField ad = form.GetNewPushbuttonFromField(FieldName); BarcodeQRCode qrcode = new BarcodeQRCode(QrCodeContent, 2, 2, null); var qrcodeImg = qrcode.GetImage(); ad.Layout = PushbuttonField.LAYOUT_ICON_ONLY; ad.ProportionalIcon = true; ad.Image = qrcodeImg; form.ReplacePushbuttonField(FieldName, ad.Field); }
/// <summary> /// Obtener el Barcore QR /// </summary> /// <param name="text">Mensaje que será pasado a QR</param> /// <returns>Imágen QR</returns> private Image GetQr(string text) { BarcodeQRCode qrCode = new BarcodeQRCode(text); Image qr = new Image(qrCode.CreateFormXObject(null, null)); qr.Scale(2, 2); qr.SetHorizontalAlignment(HorizontalAlignment.LEFT); qr.SetMarginLeft(20); qr.SetMarginTop(10); return(qr); }
private string GenerateQrCode(string assettagid) { string base64; //iTextSharp.text.Document doc = new iTextSharp.text.Document(new iTextSharp.text.Rectangle(4.5f, 5.5f), 0.5f, 0.5f, 0, 0); //string filepathimg = Path.Combine(Server.MapPath("~/Views/QrCode/"), assettagid + ".jpg"); ByteMatrix btm; MemoryStream ms = null; Bitmap bmp = null; try { BarcodeQRCode qrcode = new BarcodeQRCode(assettagid, 200, 200, null); QRCodeWriter qrwriter = new QRCodeWriter(); btm = qrwriter.Encode(assettagid, 200, 200, null); qrcode.GetImage(); sbyte[][] imgQr = btm.GetArray(); bmp = new Bitmap(200, 200); Graphics gpr = Graphics.FromImage(bmp); gpr.Clear(Color.White); for (int i = 0; i < imgQr.Length; i++) { for (int j = 0; j <= imgQr[i].Length - 1; j++) { if (imgQr[j][i] == 0) { gpr.FillRectangle(Brushes.Black, i, j, 1, 1); } else { gpr.FillRectangle(Brushes.White, i, j, 1, 1); } } } Response.ContentType = "image/jpeg"; //fs = new FileStream(filepathimg, FileMode.Create); ms = new MemoryStream(); bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] byteImg = ms.ToArray(); base64 = Convert.ToBase64String(byteImg); } catch (Exception ex) { base64 = ""; string msg = ex.Message; } bmp.Dispose(); ms.Close(); return(base64); }
public static byte[] createBarCode(String Cadena) { byte[] array = null; byte[] array1 = null; using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { iTextSharp.text.Document doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 30f, 30f, 30f, 30f); iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, ms); doc.Open(); var hints = new Dictionary <EncodeHintType, object>(); hints.Add(EncodeHintType.ERROR_CORRECTION, iTextSharp.text.pdf.qrcode.ErrorCorrectionLevel.H); //Creamos el QR BarcodeQRCode qrcode = new BarcodeQRCode(Cadena, 1, 1, hints); Image qrcodeImage = qrcode.GetImage(); qrcodeImage.SetAbsolutePosition(50, 500); qrcodeImage.ScalePercent(200); doc.Add(qrcodeImage); doc.Close(); byte[] result = ms.ToArray(); array = result; } try { System.Diagnostics.Debug.WriteLine("Wait for extracting image from PDF file...."); // Get a List of Image List <System.Drawing.Image> ListImage = ExtractImages(array); for (int i = 0; i < ListImage.Count; i++) { try { array1 = imageToByteArray(ListImage[i]); } catch (Exception) { } } } catch (Exception ex) { throw new Exception(ex.Message); } return(array1); }
private void button_Click(object sender, RoutedEventArgs e) { var retangulo = new iTextSharp.text.Rectangle(765, 765); var documento = new Document(retangulo); var writer = PdfWriter.GetInstance(documento, new FileStream(@"c:\teste\teste.pdf", FileMode.Create)); documento.Open(); var imagemDoTopo = iTextSharp.text.Image.GetInstance(@"c:\teste\imagem.png"); imagemDoTopo.SetAbsolutePosition(0, 100); documento.Add(imagemDoTopo); PdfContentByte cb = writer.DirectContent; BaseFont outraFonte = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1252, false, false); cb.BeginText(); cb.SetFontAndSize(outraFonte, 12); cb.SetColorFill(new BaseColor(51, 51, 51)); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "TESTE", 50, 35, 50); cb.EndText(); var paramQR = new Dictionary <EncodeHintType, object>(); paramQR.Add(EncodeHintType.CHARACTER_SET, CharacterSetECI.GetCharacterSetECIByName("UTF-8")); BarcodeQRCode qrCodigo = new BarcodeQRCode("https://www.youtube.com/channel/UCcOGfx3w8BRxkfSyZFsW5fQ", 150, 150, paramQR); iTextSharp.text.Image imgBarCode = qrCodigo.GetImage(); imgBarCode.SetAbsolutePosition(200, 200); documento.Add(imgBarCode); BarcodeEAN codeEAN13 = null; codeEAN13 = new BarcodeEAN(); codeEAN13.CodeType = Barcode.EAN13; codeEAN13.ChecksumText = true; codeEAN13.GenerateChecksum = true; codeEAN13.BarHeight = 12; codeEAN13.Code = "1234567890123"; imgBarCode = codeEAN13.CreateImageWithBarcode(cb, null, null); imgBarCode.SetAbsolutePosition(150, 150); imgBarCode.Alignment = iTextSharp.text.Image.TEXTWRAP; documento.Add(imgBarCode); documento.Close(); }
public PdfPCell RenderingCell(CellAttributes attributes) { var data = attributes.RowData.TableRowData; var id = data.GetSafeStringValueOf <User>(x => x.Id); var qrcode = new BarcodeQRCode(id, 1, 1, null); var image = qrcode.GetImage(); var mask = qrcode.GetImage(); mask.MakeMask(); image.ImageMask = mask; // making the background color transparent var pdfCell = new PdfPCell(image, fit: false); return(pdfCell); }
static void Main(string[] args) { Document doc = new Document(PageSize.LETTER); //Hacer una app de escritorio. PdfWriter.GetInstance(doc, new FileStream(@"E:\prueba.pdf", FileMode.Create)); doc.Open(); BarcodeQRCode barCode = new BarcodeQRCode("http://wwww.google.com", 200, 200, null); Image codeQRImage = barCode.GetImage(); doc.Add(codeQRImage); doc.Close(); }
/** * Metodo que genera un PDF con codigos QR * **/ private PdfPTable CodigoQR(string[] datos, int codigos_por_fila) { PdfPTable table = new PdfPTable(codigos_por_fila); table.WidthPercentage = 100; //****Se agregan elementos for (int i = 0; i < datos.Length; i++) { BarcodeQRCode bc = new BarcodeQRCode(datos[i], 1, 1, null); PdfPCell cell = new PdfPCell(table.DefaultCell); cell.AddElement(new Chunk("OET - " + datos[i])); cell.AddElement(bc.GetImage()); table.AddCell(cell); } table.CompleteRow(); return(table); }
iTextSharp.text.Image GetQrCodeImage() { Dictionary <EncodeHintType, object> hints = new Dictionary <EncodeHintType, object> { { EncodeHintType.CHARACTER_SET, "utf-8" } //добавление в коллекцию кодировки utf-8 }; // Формируем строку для QRcode string strRUS = ""; strRUS = "ST00012|" + "Name=" + Aut.NameOgv + "|PersonalAcc=" + Aut.PersonalAcc + "|BankName=" + Aut.BankName + "|BIC=" + Aut.Bic + "|CorrespAcc=" + Aut.CorrespAcc + "|Sum=" + purpose.Sum + "|PayeeINN=" + Aut.PayeeInn + "|KPP=" + Aut.Kpp + "|CBC=" + purpose.Kbk + "|OKTMO=" + Aut.Oktmo + "|Purpose=" + purpose.Name; if (Mod.LastName != "" && Mod.LastName != null) { strRUS = strRUS + "|LASTNAME=" + Mod.LastName + " " + Mod.FirstName + " " + Mod.MiddleName + "|PayerAddress=" + Mod.PayerAdress + "|Nationality=" + Mod.Nationaly + "|PayerIdType=" + Mod.PayerIdType + "|PayerIdNum=" + Mod.PayerIdNum; } //создание матрицы QR BarcodeQRCode qrMatrix = new BarcodeQRCode( strRUS, //кодируемая строка 100, //ширина 100, //высота hints); return(qrMatrix.GetImage()); }
private Cell MakeCell(string code, PdfDocument pdfDoc, PDFQRConfiguration settings) { Cell cell = new Cell(); cell.SetKeepTogether(true); cell.SetBorder(iText.Layout.Borders.Border.NO_BORDER); cell.SetHorizontalAlignment(HorizontalAlignment.CENTER); cell.SetVerticalAlignment(VerticalAlignment.MIDDLE); Paragraph p = new Paragraph(settings.Prefix); p.SetTextAlignment(TextAlignment.CENTER); p.SetVerticalAlignment(VerticalAlignment.BOTTOM); p.SetMargin(0); p.SetPadding(0); cell.Add(p); BarcodeQRCode barcode = new BarcodeQRCode($"{settings.Prefix}{code}"); PdfFormXObject barcodeObject = barcode.CreateFormXObject(pdfDoc); // Create barcode object to put it to the cell as image var image = new Image(barcodeObject); image.SetMargins(0, 0, 0, 0); image.Scale(settings.Scale, settings.Scale); image.SetPadding(0); cell.Add(image); cell.SetPaddingTop(settings.CellPaddingTop); cell.SetPaddingRight(settings.CellPaddingRight); cell.SetPaddingBottom(settings.CellPaddingBottom); cell.SetPaddingLeft(settings.CellPaddingLeft); cell.SetBorder(iText.Layout.Borders.Border.NO_BORDER); p = new Paragraph(code); p.SetTextAlignment(TextAlignment.CENTER); p.SetVerticalAlignment(VerticalAlignment.TOP); p.SetMargin(0); p.SetPadding(0); cell.Add(p); return(cell); }
public QRCodeTagWorker(IElementNode tag, ProcessorContext context, string content) { var hints = new Dictionary <EncodeHintType, object>(); string charset = tag.GetAttribute("charset"); _content = content; if (CheckCharSet(charset)) { hints.Add(EncodeHintType.CHARACTER_SET, charset); } string errorCorrection = tag.GetAttribute("errorcorrection"); if (CheckErrorCorrectionAllowed(errorCorrection)) { ErrorCorrectionLevel errorCorrectionLevel = getErrorCorrectionLevel(errorCorrection); hints.Add(EncodeHintType.ERROR_CORRECTION, errorCorrectionLevel); } qrCode = new BarcodeQRCode("placeholder", hints); }
public static void GenerarCodigoQR() { string numero; Console.WriteLine("\nIngrese DNI del empleado para generar codigo QR:\n"); numero = Console.ReadLine(); foreach (var m in RepositorioGlobal.personasAutorizadas) { if (m.dni == numero) { Document doc = new Document(PageSize.A4); PdfWriter.GetInstance(doc, new FileStream($@"C:\Users\Usuario\Desktop\TPMenosCuatroMondinoFacundoDiseño\QR\QR{m.nombreApellido}.pdf", FileMode.Create)); doc.Open(); BarcodeQRCode codigoQR = new BarcodeQRCode(m.nombreApellido, 1000, 1000, null); Image codeQRImage = codigoQR.GetImage(); codeQRImage.ScaleAbsolute(200, 200); doc.Add(codeQRImage); doc.Close(); Console.WriteLine($"\nSe genero correctamente el Codigo QR del empleado: {m.nombreApellido}\n"); } } }
// =========================================================================== public void Write(Stream stream) { // step 1 using (Document document = new Document(new Rectangle(340, 842))) { // step 2 PdfWriter writer = PdfWriter.GetInstance(document, stream); // step 3 document.Open(); // step 4 PdfContentByte cb = writer.DirectContent; // EAN 13 document.Add(new Paragraph("Barcode EAN.UCC-13")); BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.Code = "4512345678906"; document.Add(new Paragraph("default:")); document.Add(codeEAN.CreateImageWithBarcode(cb, null, null)); codeEAN.GuardBars = false; document.Add(new Paragraph("without guard bars:")); document.Add(codeEAN.CreateImageWithBarcode(cb, null, null)); codeEAN.Baseline = -1f; codeEAN.GuardBars = true; document.Add(new Paragraph("text above:")); document.Add(codeEAN.CreateImageWithBarcode(cb, null, null)); codeEAN.Baseline = codeEAN.Size; // UPC A document.Add(new Paragraph("Barcode UCC-12 (UPC-A)")); codeEAN.CodeType = Barcode.UPCA; codeEAN.Code = "785342304749"; document.Add(codeEAN.CreateImageWithBarcode(cb, null, null)); // EAN 8 document.Add(new Paragraph("Barcode EAN.UCC-8")); codeEAN.CodeType = Barcode.EAN8; codeEAN.BarHeight = codeEAN.Size * 1.5f; codeEAN.Code = "34569870"; document.Add(codeEAN.CreateImageWithBarcode(cb, null, null)); // UPC E document.Add(new Paragraph("Barcode UPC-E")); codeEAN.CodeType = Barcode.UPCE; codeEAN.Code = "03456781"; document.Add(codeEAN.CreateImageWithBarcode(cb, null, null)); codeEAN.BarHeight = codeEAN.Size * 3f; // EANSUPP document.Add(new Paragraph("Bookland")); document.Add(new Paragraph("ISBN 0-321-30474-8")); codeEAN.CodeType = Barcode.EAN13; codeEAN.Code = "9781935182610"; BarcodeEAN codeSUPP = new BarcodeEAN(); codeSUPP.CodeType = Barcode.SUPP5; codeSUPP.Code = "55999"; codeSUPP.Baseline = -2; BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN, codeSUPP); document.Add(eanSupp.CreateImageWithBarcode(cb, null, BaseColor.BLUE)); // CODE 128 document.Add(new Paragraph("Barcode 128")); Barcode128 code128 = new Barcode128(); code128.Code = "0123456789 hello"; document.Add(code128.CreateImageWithBarcode(cb, null, null)); code128.Code = "0123456789\uffffMy Raw Barcode (0 - 9)"; code128.CodeType = Barcode.CODE128_RAW; document.Add(code128.CreateImageWithBarcode(cb, null, null)); // Data for the barcode : String code402 = "24132399420058289"; String code90 = "3700000050"; String code421 = "422356"; StringBuilder data = new StringBuilder(code402); data.Append(Barcode128.FNC1); data.Append(code90); data.Append(Barcode128.FNC1); data.Append(code421); Barcode128 shipBarCode = new Barcode128(); shipBarCode.X = 0.75f; shipBarCode.N = 1.5f; shipBarCode.Size = 10f; shipBarCode.TextAlignment = Element.ALIGN_CENTER; shipBarCode.Baseline = 10f; shipBarCode.BarHeight = 50f; shipBarCode.Code = data.ToString(); document.Add(shipBarCode.CreateImageWithBarcode( cb, BaseColor.BLACK, BaseColor.BLUE )); // it is composed of 3 blocks whith AI 01, 3101 and 10 Barcode128 uccEan128 = new Barcode128(); uccEan128.CodeType = Barcode.CODE128_UCC; uccEan128.Code = "(01)00000090311314(10)ABC123(15)060916"; document.Add(uccEan128.CreateImageWithBarcode( cb, BaseColor.BLUE, BaseColor.BLACK )); uccEan128.Code = "0191234567890121310100035510ABC123"; document.Add(uccEan128.CreateImageWithBarcode( cb, BaseColor.BLUE, BaseColor.RED )); uccEan128.Code = "(01)28880123456788"; document.Add(uccEan128.CreateImageWithBarcode( cb, BaseColor.BLUE, BaseColor.BLACK )); // INTER25 document.Add(new Paragraph("Barcode Interleaved 2 of 5")); BarcodeInter25 code25 = new BarcodeInter25(); code25.GenerateChecksum = true; code25.Code = "41-1200076041-001"; document.Add(code25.CreateImageWithBarcode(cb, null, null)); code25.Code = "411200076041001"; document.Add(code25.CreateImageWithBarcode(cb, null, null)); code25.Code = "0611012345678"; code25.ChecksumText = true; document.Add(code25.CreateImageWithBarcode(cb, null, null)); // POSTNET document.Add(new Paragraph("Barcode Postnet")); BarcodePostnet codePost = new BarcodePostnet(); document.Add(new Paragraph("ZIP")); codePost.Code = "01234"; document.Add(codePost.CreateImageWithBarcode(cb, null, null)); document.Add(new Paragraph("ZIP+4")); codePost.Code = "012345678"; document.Add(codePost.CreateImageWithBarcode(cb, null, null)); document.Add(new Paragraph("ZIP+4 and dp")); codePost.Code = "01234567890"; document.Add(codePost.CreateImageWithBarcode(cb, null, null)); document.Add(new Paragraph("Barcode Planet")); BarcodePostnet codePlanet = new BarcodePostnet(); codePlanet.Code = "01234567890"; codePlanet.CodeType = Barcode.PLANET; document.Add(codePlanet.CreateImageWithBarcode(cb, null, null)); // CODE 39 document.Add(new Paragraph("Barcode 3 of 9")); Barcode39 code39 = new Barcode39(); code39.Code = "ITEXT IN ACTION"; document.Add(code39.CreateImageWithBarcode(cb, null, null)); document.Add(new Paragraph("Barcode 3 of 9 extended")); Barcode39 code39ext = new Barcode39(); code39ext.Code = "iText in Action"; code39ext.StartStopText = false; code39ext.Extended = true; document.Add(code39ext.CreateImageWithBarcode(cb, null, null)); // CODABAR document.Add(new Paragraph("Codabar")); BarcodeCodabar codabar = new BarcodeCodabar(); codabar.Code = "A123A"; codabar.StartStopText = true; document.Add(codabar.CreateImageWithBarcode(cb, null, null)); // PDF417 document.Add(new Paragraph("Barcode PDF417")); BarcodePDF417 pdf417 = new BarcodePDF417(); String text = "Call me Ishmael. Some years ago--never mind how long " + "precisely --having little or no money in my purse, and nothing " + "particular to interest me on shore, I thought I would sail about " + "a little and see the watery part of the world." ; pdf417.SetText(text); Image img = pdf417.GetImage(); img.ScalePercent(50, 50 * pdf417.YHeight); document.Add(img); document.Add(new Paragraph("Barcode Datamatrix")); BarcodeDatamatrix datamatrix = new BarcodeDatamatrix(); datamatrix.Generate(text); img = datamatrix.CreateImage(); document.Add(img); document.Add(new Paragraph("Barcode QRCode")); BarcodeQRCode qrcode = new BarcodeQRCode( "Moby Dick by Herman Melville", 1, 1, null ); img = qrcode.GetImage(); document.Add(img); } }
private Cell MakeCell(string code, PdfDocument pdfDoc, PDFQRConfiguration settings) { var cell = new Cell(); cell.SetKeepTogether(true); cell.SetBorder(iText.Layout.Borders.Border.NO_BORDER); cell.SetHorizontalAlignment(HorizontalAlignment.CENTER); cell.SetVerticalAlignment(VerticalAlignment.MIDDLE); if (settings.PrefixAboveQR) { var p = new Paragraph(settings.Prefix); p.SetFontSize(settings.TopTextSize); p.SetTextAlignment(TextAlignment.CENTER); p.SetVerticalAlignment(VerticalAlignment.BOTTOM); p.SetMargin(0); p.SetPadding(0); cell.Add(p); } var qrParam = new Dictionary <EncodeHintType, object> { [EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.H, [EncodeHintType.CHARACTER_SET] = "ASCII" }; var codeInQR = ""; if (settings.IncludePrefixInQR) { codeInQR = $"{settings.Prefix}{code}"; } else { codeInQR = $"{code}"; } var barcode = new BarcodeQRCode(codeInQR, qrParam); var barcodeObject = barcode.CreateFormXObject(pdfDoc); // Create barcode object to put it to the cell as image var image = new Image(barcodeObject); image.SetMargins(0, 0, 0, 0); image.Scale(settings.Scale, settings.Scale); image.SetPadding(0); cell.Add(image); cell.SetPaddingTop(settings.CellPaddingTop); cell.SetPaddingRight(settings.CellPaddingRight); cell.SetPaddingBottom(settings.CellPaddingBottom); cell.SetPaddingLeft(settings.CellPaddingLeft); cell.SetBorder(iText.Layout.Borders.Border.NO_BORDER); if (settings.PrefixAboveQR) { var p = new Paragraph(code); p.SetFontSize(settings.BottomTextSize); p.SetTextAlignment(TextAlignment.CENTER); p.SetVerticalAlignment(VerticalAlignment.TOP); p.SetMargin(0); p.SetPadding(0); cell.Add(p); } else { var p = new Paragraph($"{settings.Prefix}{code}"); p.SetFontSize(settings.BottomTextSize); p.SetTextAlignment(TextAlignment.CENTER); p.SetVerticalAlignment(VerticalAlignment.TOP); p.SetMargin(0); p.SetPadding(0); cell.Add(p); } return(cell); }
public void PrintCertificate(string name, string qrUrl, Models.FileDocuments certificate, Models.Citizens trackParticipant) { PdfReader reader = new PdfReader(new RandomAccessFileOrArray(certificate.File), null); Rectangle size = reader.GetPageSizeWithRotation(1); Document document = new Document(size); using (MemoryStream ms = new MemoryStream()) using (PdfWriter writer = PdfWriter.GetInstance(document, ms)) { try { document.Open(); PdfContentByte cb = writer.DirectContentUnder; BaseFont bfb = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, false); BaseFont bfr = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false); //Open the document PdfImportedPage page = writer.GetImportedPage(reader, 1); cb.AddTemplate(page, 0, 0); cb.SetCharacterSpacing(0.5f); //cb.SetRGBColorFill(230, 20, 30); cb.SetRGBColorFill(0, 0, 0); cb.BeginText(); cb.SetFontAndSize(bfb, Convert.ToSingle(certificate.FontSize)); var x = (size.Width + Convert.ToSingle(certificate.NameXPosition)) / 2; var y = (size.Height + Convert.ToSingle(certificate.NameYPosition)) / 2; cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, trackParticipant.FullName, x, y, 0); cb.EndText(); //Peserta //cb.SetRGBColorFill(0, 0, 0); //cb.BeginText(); //cb.SetFontAndSize(bfb, Convert.ToSingle(26)); //x = (size.Width + Convert.ToSingle(certificate.NameXPosition)) / 2; //y = (size.Height + Convert.ToSingle(certificate.NameYPosition - 135)) / 2; //cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "PESERTA", x, y, 0); //cb.EndText(); //Judul Acara //cb.SetRGBColorFill(64, 64, 64); //cb.BeginText(); //cb.SetFontAndSize(bfr, Convert.ToSingle(25)); //x = (size.Width + Convert.ToSingle(certificate.NameXPosition)) / 2; //y = (size.Height + Convert.ToSingle(certificate.NameYPosition - 260)) / 2; //cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, trackParticipant.Track.Title, x, y, 0); //cb.EndText(); //Waktu Acara //cb.SetRGBColorFill(80, 80, 80); //cb.BeginText(); //cb.SetFontAndSize(bfr, Convert.ToSingle(16)); //x = (size.Width + Convert.ToSingle(certificate.NameXPosition)) / 2; //y = (size.Height + Convert.ToSingle(certificate.NameYPosition - 320)) / 2; //cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, trackParticipant.Track.Start.ToString("dddd dd MMMM yyyy", CultureInfo.CreateSpecificCulture("id-ID")) + " di "+ trackParticipant.Track.Location.Name, x, y, 0); //cb.EndText(); //background cb.SetColorStroke(new CMYKColor(1f, 0f, 0f, 0f)); cb.SetColorFill(new CMYKColor(0f, 0f, 0f, 0f)); x = Convert.ToSingle(certificate.QRXPosition); y = Convert.ToSingle(certificate.QRYPosition); var qrSize = 80; cb.MoveTo(x, y); cb.LineTo(x + qrSize, y); cb.LineTo(x + qrSize, y + qrSize); cb.LineTo(x, y + qrSize); cb.Fill(); BarcodeQRCode qrCode = new BarcodeQRCode(qrUrl, 1000, 1000, null); Image image = qrCode.GetImage(); image.SetAbsolutePosition(x, y); image.ScaleAbsolute(qrSize, qrSize); document.Add(image); document.Close(); writer.Close(); ms.Close(); var fileName = "Dokumen SI-Dital - " + qrUrl.ToUpper(); HttpContext.Response.ContentType = "pdf/application"; HttpContext.Response.AddHeader("content-disposition", "attachment;filename=" + fileName + ".pdf"); HttpContext.Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length); } catch (Exception ex) { System.Diagnostics.Trace.TraceError(ex.Message); } } }
public void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); Document doc = new Document(pdfDoc, new PageSize(340, 842)); // The default barcode EAN 13 type doc.Add(new Paragraph("Barcode EAN.UCC-13")); BarcodeEAN codeEAN = new BarcodeEAN(pdfDoc); codeEAN.SetCode("4512345678906"); doc.Add(new Paragraph("default:")); codeEAN.FitWidth(250); doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc))); codeEAN.SetGuardBars(false); doc.Add(new Paragraph("without guard bars:")); doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc))); codeEAN.SetBaseline(-1); codeEAN.SetGuardBars(true); doc.Add(new Paragraph("text above:")); doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc))); codeEAN.SetBaseline(codeEAN.GetSize()); // Barcode EAN UPC A type doc.Add(new Paragraph("Barcode UCC-12 (UPC-A)")); codeEAN.SetCodeType(BarcodeEAN.UPCA); codeEAN.SetCode("785342304749"); doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc))); // Barcode EAN 8 type doc.Add(new Paragraph("Barcode EAN.UCC-8")); codeEAN.SetCodeType(BarcodeEAN.EAN8); codeEAN.SetBarHeight(codeEAN.GetSize() * 1.5f); codeEAN.SetCode("34569870"); codeEAN.FitWidth(250); doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc))); // Barcode UPC E type doc.Add(new Paragraph("Barcode UPC-E")); codeEAN.SetCodeType(BarcodeEAN.UPCE); codeEAN.SetCode("03456781"); codeEAN.FitWidth(250); doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc))); codeEAN.SetBarHeight(codeEAN.GetSize() * 3); // Barcode EANSUPP type doc.Add(new Paragraph("Bookland - BarcodeEANSUPP")); doc.Add(new Paragraph("ISBN 0-321-30474-8")); codeEAN = new BarcodeEAN(pdfDoc); codeEAN.SetCodeType(BarcodeEAN.EAN13); codeEAN.SetCode("9781935182610"); BarcodeEAN codeSUPP = new BarcodeEAN(pdfDoc); codeSUPP.SetCodeType(BarcodeEAN.SUPP5); codeSUPP.SetCode("55999"); codeSUPP.SetBaseline(-2); BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN, codeSUPP); doc.Add(new Image(eanSupp.CreateFormXObject(null, ColorConstants.BLUE, pdfDoc))); // Barcode CODE 128 type doc.Add(new Paragraph("Barcode 128")); Barcode128 code128 = new Barcode128(pdfDoc); code128.SetCode("0123456789 hello"); code128.FitWidth(250); doc.Add(new Image(code128.CreateFormXObject(pdfDoc)) .SetRotationAngle(Math.PI / 2) .SetMargins(10, 10, 10, 10)); code128.SetCode("0123456789\uffffMy Raw Barcode (0 - 9)"); code128.SetCodeType(Barcode128.CODE128_RAW); code128.FitWidth(250); doc.Add(new Image(code128.CreateFormXObject(pdfDoc))); // Data for the barcode String code402 = "24132399420058289"; String code90 = "3700000050"; String code421 = "422356"; StringBuilder data = new StringBuilder(code402); data.Append(Barcode128.FNC1); data.Append(code90); data.Append(Barcode128.FNC1); data.Append(code421); Barcode128 shipBarCode = new Barcode128(pdfDoc); shipBarCode.SetX(0.75f); shipBarCode.SetN(1.5f); shipBarCode.SetSize(10f); shipBarCode.SetTextAlignment(Barcode1D.ALIGN_CENTER); shipBarCode.SetBaseline(10f); shipBarCode.SetBarHeight(50f); shipBarCode.SetCode(data.ToString()); shipBarCode.FitWidth(250); doc.Add(new Image(shipBarCode.CreateFormXObject(ColorConstants.BLACK, ColorConstants.BLUE, pdfDoc))); // CODE 128 type barcode, which is composed of 3 blocks with AI 01, 3101 and 10 Barcode128 uccEan128 = new Barcode128(pdfDoc); uccEan128.SetCodeType(Barcode128.CODE128_UCC); uccEan128.SetCode("(01)00000090311314(10)ABC123(15)060916"); uccEan128.FitWidth(250); doc.Add(new Image(uccEan128.CreateFormXObject(ColorConstants.BLUE, ColorConstants.BLACK, pdfDoc))); uccEan128.SetCode("0191234567890121310100035510ABC123"); uccEan128.FitWidth(250); doc.Add(new Image(uccEan128.CreateFormXObject(ColorConstants.BLUE, ColorConstants.RED, pdfDoc))); uccEan128.SetCode("(01)28880123456788"); uccEan128.FitWidth(250); doc.Add(new Image(uccEan128.CreateFormXObject(ColorConstants.BLUE, ColorConstants.BLACK, pdfDoc))); // Barcode INTER25 type doc.Add(new Paragraph("Barcode Interrevealed 2 of 5")); BarcodeInter25 code25 = new BarcodeInter25(pdfDoc); code25.SetGenerateChecksum(true); code25.SetCode("41-1200076041-001"); code25.FitWidth(250); doc.Add(new Image(code25.CreateFormXObject(pdfDoc))); code25.SetCode("411200076041001"); code25.FitWidth(250); doc.Add(new Image(code25.CreateFormXObject(pdfDoc))); code25.SetCode("0611012345678"); code25.SetChecksumText(true); code25.FitWidth(250); doc.Add(new Image(code25.CreateFormXObject(pdfDoc))); // Barcode POSTNET type doc.Add(new Paragraph("Barcode Postnet")); BarcodePostnet codePost = new BarcodePostnet(pdfDoc); doc.Add(new Paragraph("ZIP")); codePost.SetCode("01234"); codePost.FitWidth(250); doc.Add(new Image(codePost.CreateFormXObject(pdfDoc))); doc.Add(new Paragraph("ZIP+4")); codePost.SetCode("012345678"); codePost.FitWidth(250); doc.Add(new Image(codePost.CreateFormXObject(pdfDoc))); doc.Add(new Paragraph("ZIP+4 and dp")); codePost.SetCode("01234567890"); codePost.FitWidth(250); doc.Add(new Image(codePost.CreateFormXObject(pdfDoc))); // Barcode PLANET type doc.Add(new Paragraph("Barcode Planet")); BarcodePostnet codePlanet = new BarcodePostnet(pdfDoc); codePlanet.SetCode("01234567890"); codePlanet.SetCodeType(BarcodePostnet.TYPE_PLANET); codePlanet.FitWidth(250); doc.Add(new Image(codePlanet.CreateFormXObject(pdfDoc))); // Barcode CODE 39 type doc.Add(new Paragraph("Barcode 3 of 9")); Barcode39 code39 = new Barcode39(pdfDoc); code39.SetCode("ITEXT IN ACTION"); code39.FitWidth(250); doc.Add(new Image(code39.CreateFormXObject(pdfDoc))); doc.Add(new Paragraph("Barcode 3 of 9 extended")); Barcode39 code39ext = new Barcode39(pdfDoc); code39ext.SetCode("iText in Action"); code39ext.SetStartStopText(false); code39ext.SetExtended(true); code39ext.FitWidth(250); doc.Add(new Image(code39ext.CreateFormXObject(pdfDoc))); // Barcode CODABAR type doc.Add(new Paragraph("Codabar")); BarcodeCodabar codabar = new BarcodeCodabar(pdfDoc); codabar.SetCode("A123A"); codabar.SetStartStopText(true); codabar.FitWidth(250); doc.Add(new Image(codabar.CreateFormXObject(pdfDoc))); doc.Add(new AreaBreak()); // Barcode PDF417 type doc.Add(new Paragraph("Barcode PDF417")); BarcodePDF417 pdf417 = new BarcodePDF417(); String text = "Call me Ishmael. Some years ago--never mind how long " + "precisely --having little or no money in my purse, and nothing " + "particular to interest me on shore, I thought I would sail about " + "a little and see the watery part of the world."; pdf417.SetCode(text); PdfFormXObject xObject = pdf417.CreateFormXObject(pdfDoc); Image img = new Image(xObject); doc.Add(img.SetAutoScale(true)); doc.Add(new Paragraph("Barcode Datamatrix")); BarcodeDataMatrix datamatrix = new BarcodeDataMatrix(); datamatrix.SetCode(text); Image imgDM = new Image(datamatrix.CreateFormXObject(pdfDoc)); doc.Add(imgDM.ScaleToFit(250, 250)); // Barcode QRCode type doc.Add(new Paragraph("Barcode QRCode")); BarcodeQRCode qrcode = new BarcodeQRCode("Moby Dick by Herman Melville"); img = new Image(qrcode.CreateFormXObject(pdfDoc)); doc.Add(img.ScaleToFit(250, 250)); doc.Close(); }
public void createTable_NEW_QR(string FileName, int spl_id, string id_1) { System.Text.Encoding enc = new System.Text.UTF8Encoding(true, true); //Get the BOM byte[] bom = enc.GetPreamble(); //Get the raw bytes for the string byte[] bytes = enc.GetBytes(""); //Combine the byte arrays byte[] final = new byte[bom.Length + bytes.Length]; System.Buffer.BlockCopy(bom, 0, final, 0, bom.Length); System.Buffer.BlockCopy(bytes, 0, final, bom.Length, bytes.Length); var r = new Rectangle(160, 100) { //BackgroundColor=new BaseColor(179,227,238), remove this in original code Border = 0 }; Document dc = new Document(r, 0, 0, 0, 0); // PdfWriter writer = PdfWriter.GetInstance(dc, new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + FileName + "/" + spl_id + ".pdf", FileMode.Create)); PdfWriter writer = PdfWriter.GetInstance(dc, new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + FileName + "/" + id_1 + ".pdf", FileMode.Create)); dc.Open(); // BaseFont customfont = BaseFont.CreateFont("d:\\ss.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); BaseFont customfont = BaseFont.CreateFont(); int a = spl_id; //string connectionString = "Data Source=ALRAR;Persist Security Info=True;User ID=AMOGH;Password=ALRAR2020;Unicode=True"; OracleConnection conn = WebTools.GetIpmsConnection(); // string query = "SELECT iso_title1,spl_rev,spool,round(spl_size,2) as spl_size ,area_l1,round(weight,2),mat_type,line_no,unit FROM view_total_spool_list WHERE spl_id=" + spl_id; string query = "SELECT mat_code1,heat_no,nvl(paint_code,'NA') as paint_code,wall_thk,joint_thk,size1,nvl(mat_type,'XXX') as mat_type,substr(mat_descr,1,100) AS mat_descr, SubStr(mat_descr,101,100) AS mat_descr2, SubStr(mat_descr,201,100) AS mat_descr3 FROM view_bulk_paint_barcode WHERE spl_id=" + spl_id; OracleCommand cmd = new OracleCommand(query, conn); if (conn.State == ConnectionState.Closed) { conn.Open(); } OracleDataReader rdr = cmd.ExecuteReader(); // Font bigFont = new Font(Font.FontFamily.TIMES_ROMAN, 6.5f, Font.NORMAL); Font bigFont = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 8, Font.BOLD, BaseColor.BLACK); Font smallFont = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 7, Font.BOLD, BaseColor.BLACK); Font mediumFont = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 6, Font.BOLD, BaseColor.BLACK); Font mediumFont_a = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 4, Font.BOLD, BaseColor.BLACK); Font headfont = new Font(Font.FontFamily.COURIER, 14f, Font.BOLD); iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent; //table.AddCell(new Paragraph("Item code:" + rdr[0].ToString(), mediumFont)); //table.AddCell(new Paragraph("Paint Code:" + rdr[2].ToString(), mediumFont)); //table.AddCell(new Paragraph("Heat No:" + rdr[1].ToString(), mediumFont)); //table.AddCell(new Paragraph("Sch & Thk:" + rdr[3].ToString() + " & " + rdr[4].ToString(), mediumFont)); //table.AddCell(new Paragraph("Pipe-Size:" + rdr[5].ToString(), mediumFont)); //table.AddCell(new Paragraph("Main-Mat:" + rdr[6].ToString(), mediumFont)); //table.AddCell(new Paragraph("Pipe-Description:" + rdr[7].ToString(), mediumFont_a)); //table.AddCell(new Paragraph(rdr[8].ToString(), mediumFont_a)); //table.AddCell(new Paragraph(rdr[9].ToString(), mediumFont_a)); rdr.Read(); string s1 = "Item-Code / Paint-Code :" + " " + rdr[0].ToString() + "/" + rdr[2].ToString(); string s2 = " " + "Heat-No / Sch &Thk :" + " " + rdr[1].ToString() + "/" + rdr[3].ToString() + " & " + rdr[4].ToString(); string s3 = " " + "Pipe-Size / Main-Mat :" + rdr[5].ToString() + "/" + rdr[6].ToString(); string s4 = " " + "Pipe-Description :" + rdr[7].ToString(); BarcodeQRCode bcd = new BarcodeQRCode(s1.ToString() + " " + s2.ToString() + " " + s3.ToString() + " " + s4.ToString(), 10, 10, null); PdfPTable table = new PdfPTable(2); table.SetWidthPercentage(new float[] { 70, 70 }, r); //table.SetWidths(new float[] { 145, 80 }); table.SetWidths(new float[] { 100, 80 }); table.DefaultCell.Border = Rectangle.NO_BORDER; table.DefaultCell.NoWrap = true; // PdfPCell cell = new PdfPCell(new Paragraph("Petrofac / Rabigh")); //PdfPCell cell = new PdfPCell(new Paragraph("Petrofac / JI-2014", headfont)); PdfPCell cell = new PdfPCell(); cell.Image = iTextSharp.text.Image.GetInstance(bcd.GetImage()); cell.Colspan = 2; cell.Border = 0; cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right table.AddCell(cell); conn.Close(); dc.Add(table); dc.Close(); //Barcode128 bc = new Barcode128(); //bc.ChecksumText = true; //bc.Code = a.ToString().PadLeft(16, '0'); //bc.Size = 4; //bc.BarHeight = 15; //bc.Baseline = 4; //PdfPTable table = new PdfPTable(2); //// table.SetWidths(new float[]{158,68}); //table.SetWidthPercentage(new float[] { 100, 100 }, r); //table.SetWidths(new float[] { 145, 80 }); //table.DefaultCell.Border = Rectangle.NO_BORDER; //table.DefaultCell.NoWrap = true; //// PdfPCell cell = new PdfPCell(new Paragraph("Petrofac / Rabigh")); //PdfPCell cell = new PdfPCell(new Paragraph("Job: Petrofac/JI-2037", headfont)); //cell.Colspan = 2; //cell.Rowspan = 4; //cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right //cell.Border = 0; //cell.Padding = 4; //table.AddCell(cell); //cell = new PdfPCell(); //cell.Image = iTextSharp.text.Image.GetInstance(bc.CreateImageWithBarcode(cb, null, null)); //cell.Colspan = 2; //cell.Border = 0; //cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right //table.AddCell(cell); //rdr.Read(); //table.AddCell(new Paragraph("Item code:" + rdr[0].ToString(), mediumFont)); //table.AddCell(new Paragraph("Paint Code:" + rdr[2].ToString(), mediumFont)); //table.AddCell(new Paragraph("Heat No:" + rdr[1].ToString(), mediumFont)); //table.AddCell(new Paragraph("Sch & Thk:" + rdr[3].ToString() + " & " + rdr[4].ToString(), mediumFont)); //table.AddCell(new Paragraph("Pipe-Size:" + rdr[5].ToString(), mediumFont)); //table.AddCell(new Paragraph("Main-Mat:" + rdr[6].ToString(), mediumFont)); //table.AddCell(new Paragraph("Pipe-Description:" + rdr[7].ToString(), mediumFont_a)); //table.AddCell(new Paragraph(rdr[8].ToString(), mediumFont_a)); //table.AddCell(new Paragraph(rdr[9].ToString(), mediumFont_a)); //table.AddCell(""); ////NEW CONDITION //rdr.Close(); ////END //conn.Close(); //dc.Add(table); //dc.Close(); }
public IPdfReportData CreatePdfReport() { return(new PdfReport().DocumentPreferences(doc => { doc.RunDirection(PdfRunDirection.LeftToRight); doc.Orientation(PageOrientation.Portrait); doc.PageSize(PdfPageSize.A4); doc.DocumentMetadata(new DocumentMetadata { Author = "Vahid", Application = "PdfRpt", Keywords = "IList Rpt.", Subject = "Test Rpt", Title = "Test" }); doc.Compression(new CompressionSettings { EnableCompression = true, EnableFullCompression = true }); }) .DefaultFonts(fonts => { fonts.Path(System.IO.Path.Combine(Environment.GetEnvironmentVariable("SystemRoot"), "fonts\\arial.ttf"), System.IO.Path.Combine(Environment.GetEnvironmentVariable("SystemRoot"), "fonts\\verdana.ttf")); fonts.Size(9); fonts.Color(System.Drawing.Color.Black); }) .PagesFooter(footer => { var date = DateTime.Now.ToString("MM/dd/yyyy"); footer.InlineFooter(inlineFooter => { inlineFooter.FooterProperties(new FooterBasicProperties { PdfFont = footer.PdfFont, HorizontalAlignment = HorizontalAlignment.Center, RunDirection = PdfRunDirection.LeftToRight, SpacingBeforeTable = 30, TotalPagesCountTemplateHeight = 9, TotalPagesCountTemplateWidth = 50 }); inlineFooter.AddPageFooter(data => { return createFooter(footer, date, data); }); }); }) .PagesHeader(header => { header.InlineHeader(inlineHeader => { inlineHeader.AddPageHeader(data => { return createHeader(header); }); }); }) .MainTableTemplate(template => { template.BasicTemplate(BasicTemplate.ClassicTemplate); }) .MainTablePreferences(table => { table.ColumnsWidthsType(TableColumnWidthType.Relative); }) .MainTableDataSource(dataSource => { var listOfRows = new List <User>(); for (int i = 0; i < 200; i++) { listOfRows.Add(new User { Id = i, LastName = "LastName " + i, Name = "Name " + i, Balance = i + 1000 }); } dataSource.StronglyTypedList(listOfRows); }) .MainTableSummarySettings(summarySettings => { summarySettings.OverallSummarySettings("Summary"); summarySettings.PreviousPageSummarySettings("Previous Page Summary"); summarySettings.PageSummarySettings("Page Summary"); }) .MainTableColumns(columns => { columns.AddColumn(column => { column.PropertyName("rowNo"); column.IsRowNumber(true); column.CellsHorizontalAlignment(HorizontalAlignment.Center); column.IsVisible(true); column.Order(0); column.Width(1); column.HeaderCell("#"); }); columns.AddColumn(column => { column.PropertyName <User>(x => x.Id); column.CellsHorizontalAlignment(HorizontalAlignment.Center); column.IsVisible(true); column.Order(1); column.Width(2); column.HeaderCell("Id"); }); columns.AddColumn(column => { column.PropertyName <User>(x => x.Name); column.CellsHorizontalAlignment(HorizontalAlignment.Center); column.IsVisible(true); column.Order(2); column.Width(3); column.HeaderCell("Name"); }); columns.AddColumn(column => { column.PropertyName <User>(x => x.LastName); column.CellsHorizontalAlignment(HorizontalAlignment.Center); column.IsVisible(true); column.Order(3); column.Width(3); column.HeaderCell("Last Name"); }); columns.AddColumn(column => { column.PropertyName <User>(x => x.Balance); column.CellsHorizontalAlignment(HorizontalAlignment.Center); column.IsVisible(true); column.Order(4); column.Width(2); column.HeaderCell("Balance"); column.ColumnItemsTemplate(template => { template.TextBlock(); template.DisplayFormatFormula(obj => obj == null ? string.Empty : string.Format("{0:n0}", obj)); }); column.AggregateFunction(aggregateFunction => { aggregateFunction.NumericAggregateFunction(AggregateFunction.Sum); aggregateFunction.DisplayFormatFormula(obj => obj == null ? string.Empty : string.Format("{0:n0}", obj)); }); }); columns.AddColumn(column => { column.PropertyName <User>(x => x.Id); column.CellsHorizontalAlignment(HorizontalAlignment.Center); column.IsVisible(true); column.Order(5); column.Width(2); column.HeaderCell("QRCode"); column.ColumnItemsTemplate(itemsTemplate => { itemsTemplate.InlineField(inlineField => { inlineField.RenderCell(cellData => { var data = cellData.Attributes.RowData.TableRowData; var id = data.GetSafeStringValueOf <User>(x => x.Id); var qrcode = new BarcodeQRCode(id, 1, 1, null); var image = qrcode.GetImage(); var mask = qrcode.GetImage(); mask.MakeMask(); image.ImageMask = mask; // making the background color transparent var pdfCell = new PdfPCell(image, fit: false); return pdfCell; }); }); }); }); }) .MainTableEvents(events => { events.DataSourceIsEmpty(message: "There is no data available to display."); }) .Export(export => { export.ToExcel(); }) .Generate(data => data.AsPdfFile(string.Format("{0}\\Pdf\\InlineProvidersPdfReport-{1}.pdf", AppPath.ApplicationPath, Guid.NewGuid().ToString("N"))), debugMode: true)); }
//public void createTable_QR(string FileName, int spl_id, string id_1) //{ // //PdfPTable table = new PdfPTable(8); // //PdfPCell cell; // //cell = new PdfPCell(); // ////cell.setRowspan(2); // //cell.Rowspan = 2; // //table.AddCell(cell); // //for (int aw = 0; aw < 8; aw++) // //{ // // table.AddCell("hi"); // //} // System.Text.Encoding enc = new System.Text.UTF8Encoding(true, true); // //Get the BOM // byte[] bom = enc.GetPreamble(); // //Get the raw bytes for the string // byte[] bytes = enc.GetBytes(""); // //Combine the byte arrays // byte[] final = new byte[bom.Length + bytes.Length]; // System.Buffer.BlockCopy(bom, 0, final, 0, bom.Length); // System.Buffer.BlockCopy(bytes, 0, final, bom.Length, bytes.Length); // var r = new Rectangle(165, 71) // { // //BackgroundColor=new BaseColor(179,227,238), remove this in original code // Border = 0 // }; // Document dc = new Document(r, 0, 0, 0, 0); // PdfWriter writer = PdfWriter.GetInstance(dc, new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + FileName + "/" + id_1 + ".pdf", FileMode.Create)); // dc.Open(); // // BaseFont customfont = BaseFont.CreateFont("d:\\ss.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); // BaseFont customfont = BaseFont.CreateFont(); // int a = spl_id; // string connectionString = WebTools.GetIpmsConnection().ConnectionString; // OracleConnection conn = new OracleConnection(connectionString); // // string query = "SELECT iso_title1,spl_rev,spool,round(spl_size,2) as spl_size ,area_l1,round(weight,2),mat_type,line_no,unit FROM view_total_spool_list WHERE spl_id=" + spl_id; // string query = "SELECT iso_title1,spl_rev,spool,spl_size,area_l1,weight,unit,mat_type,line_no FROM view_bc_image_dt WHERE spl_id=" + spl_id; // OracleCommand cmd = new OracleCommand(query, conn); // conn.Open(); // OracleDataReader rdr = cmd.ExecuteReader(); // // Font bigFont = new Font(Font.FontFamily.TIMES_ROMAN, 6.5f, Font.NORMAL); // Font bigFont = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 6.3f, Font.BOLD, BaseColor.BLACK); // Font headfont = new Font(Font.FontFamily.COURIER, 14f, Font.BOLD); // iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent; // rdr.Read(); // string qrstring = rdr[0].ToString() + " / " + rdr[2].ToString(); // BarcodeQRCode bcd = new BarcodeQRCode(qrstring.ToString(), 7000, 7000, null); // // a table with three columns // PdfPTable table_100 = new PdfPTable(2); // // table_100.SetWidthPercentage(new float[] { 40, 120 }, r); // // table_100.SetWidths(new float[] { 50, 120 }); // table_100.SetWidthPercentage(new float[] { 75, 100 }, r); // table_100.SetWidths(new float[] { 75, 100 }); // table_100.DefaultCell.Border = Rectangle.NO_BORDER; // // the cell object // PdfPCell cell_100 = new PdfPCell(); // table_100.HorizontalAlignment = Element.ALIGN_LEFT; // cell_100.Border = 0; // cell_100.PaddingTop = 3; // cell_100.Image = iTextSharp.text.Image.GetInstance(bcd.GetImage()); // cell_100.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right // table_100.AddCell(cell_100); // //var splitter = "Iso:" + rdr[0].ToString() + "\n" + "\n" + "Spool:" + rdr[2].ToString(); // var splitter = "Line No :" + rdr[8].ToString() + "\n" + "\n" + "Iso:" + rdr[0].ToString() + "\n" + "\n" + "Spool:" + rdr[2].ToString() + "\n" + "\n" + "Weight:" + rdr[5].ToString(); // var splitter1 = splitter.Split('_'); // //var splitter1 = splitter.Split('_'); // iTextSharp.text.Paragraph paragraph; // paragraph = new Paragraph(); // paragraph.Add(new Chunk(ConvertStringArrayToString(splitter1), bigFont)); // cell_100 = new PdfPCell(paragraph); // cell_100.PaddingTop = 8; // cell_100.Border = 0; // table_100.AddCell(cell_100); // //table_100.AddCell(new Paragraph(ConvertStringArrayToString(splitter1), bigFont)); // conn.Close(); // dc.Add(table_100); // dc.Close(); //} public void createTable_QR(string FileName, int joint_id, string id_1) { System.Text.Encoding enc = new System.Text.UTF8Encoding(true, true); //Get the BOM byte[] bom = enc.GetPreamble(); //Get the raw bytes for the string byte[] bytes = enc.GetBytes(""); //Combine the byte arrays byte[] final = new byte[bom.Length + bytes.Length]; System.Buffer.BlockCopy(bom, 0, final, 0, bom.Length); System.Buffer.BlockCopy(bytes, 0, final, bom.Length, bytes.Length); var r = new Rectangle(216, 144) //var r = new Rectangle(216, 144) { //BackgroundColor=new BaseColor(179,227,238), remove this in original code }; Document dc = new Document(r, 0, 0, 0, 0); PdfWriter writer = PdfWriter.GetInstance(dc, new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + FileName + "/" + id_1 + ".pdf", FileMode.Create)); dc.Open(); BaseFont customfont = BaseFont.CreateFont(); int a = joint_id; OracleConnection conn = WebTools.GetIpmsConnection(); // string query = "SELECT iso_title1,spl_rev,spool,round(spl_size,2) as spl_size ,area_l1,round(weight,2),mat_type,line_no,unit FROM view_total_spool_list WHERE spl_id=" + spl_id; string query = "SELECT * FROM VIEW_BC_IMAGE_DETAIL_FLANGE WHERE JOINT_ID=" + joint_id; OracleCommand cmd = new OracleCommand(query, conn); if (conn.State == ConnectionState.Closed) { conn.Open(); } OracleDataReader rdr = cmd.ExecuteReader(); // Font bigFont = new Font(Font.FontFamily.TIMES_ROMAN, 6.5f, Font.NORMAL); Font bigFont = FontFactory.GetFont("Arial", BaseFont.CP1252, BaseFont.EMBEDDED, 7, Font.BOLD, BaseColor.BLACK); Font headfont = new Font(Font.FontFamily.COURIER, 14f, Font.BOLD); iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent; rdr.Read(); string qrstring = rdr[0].ToString() + " / " + rdr[2].ToString(); BarcodeQRCode bcd = new BarcodeQRCode(qrstring.ToString(), 300, 300, null); // a table with three columns PdfPTable table_100 = new PdfPTable(2); // table_100.SetWidthPercentage(new float[] { 40, 120 }, r); // table_100.SetWidths(new float[] { 50, 120 }); table_100.SetWidthPercentage(new float[] { 90, 170 }, r); table_100.SetWidths(new float[] { 90, 170 }); Font headerFont = new Font(Font.FontFamily.COURIER, 15f, Font.BOLD); PdfPCell cell = new PdfPCell(new Paragraph("Job: BIFP/P11570", headerFont)); cell.Colspan = 2; cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right cell.Border = 0; table_100.AddCell(cell); // the cell object PdfPCell cell_100 = new PdfPCell(); table_100.HorizontalAlignment = Element.ALIGN_LEFT; cell_100.Border = 0; cell_100.PaddingTop = 10; cell_100.PaddingRight = 0; cell_100.Image = iTextSharp.text.Image.GetInstance(bcd.GetImage()); cell_100.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right table_100.AddCell(cell_100); //var splitter = "Iso:" + rdr[0].ToString() + "\n" + "\n" + "Spool:" + rdr[2].ToString(); //var splitter = "\n" + "\n"+"Iso:" + rdr[0].ToString() + "\n" + "\n" + "Joint:" + rdr[2].ToString() + "\n" + "\n" + "Joint size:" + rdr[4].ToString(); var splitter = "Line No:" + rdr[8].ToString() + "\n" + "\n" + "Iso:" + rdr[0].ToString() + "\n" + "\n" + "Joint:" + rdr[2].ToString() + "\n" + "\n" + "Joint size:" + rdr[4].ToString() + "\n" + "\n" + "Item Code1:" + rdr[11].ToString() + "\n" + "\n" + "Item Code2:" + rdr[12].ToString(); var splitter1 = splitter.Split('_'); //var splitter1 = splitter.Split('_'); iTextSharp.text.Paragraph paragraph; paragraph = new Paragraph(); paragraph.Add(new Chunk(ConvertStringArrayToString(splitter1), bigFont)); cell_100 = new PdfPCell(paragraph); cell_100.PaddingTop = 15; cell_100.PaddingLeft = 0; cell_100.Border = 0; table_100.AddCell(cell_100); //table_100.AddCell(new Paragraph(ConvertStringArrayToString(splitter1), bigFont)); conn.Close(); dc.Add(table_100); dc.Close(); }