Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        /// <summary>
        /// Placeholder for what needs to be done after the content of a tag has been processed.
        /// </summary>
        /// <param name="element">the element node</param>
        /// <param name="context">the processor context</param>
        public void ProcessEnd(IElementNode element, ProcessorContext context)
        {
            float moduleSize = 1.8f;

            // Transform barcode into image
            qrCodeAsImage = new Image(qrCode.CreateFormXObject(ColorConstants.BLACK,
                                                               moduleSize, context.GetPdfDocument()));
        }
        /// <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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
 public virtual void ProcessEnd(IElementNode element, ProcessorContext context)
 {
     // Transform barcode into image
     qrCodeAsImage = new Image(qrCode.CreateFormXObject(context.GetPdfDocument()));
 }
Esempio n. 6
0
        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();
        }
Esempio n. 7
0
        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 ProcessEnd(IElementNode element, ProcessorContext context)
 {
     qrCodeAsImage = new Image(qrCode.CreateFormXObject(context.GetPdfDocument()));
 }