Esempio n. 1
0
        public byte[] CreateUserPdfList(List <User> users)
        {
            try
            {
                var ms       = new MemoryStream();                        //为系统内存提供流式的读写操作。常作为其他流数据交换时的中间对象操作
                var document = new Document(PageSize.A4, 40, 60, 40, 40); //

                var writer = PdfWriter.GetInstance(document, ms);
                document.Open();

                var currentPage = 1;
                var outterTable = new PdfPTable(1)
                {
                    WidthPercentage = 100
                };

                var innerTable = new PdfPTable(1);

                foreach (var user in users)
                {
                    PdfPTable bottomTable = new PdfPTable(2);

                    StringBuilder sb = new StringBuilder();
                    sb.Append("User:"******"(" + user.Id.ToString() + ")")))
                    {
                        BorderWidthLeft     = 0,
                        BorderWidthTop      = 0,
                        FixedHeight         = 120,
                        PaddingBottom       = 6,
                        HorizontalAlignment = Element.ALIGN_CENTER,
                        VerticalAlignment   = Element.ALIGN_MIDDLE,
                    });

                    innerTable.AddCell(new PdfPCell(bottomTable)
                    {
                        HorizontalAlignment = Element.ALIGN_RIGHT,
                        VerticalAlignment   = Element.ALIGN_MIDDLE,
                        BorderWidthTop      = 2,
                        BorderWidthBottom   = 0,
                    });
                }
                outterTable.AddCell(new PdfPCell(innerTable)
                {
                    PaddingLeft   = 10,
                    PaddingRight  = 5,
                    PaddingBottom = 10,
                    PaddingTop    = 10
                });
                document.Add(outterTable);
                document.NewPage();
                currentPage++;
                document.Close();
                return(ms.ToArray());
            }
            catch (Exception e)
            {
                Log.Error(e.StackTrace);
                return(null);
            }
        }
Esempio n. 2
0
        public byte[] CreateProcessPdf(Process process)
        {
            var ms       = new MemoryStream();                        //为系统内存提供流式的读写操作。常作为其他流数据交换时的中间对象操作
            var document = new Document(PageSize.A4, 40, 60, 40, 40); //

            var writer = PdfWriter.GetInstance(document, ms);

            document.Open();

            if (process.Procedures == null)
            {
                return(null);
            }

            var currentPage = 1;
            var totalPage   = 0;


            foreach (var procedure in process.Procedures)
            {
                totalPage += procedure.Seams.Count;
            }

            foreach (var procedure in process.Procedures)
            {
                foreach (var seam in procedure.Seams)
                {
                    var outterTable = new PdfPTable(1)
                    {
                        WidthPercentage = 100
                    };

                    var innerTable = new PdfPTable(1);

                    innerTable.AddCell(new PdfPCell(new Phrase("LY-XX"))
                    {
                        PaddingRight        = 10,
                        PaddingBottom       = 10,
                        Border              = 0,
                        HorizontalAlignment = Element.ALIGN_RIGHT
                    });


                    PdfPTable baseTable1 = new PdfPTable(7);
                    baseTable1.AddCell(Crtc("单    位"));
                    baseTable1.AddCell(new PdfPCell(new Phrase("焊接图表", new Font(BaseFont, 16)))
                    {
                        PaddingBottom       = 6,
                        BorderWidthTop      = 0,
                        BorderWidthLeft     = 0,
                        HorizontalAlignment = Element.ALIGN_CENTER,
                        VerticalAlignment   = Element.ALIGN_MIDDLE,
                        Rowspan             = 2
                    });
                    baseTable1.AddCell(Crtc("零件号"));
                    baseTable1.AddCell(Crtc(process.PartNo));
                    baseTable1.AddCell(Crtc("工序号"));
                    baseTable1.AddCell(Crtc("焊缝编号"));
                    baseTable1.AddCell(Crtc("第 " + currentPage + " 页"));
                    baseTable1.AddCell(Crtc("燃烧分厂"));
                    baseTable1.AddCell(Crtc("零件名称"));
                    baseTable1.AddCell(Crtc(process.PartName));
                    baseTable1.AddCell(Crtc(procedure.No));
                    baseTable1.AddCell(Crtc(seam.No));
                    baseTable1.AddCell(Crtc("共 " + totalPage + " 页"));

                    innerTable.AddCell(new PdfPCell(baseTable1)
                    {
                        BorderWidthRight  = 0,
                        BorderWidthBottom = 0
                    });


                    PdfPTable baseTable2 = new PdfPTable(4);

                    baseTable2.SetWidths(new float[] { 0.2f, 0.35f, 0.2f, 0.25f });
                    var metal = seam.Material1 + " + " + seam.Material2 + "   " + seam.Thick1 + " + " +
                                seam.Thick2;

                    baseTable2.AddCell(Crtc("材料牌号"));
                    baseTable2.AddCell(Crtc(seam.Material1 + " + " + seam.Material2, 1, 3));
                    baseTable2.AddCell(Crtc("材料规格"));
                    baseTable2.AddCell(Crtc(seam.Thick1 + " + " + seam.Thick2));
                    baseTable2.AddCell(Crtc("焊缝间隙"));
                    baseTable2.AddCell(Crtc(seam.Gap.ToString()));
                    baseTable2.AddCell(Crtc("工序名称"));
                    baseTable2.AddCell(Crtc(procedure.Name));
                    baseTable2.AddCell(Crtc("接头形式"));
                    baseTable2.AddCell(Crtc(seam.JointForm.ToString()));
                    baseTable2.AddCell(Crtc("工艺规程编号"));
                    baseTable2.AddCell(Crtc(process.No));
                    baseTable2.AddCell(Crtc("设备"));
                    baseTable2.AddCell(Crtc(""));


                    innerTable.AddCell(new PdfPCell(baseTable2)
                    {
                        BorderWidthRight  = 0,
                        BorderWidthBottom = 0,
                        BorderWidthTop    = 0
                    });


                    innerTable.AddCell(new PdfPCell(CreateParamsTable(procedure.WeldMethod, seam))
                    {
                        PaddingLeft    = 5,
                        PaddingRight   = 5,
                        PaddingBottom  = 20,
                        PaddingTop     = 8,
                        BorderWidthTop = 2
                    });
                    StringBuilder sb = new StringBuilder();
                    sb.Append("wcapp:");
                    sb.Append(process.Id + "-");
                    //sb.Append(process.No + "-");
                    sb.Append(process.VersionString + "-");
                    sb.Append(process.Id + "-");
                    sb.Append(procedure.No + "-");
                    sb.Append(seam.No.ToString());
                    var image = Image.GetInstance(QrCoder.Encode(sb.ToString()));
                    image.ScaleAbsolute(100, 100);
                    innerTable.AddCell(new PdfPCell(image)
                    {
                        Padding             = 15,
                        HorizontalAlignment = Element.ALIGN_RIGHT,
                        BorderWidthTop      = 1
                    });

                    PdfPTable bottomTable = new PdfPTable(2);

                    var cell = Crtc("签名/日期", -1);
                    cell.PaddingLeft = 10;
                    cell.FixedHeight = 120;
                    bottomTable.AddCell(cell);

                    bottomTable.SetWidths(new float[] { 0.7f, 0.3f });
                    bottomTable.AddCell(new PdfPCell(new Phrase("PDM印章", new Font(BaseFont, 32)))
                    {
                        BorderWidthLeft     = 0,
                        BorderWidthTop      = 0,
                        FixedHeight         = 120,
                        PaddingBottom       = 6,
                        HorizontalAlignment = Element.ALIGN_CENTER,
                        VerticalAlignment   = Element.ALIGN_MIDDLE,
                    });

                    innerTable.AddCell(new PdfPCell(bottomTable)
                    {
                        HorizontalAlignment = Element.ALIGN_RIGHT,
                        VerticalAlignment   = Element.ALIGN_MIDDLE,
                        BorderWidthTop      = 2,
                        BorderWidthBottom   = 0,
                    });

                    outterTable.AddCell(new PdfPCell(innerTable)
                    {
                        PaddingLeft   = 10,
                        PaddingRight  = 5,
                        PaddingBottom = 30,
                        PaddingTop    = 10
                    });

                    document.Add(outterTable);
                    document.NewPage();
                    currentPage++;
                }
            }

            document.Close();

            return(ms.ToArray());
        }