Exemple #1
0
        private void generarXMLTokens(LinkedList <Token> tokens)
        {
            string path = "archivo.xml";

            File.WriteAllText(path, "");

            iTextSharp.text.Document doc = new iTextSharp.text.Document();
            iTextSharp.text.pdf.PdfWriter.GetInstance(doc, new FileStream("reporte.pdf", FileMode.Create));
            doc.Open();
            iTextSharp.text.Paragraph titulo = new iTextSharp.text.Paragraph();
            titulo.Font = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA_BOLD, 18f, iTextSharp.text.BaseColor.ORANGE);
            titulo.Add("REPORTE DE TOKENS");
            doc.Add(titulo);
            doc.Add(new iTextSharp.text.Paragraph("\n"));

            doc.Add(new iTextSharp.text.Paragraph("\n"));

            doc.Add(new iTextSharp.text.Paragraph(""));

            iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(4);

            table.AddCell("Tokens");
            table.AddCell("Lexema");
            table.AddCell("Fila");
            table.AddCell("Columa");



            if (File.Exists(path))
            {
                using (StreamWriter file = File.AppendText(path))
                {
                    file.WriteLine("<ListaTokens>");
                    foreach (Token item in tokens)
                    {
                        table.AddCell(item.getToken());
                        table.AddCell(item.getValor());
                        table.AddCell(item.getFila().ToString());
                        table.AddCell(item.getColumna().ToString());
                        file.WriteLine(
                            "   <Token>\n" +
                            "       <Nombre>" + item.getToken() + "</Nombre>\n" +
                            "       <Valor>" + item.getValor() + "</Valor>\n" +
                            "       <Fila>" + item.getFila() + "</Fila>\n" +
                            "       <Columna>" + item.getColumna() + "</Columna>\n" +
                            "   </Token>\n");
                    }
                    file.WriteLine("</ListaTokens>");
                    Console.WriteLine("si se modifico");
                    file.Close();
                }
                doc.Add(table);
                doc.Close();
            }

            /*Process p = new Process();
             * p.StartInfo.FileName = path;
             * p.Start();*/
        }
        public void printOrder(List <Product> productsCart)
        {
            var    file        = Path.GetTempFileName();
            string filepath    = Path.GetTempPath();
            string strFilename = MainUtils.getCurrentTime("h_mm_ss") + ".pdf";

            using (MemoryStream ms = new MemoryStream())
            {
                iTextSharp.text.Document document = new iTextSharp.text.Document(getPageSize(), 20, 20, 15, 15);

                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(Path.Combine(filepath, strFilename), FileMode.Create));
                document.AddTitle("Document Title");
                document.Open();

                iTextSharp.text.pdf.BaseFont Vn_Helvetica      = iTextSharp.text.pdf.BaseFont.CreateFont(@"C:\Windows\Fonts\arial.ttf", "Identity-H", iTextSharp.text.pdf.BaseFont.EMBEDDED);
                iTextSharp.text.Font         titleFont         = new iTextSharp.text.Font(Vn_Helvetica, 18, iTextSharp.text.Font.BOLD);
                iTextSharp.text.Font         subTitleFont      = new iTextSharp.text.Font(Vn_Helvetica, 14, iTextSharp.text.Font.NORMAL);
                iTextSharp.text.Font         boldTableFont     = new iTextSharp.text.Font(Vn_Helvetica, 12, iTextSharp.text.Font.BOLD);
                iTextSharp.text.Font         endingMessageFont = new iTextSharp.text.Font(Vn_Helvetica, 10, iTextSharp.text.Font.NORMAL);
                iTextSharp.text.Font         bodyFont          = new iTextSharp.text.Font(Vn_Helvetica, 12, iTextSharp.text.Font.NORMAL);

                document.Add(new iTextSharp.text.Paragraph(Properties.Settings.Default.ShopName, titleFont));

                var orderInfoTable = new PdfPTable(2);
                orderInfoTable.HorizontalAlignment = 0;
                orderInfoTable.SpacingBefore       = 10;
                orderInfoTable.SpacingAfter        = 10;
                orderInfoTable.DefaultCell.Border  = 0;
                orderInfoTable.SetWidths(new int[] { 70, 150 });

                //Id of Order
                orderInfoTable.AddCell(new iTextSharp.text.Phrase("Mã đơn hàng: ", boldTableFont));
                orderInfoTable.AddCell("");
                double totalPrice = 0;

                //Products
                for (int i = 0; i < productsCart.Count; i++)
                {
                    int c = i + 1;
                    orderInfoTable.AddCell(new iTextSharp.text.Phrase("Sản phẩm " + c + ": ", boldTableFont));
                    orderInfoTable.AddCell(new iTextSharp.text.Phrase(productsCart[i].getName(), bodyFont));
                    orderInfoTable.AddCell(new iTextSharp.text.Phrase("Mã sản phẩm " + c + ": ", boldTableFont));
                    orderInfoTable.AddCell(productsCart[i].getpID());
                    orderInfoTable.AddCell(new iTextSharp.text.Phrase("Số lượng " + c + ": ", boldTableFont));
                    orderInfoTable.AddCell(productsCart[i].getQuantity().ToString());
                    totalPrice += double.Parse(productsCart[i].getPrice());
                }

                //Total price
                orderInfoTable.AddCell(new iTextSharp.text.Phrase("Tổng giá:", boldTableFont));
                orderInfoTable.AddCell(Convert.ToDecimal(totalPrice).ToString("###,###,###.00") + " dong");

                document.Add(orderInfoTable);

                document.Close();
            }
            System.Diagnostics.Process.Start(filepath + strFilename);
        }
        private void Imprimir_Click(object sender, EventArgs e)
        {
            if (dgvDados.RowCount == 0)
            {
                MessageBox.Show("Realize a pesquisa previamente");
            }
            else
            {
                SaveFileDialog saveFileDialog1 = new SaveFileDialog();

                saveFileDialog1.Filter = "PDF files (*.pdf)|*.pdf";

                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        using (var fileStream = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
                        {
                            var document  = new iTextSharp.text.Document();
                            var pdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(document, fileStream);
                            document.Open();

                            var paragraph = new iTextSharp.text.Paragraph("RELATÓRIO DE EMPRÉSTIMOS");
                            paragraph.Alignment = iTextSharp.text.Element.ALIGN_CENTER;
                            document.Add(paragraph);

                            paragraph           = new iTextSharp.text.Paragraph("DE: " + dtpInicio.Text + " ATÉ: " + dtpFim.Text);
                            paragraph.Alignment = iTextSharp.text.Element.ALIGN_CENTER;
                            document.Add(paragraph);

                            paragraph = new iTextSharp.text.Paragraph("\n");
                            document.Add(paragraph);

                            for (int i = 0; i < dgvDados.RowCount; i++)
                            {
                                DateTime data = DateTime.Parse(dgvDados.Rows[i].Cells[6].Value.ToString());

                                paragraph = new iTextSharp.text.Paragraph(dgvDados.Rows[i].Cells[2].Value.ToString() + "         " +
                                                                          dgvDados.Rows[i].Cells[3].Value.ToString() + "         " +
                                                                          dgvDados.Rows[i].Cells[4].Value.ToString() + "         " +
                                                                          dgvDados.Rows[i].Cells[5].Value.ToString() + "         " +
                                                                          data.ToString("d"));
                                paragraph.Alignment = iTextSharp.text.Element.ALIGN_JUSTIFIED;
                                document.Add(paragraph);
                            }
                            document.Close();
                            System.Diagnostics.Process.Start(saveFileDialog1.FileName);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "ATENÇÃO");
                    }
                }
            }
        }
Exemple #4
0
        public void Save(string fileName, Func <List <IElementRoot>, List <IElementRoot> > formatFunc = null)
        {
            if (formatFunc != null)
            {
                formatFunc.Invoke(Paragraphs);
            }

            string defaultFontPath = FontUtils.GetFontPath(ReportFactory.FontList, ReportFactory.FontStyle);

            iTextSharp.text.FontFactory.Register(defaultFontPath);

            using (var fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write))
            {
                PageSize currentPageSize = PageSize ?? ReportFactory.PageSize;

                PageOrientation           pageOrientation = PageOrientation ?? ReportFactory.PageOrientation;
                iTextSharp.text.Rectangle pageSize        = currentPageSize.ToRectangle(pageOrientation);
                using (var document = new iTextSharp.text.Document(pageSize))
                {
                    float marginTop    = MarginLeft ?? ReportFactory.MarginLeft;
                    float marginRight  = MarginLeft ?? ReportFactory.MarginRight;
                    float marginBottom = MarginLeft ?? ReportFactory.MarginBottom;
                    float marginLeft   = MarginLeft ?? ReportFactory.MarginLeft;
                    document.SetMargins(marginLeft, marginRight, marginTop, marginBottom);

                    iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, fileStream);
                    document.Open();

                    foreach (var para in Paragraphs)
                    {
                        if (para is Table)
                        {
                            iTextSharp.text.pdf.PdfPTable tableSource = para as Table;
                            document.Add(tableSource);
                        }
                        else if (para is Paragraph)
                        {
                            iTextSharp.text.Paragraph paragraph = para as Paragraph;
                            document.Add(paragraph);
                        }
                    }

                    document.Close();
                }

                fileStream.Close();
            }
        }
Exemple #5
0
        public void PrintPDFPage(bool hasMore = true)
        {
            if (!hasMore)
            {
                return;
            }
            //初始化图像对象
            var img = new Bitmap((int)(PaperSize.Width * 100 / 25.4), (int)(PaperSize.Height * 100 / 25.4));
            var g   = Graphics.FromImage(img);

            if (m_jsonData != null)
            {
                Canvas.DoPrintJson(m_jsonData[m_printPageIndex], new wPrintEventArgs(g, m_offset));
                hasMore = ++m_printPageIndex < m_jsonData.Count;
            }
            var ms = new System.IO.MemoryStream();

            img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            var img2 = iTextSharp.text.Image.GetInstance(ms.GetBuffer());

            //var img2 = iTextSharp.text.Image.GetInstance(img, iTextSharp.text.BaseColor.WHITE);
            img2.SetAbsolutePosition(0, 0);
            img2.ScalePercent(80);
            m_doc.Add(img2);
            if (hasMore)
            {
                m_doc.NewPage();
            }
            img.Dispose();
            ms.Dispose();
            PrintPDFPage(hasMore);
        }
Exemple #6
0
        public void Save(System.Drawing.Bitmap bm, string filename, System.Drawing.RotateFlipType rotate)
        {
            Bitmap image = bm;

            if (rotate != RotateFlipType.RotateNoneFlipNone)
            {
                image.RotateFlip(rotate);
            }

            using (FileStream stream = new FileStream(filename, FileMode.Create))
            {
                using (iTextSharp.text.Document pdfDocument = new iTextSharp.text.Document(PageSize.LETTER, PAGE_LEFT_MARGIN, PAGE_RIGHT_MARGIN, PAGE_TOP_MARGIN, PAGE_BOTTOM_MARGIN))
                {
                    iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDocument, stream);
                    pdfDocument.Open();

                    MemoryStream ms = new MemoryStream();
                    image.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff);
                    iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(ms);
                    img.ScaleToFit(PageSize.LETTER.Width - (PAGE_LEFT_MARGIN + PAGE_RIGHT_MARGIN), PageSize.LETTER.Height - (PAGE_TOP_MARGIN + PAGE_BOTTOM_MARGIN));
                    pdfDocument.Add(img);

                    pdfDocument.Close();
                    writer.Close();
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Text转成PDF
        /// </summary>
        /// <param name="sourcePath">源路径</param>
        /// <param name="targetPath">目标路径</param>
        /// <param name="fontPath">系统字体路径</param>
        /// <returns></returns>
        public static bool TextConvert(string sourcePath, string targetPath, string fontPath = default(string))
        {
            var path = fontPath != default(string) ? fontPath : FontPath;

            using (var objReader = new StreamReader(sourcePath, Encoding.Default))
            {
                iTextSharp.text.Document textDocument = null;
                try
                {
                    var baseFont = BaseFont.createFont(path, BaseFont.IDENTITY_H,
                                                       BaseFont.NOT_EMBEDDED);
                    var font = new Font(baseFont);
                    textDocument = new iTextSharp.text.Document();
                    PdfWriter.getInstance(textDocument, new FileStream(targetPath, FileMode.Create));
                    textDocument.Open();
                    var strRead = objReader.ReadToEnd();
                    textDocument.Add(new Paragraph(strRead == "" ? " " : strRead, font));
                    textDocument.Close();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    throw;
                }
                finally
                {
                    if (textDocument != null && textDocument.isOpen())
                    {
                        textDocument.Close();
                    }
                }
            }
            return(true);
        }
 void SavePDF()
 {
     iTextSharp.text.Document document = new iTextSharp.text.Document();
     using (var stream = new MemoryStream())
     {
         var writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, stream);
         writer.CloseStream = false;
         document.Open();
         foreach (Pixbuf pix in vimageslist1.Images)
         {
             if (pix.Width > pix.Height)
             {
                 document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
             }
             else
             {
                 document.SetPageSize(iTextSharp.text.PageSize.A4);
             }
             document.NewPage();
             var image = iTextSharp.text.Image.GetInstance(pix.SaveToBuffer("jpeg"));
             image.SetAbsolutePosition(0, 0);
             image.ScaleToFit(document.PageSize.Width, document.PageSize.Height);
             document.Add(image);
         }
         document.Close();
         stream.Position = 0;
         File            = stream.ToArray();
     }
 }
Exemple #9
0
        public static void Pdf(string filepath, string printData)
        {
            //simple file write check

            //using (System.IO.StreamWriter file =
            //new System.IO.StreamWriter(pdfFilePath, true))
            //{
            //    file.WriteLine("Fourth line");
            //}


            var author = "Dummy author";
            var stream = new FileStream(filepath, FileMode.Create);

            // step 1
            var document = new iTextSharp.text.Document();

            // step 2
            PdfWriter.GetInstance(document, stream);
            // step 3
            document.AddAuthor(author);
            document.Open();
            // step 4
            document.Add(new iTextSharp.text.Paragraph(printData));

            document.Close();
            stream.Dispose();
        }
Exemple #10
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     //saving the reciepts into pdf format for expenses
     using (SaveFileDialog sfd = new SaveFileDialog()
     {
         Filter = "PDF file|*.pdf", ValidateNames = true
     })
     {
         if (sfd.ShowDialog() == DialogResult.OK)
         {
             iTextSharp.text.Document doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4.Rotate());
             try
             {
                 PdfWriter.GetInstance(doc, new FileStream(sfd.FileName, FileMode.Create));
                 doc.Open();
                 doc.Add(new iTextSharp.text.Paragraph(rtLoanreciept1.Text));
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             finally
             {
                 doc.Close();
             }
         }
     }
 }
Exemple #11
0
        public void MergePDFs(string outPutFilePath, params string[] filesPath)
        {
            try
            {
                List <PdfReader> readerList = new List <PdfReader>();
                foreach (string filePath in filesPath)
                {
                    PdfReader pdfReader = new PdfReader(filePath);
                    readerList.Add(pdfReader);
                }

                iTextSharp.text.Document    document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0f, 0f, 0f, 20f);
                iTextSharp.text.pdf.PdfCopy writer   = new iTextSharp.text.pdf.PdfCopy(document, new System.IO.FileStream(outPutFilePath, System.IO.FileMode.Create));

                document.Open();
                foreach (PdfReader reader in readerList)
                {
                    for (int i = 1; i <= reader.NumberOfPages; i++)
                    {
                        PdfImportedPage page = writer.GetImportedPage(reader, i);
                        document.Add(iTextSharp.text.Image.GetInstance(page));
                    }

                    writer.AddDocument(reader);
                    reader.Close();
                }
                document.Close();
                writer.Close();
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
Exemple #12
0
        public void Export(string filename)
        {
            var       fileInfo      = new FileInfo(filename);
            var       directory     = fileInfo.Directory.FullName;
            var       imageFileInfo = $"{directory}\\{fileInfo.Name}-image.jpg";
            Rectangle bounds        = this.Bounds;

            using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
            {
                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
                }
                bitmap.Save(imageFileInfo, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            iTextSharp.text.Rectangle pageSize = null;

            using (var srcImage = new Bitmap(imageFileInfo))
            {
                pageSize = new iTextSharp.text.Rectangle(0, 0, srcImage.Width, srcImage.Height);
            }

            using (var ms = new MemoryStream())
            {
                var document = new iTextSharp.text.Document(pageSize, 0, 0, 0, 0);
                iTextSharp.text.pdf.PdfWriter.GetInstance(document, ms).SetFullCompression();
                document.Open();
                var image = iTextSharp.text.Image.GetInstance(imageFileInfo);
                document.Add(image);
                document.Close();

                File.WriteAllBytes(filename, ms.ToArray());
            }
        }
Exemple #13
0
        /* ----------------------------------------------------------------- */
        ///
        /// CreateFromImage
        ///
        /// <summary>
        /// 画像ファイルから PdfReader オブジェクトを生成します。
        /// </summary>
        ///
        /// <param name="src">画像ファイルのパス</param>
        /// <param name="io">入出力用オブジェクト</param>
        ///
        /// <returns>PdfReader オブジェクト</returns>
        ///
        /* ----------------------------------------------------------------- */
        public static PdfReader CreateFromImage(string src, IO io)
        {
            using (var ms = new System.IO.MemoryStream())
                using (var ss = io.OpenRead(src))
                    using (var image = Image.FromStream(ss))
                    {
                        Debug.Assert(image != null);
                        Debug.Assert(image.FrameDimensionsList != null);
                        Debug.Assert(image.FrameDimensionsList.Length > 0);

                        var doc    = new iTextSharp.text.Document();
                        var writer = PdfWriter.GetInstance(doc, ms);
                        doc.Open();

                        var guid = image.FrameDimensionsList[0];
                        var dim  = new FrameDimension(guid);
                        for (var i = 0; i < image.GetFrameCount(dim); ++i)
                        {
                            image.SelectActiveFrame(dim, i);

                            var scale = PdfFile.Point / image.HorizontalResolution;
                            var w     = image.Width * scale;
                            var h     = image.Height * scale;

                            doc.SetPageSize(new iTextSharp.text.Rectangle(w, h));
                            doc.NewPage();
                            doc.Add(image.GetItextImage());
                        }

                        doc.Close();
                        writer.Close();

                        return(new PdfReader(ms.ToArray()));
                    }
        }
Exemple #14
0
        /// <summary>
        /// create overview table
        /// </summary>
        /// <param name="pdfDocument"></param>
        /// <param name="pdfFont"></param>
        /// <param name="tables"></param>
        private static void CreateOverviewTable(iTextSharp.text.Document pdfDocument, iTextSharp.text.Font pdfFont, List <TableDto> tables)
        {
            // TODO 创建表格
            iTextSharp.text.pdf.PdfPTable pdfTable = new iTextSharp.text.pdf.PdfPTable(3);

            // TODO 添加列标题
            pdfTable.AddCell(CreatePdfPCell("序号", pdfFont));
            pdfTable.AddCell(CreatePdfPCell("表名", pdfFont));
            pdfTable.AddCell(CreatePdfPCell("注释/说明", pdfFont));
            foreach (var table in tables)
            {
                // TODO 添加数据行,循环数据库表字段
                pdfTable.AddCell(CreatePdfPCell(table.TableOrder, pdfFont));
                pdfTable.AddCell(CreatePdfPCell(table.TableName, pdfFont));
                pdfTable.AddCell(CreatePdfPCell((!string.IsNullOrWhiteSpace(table.Comment) ? table.Comment : ""), pdfFont));
            }

            // TODO 设置表格居中
            pdfTable.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
            pdfTable.TotalWidth          = 330F;
            pdfTable.LockedWidth         = true;
            pdfTable.SetWidths(new float[] { 60F, 120F, 150F });

            // TODO 添加表格
            pdfDocument.Add(pdfTable);
        }
Exemple #15
0
        public static void pdfMain(string[] args, string strFileName)
        {
            int ishave = 0;

            string[] files = { @"D:\Devlop\PIC_control\PicFile_Managerment\PicFile_Managerment\bin\Debug\FileList\0x1024a0a0.jpg", @"D:\Devlop\PIC_control\PicFile_Managerment\PicFile_Managerment\bin\Debug\FileList\1.jpg" };
            files = args;
            iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
            try
            {
                iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(strFileName, FileMode.Create, FileAccess.ReadWrite));
                document.Open();
                iTextSharp.text.Image image;


                for (int i = 0; i < files.Length; i++)
                {
                    if (String.IsNullOrEmpty(files[i]))
                    {
                        break;
                    }

                    if (File.Exists(files[i]))
                    {
                        image = iTextSharp.text.Image.GetInstance(files[i]);
                    }
                    else
                    {
                        continue;
                    }

                    if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
                    {
                        image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
                    }
                    else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
                    {
                        image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
                    }
                    image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
                    document.NewPage();
                    document.Add(image);
                    ishave++;

                    //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
                    //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
                    //p1.Leading = 150;      //行间距
                    //document.Add(p1);
                }
                Console.WriteLine("转换成功!");
            }
            catch (Exception ex)
            {
                Console.WriteLine("转换失败,原因:" + ex.Message);
            }
            if (ishave != 0)
            {
                document.Close();
            }
            //Console.ReadKey();
        }
        public static void AddPic(iTextSharp.text.Document document, string imagefile, int chartid, Canvas canvas)
        {
            ImageFromPieControl(imagefile, chartid, canvas);
            iTextSharp.text.Image pdfimage = iTextSharp.text.Image.GetInstance(imagefile);
            pdfimage.SetDpi(300, 300);
            float left = 425;

            if (chartid == 2)
            {
                pdfimage.ScaleAbsolute(120, 120 * (550f / 350f));
                left = 440;
            }
            else
            {
                pdfimage.ScaleToFit(140, 140);
            }
            float y = 0;

            switch (chartid)
            {
            case 0:
                y = 600;
                break;

            case 1:
                y = 365;
                break;

            case 2:
                y = 45;
                break;
            }
            pdfimage.SetAbsolutePosition(left, y);
            document.Add(pdfimage);
        }
Exemple #17
0
        /// <summary>
        /// create log table
        /// </summary>
        /// <param name="pdfDocument"></param>
        /// <param name="pdfFont"></param>
        /// <param name="tables"></param>
        private static void CreateLogTable(iTextSharp.text.Document pdfDocument, iTextSharp.text.Font pdfFont, List <TableDto> tables)
        {
            // TODO 创建表格
            iTextSharp.text.pdf.PdfPTable pdfTable = new iTextSharp.text.pdf.PdfPTable(5);

            // TODO 添加列标题
            pdfTable.AddCell(CreatePdfPCell("版本号", pdfFont));
            pdfTable.AddCell(CreatePdfPCell("修订日期", pdfFont));
            pdfTable.AddCell(CreatePdfPCell("修订内容", pdfFont));
            pdfTable.AddCell(CreatePdfPCell("修订人", pdfFont));
            pdfTable.AddCell(CreatePdfPCell("审核人", pdfFont));
            for (var i = 0; i < 16; i++)
            {
                // TODO 添加数据行,循环数据库表字段
                pdfTable.AddCell(CreatePdfPCell("", pdfFont));
                pdfTable.AddCell(CreatePdfPCell("", pdfFont));
                pdfTable.AddCell(CreatePdfPCell("", pdfFont));
                pdfTable.AddCell(CreatePdfPCell("", pdfFont));
                pdfTable.AddCell(CreatePdfPCell("", pdfFont));
            }

            // TODO 设置表格居中
            pdfTable.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
            pdfTable.TotalWidth          = 540F;
            pdfTable.LockedWidth         = true;
            pdfTable.SetWidths(new float[] { 80F, 100F, 200F, 80F, 80F });

            // TODO 添加表格
            pdfDocument.Add(pdfTable);
        }
Exemple #18
0
        /// <summary>
        /// Creates a PDF from html string
        /// </summary>
        /// <param name="htmlContent">The HTML content to be converted</param>
        /// <param name="pageSize">The size of the output page</param>
        /// <returns></returns>
        public MemoryStream CreatePDFFromHtml(string htmlContent, iTextSharp.text.Rectangle pageSize)
        {
            MemoryStream ms = new MemoryStream();

            //Step 1: Create a Docuement-Object
            iTextSharp.text.Document document = new iTextSharp.text.Document(pageSize);

            //Step 2: we create a writer that listens to the document
            iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, ms);

            //Step 3: Open the document
            document.Open();

            // Add a new page to the pdf file
            document.NewPage();

            //make an arraylist ....with STRINGREADER since its no IO reading file...
            List <iTextSharp.text.IElement> htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(htmlContent), null);

            //add the collection to the document
            for (int k = 0; k < htmlarraylist.Count; k++)
            {
                document.Add((iTextSharp.text.IElement)htmlarraylist[k]);
            }

            document.Close();

            return(ms);
        }
Exemple #19
0
        public static string SavePDF(string strInputFile, string strOutputFile)
        {
            iTextSharp.text.Document doc = null;
            try
            {
                iTextSharp.text.Image     img         = iTextSharp.text.Image.GetInstance(strInputFile);
                iTextSharp.text.Rectangle rectDocSize = new iTextSharp.text.Rectangle(img.Width, img.Height);
                doc = new iTextSharp.text.Document(rectDocSize);

                iTextSharp.text.pdf.PdfWriter.GetInstance(doc, new FileStream(strOutputFile, FileMode.Create));
                doc.Open();
                //doc.Add(new iTextSharp.text.Paragraph("GIF"));
                doc.Add(img);
            }
            catch (iTextSharp.text.DocumentException dex)
            {
                throw dex;
            }
            catch (IOException ioex)
            {
                throw ioex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (doc != null)
                {
                    doc.Close();
                }
            }
            return(strOutputFile);
        }
Exemple #20
0
        void ConvertJPG2PDF(string jpgfile, string pdf)
        {
            iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
            using (Stream stream = new FileStream(pdf, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                PdfWriter.GetInstance(document, stream);
                document.Open();
                using (FileStream imageStream = new FileStream(jpgfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(imageStream);
                    if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
                    {
                        image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
                    }
                    else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
                    {
                        image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
                    }
                    image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
                    document.Add(image);
                }

                document.Close();
            }
        }
Exemple #21
0
        public static string SavePDF(string strInputFile, string strOutputFile)
        {
            iTextSharp.text.Document doc = null;
            try
            {
                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(strInputFile);
                iTextSharp.text.Rectangle rectDocSize = new iTextSharp.text.Rectangle(img.Width, img.Height);
                doc = new iTextSharp.text.Document(rectDocSize);

                iTextSharp.text.pdf.PdfWriter.GetInstance(doc, new FileStream(strOutputFile, FileMode.Create));
                doc.Open();
                //doc.Add(new iTextSharp.text.Paragraph("GIF"));
                doc.Add(img);
            }
            catch (iTextSharp.text.DocumentException dex)
            {
                throw dex;
            }
            catch (IOException ioex)
            {
                throw ioex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if(doc != null)
                    doc.Close();
            }
            return strOutputFile;
        }
Exemple #22
0
        public static void CreatePDF(Image image, string filePath, ImageFormat format)
        {
            string directoryPath = Path.GetDirectoryName(filePath);
            string filename      = Path.GetFileNameWithoutExtension(filePath);

            iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER);
            try
            {
                var writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(Path.Combine(directoryPath, filename) + ".pdf", FileMode.Create));

                document.Open();
                iTextSharp.text.Image     pic       = iTextSharp.text.Image.GetInstance(image, format);
                iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph();
                pic.Border          = 1;
                pic.BorderColor     = iTextSharp.text.BaseColor.BLACK;
                paragraph.Alignment = iTextSharp.text.Element.ALIGN_CENTER;
                paragraph.Add(pic);
                document.Add(paragraph);
                document.NewPage();
            }
            catch (iTextSharp.text.DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }
            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }
            document.Close();
        }
        private static void ConvertToPdfUsingiTextSharp(string source, string destination)
        {
            try
            {
                iTextSharp.text.Rectangle pageSize;

                using (var srcImage = new Bitmap(source))
                {
                    pageSize = new iTextSharp.text.Rectangle(0, 0, srcImage.Width, srcImage.Height);
                }

                using (var ms = new MemoryStream())
                {
                    var document = new iTextSharp.text.Document(pageSize, 0, 0, 0, 0);
                    iTextSharp.text.pdf.PdfWriter.GetInstance(document, ms).SetFullCompression();
                    document.Open();

                    var image = iTextSharp.text.Image.GetInstance(source);
                    document.Add(image);
                    document.Close();

                    File.WriteAllBytes(destination, ms.ToArray());
                }
            }
            catch (Exception ex)
            {
                FileLogger.SetLog(string.Format(ExceptionConstants.ConvertToPdf, source, ex.Message));
            }
        }
Exemple #24
0
        private byte[] ConvertJPG2PDF(Stream imageStream)
        {
            iTextSharp.text.Document document  = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
            MemoryStream             memStream = new MemoryStream();

            PdfWriter wr = PdfWriter.GetInstance(document, memStream);

            document.Open();

            iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(imageStream);
            if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
            {
                image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
            }
            else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
            {
                image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
            }
            image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
            document.Add(image);

            document.Close();

            return(memStream.ToArray());
        }
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            using (var ms = new MemoryStream())
            {
                var document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER.Rotate(), 0, 0, 0, 0);
                iTextSharp.text.pdf.PdfWriter.GetInstance(document, ms).SetFullCompression();
                document.Open();

                foreach (System.Drawing.Image aa in obj)
                {
                    MemoryStream msimage = new MemoryStream();

                    aa.Save(msimage, ImageFormat.Jpeg);

                    var image = iTextSharp.text.Image.GetInstance(msimage.ToArray());
                    image.ScaleToFit(document.PageSize.Width, document.PageSize.Height);
                    document.Add(image);
                }
                document.Close();

                string Path = ConfigurationManager.AppSettings["uploadfolderpath"].ToString();


                string filename = "C3kycDMS" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".pdf";

                File.WriteAllBytes(Path + filename, ms.ToArray());
                byte[] test = ms.ToArray();


                MessageBox.Show("File Uploaded Successfully", "Success!", MessageBoxButton.OKCancel);
                pic_scan.Source = null;
            }
        }
Exemple #26
0
 public void CrearPdf(string filePath, List <T> lista)
 {
     try {
         iTextSharp.text.Document doc = new iTextSharp.text.Document();
         PdfWriter.GetInstance(doc, new FileStream(filePath, FileMode.Create));
         doc.Open();
         foreach (object objeto in lista)
         {
             doc.Add(new iTextSharp.text.Paragraph(objeto.ToString()));
             doc.Add(new iTextSharp.text.Paragraph("-----------------------------------------------------------------------------------"));
         }
         doc.Close();
     } catch (Exception e) {
         throw e;
     }
 }
Exemple #27
0
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        internal bool CreatePDF(string PDFPath, ProgressBar PBar)
        {
            try
            {
                if (Tabs.Count > 0)
                {
                    PBar.Invoke(new Action(() =>
                    {
                        PBar.Maximum = Tabs.Count;
                        PBar.Value   = 0;
                        PBar.Visible = true;
                        PBar.Style   = ProgressBarStyle.Marquee;
                    }));
                    if (File.Exists(PDFPath))
                    {
                        File.Delete(PDFPath);
                    }
                    var CurDocument  = new iTextSharp.text.Document();
                    var CurPdfWriter = PdfWriter.GetInstance(CurDocument, new FileStream(PDFPath, FileMode.Create, FileAccess.Write, FileShare.None));
                    CurPdfWriter.SetFullCompression();
                    Tabs = Tabs.OrderBy(o => o.Index).ToList();
                    for (int i = 0; i < Tabs.Count; i++)
                    {
                        var CurImage     = Tabs[i].ScannedImage;
                        var CurRectangle = new iTextSharp.text.Rectangle(CurImage.Width, CurImage.Height);
                        CurDocument.SetPageSize(CurRectangle);
                        CurDocument.SetMargins(0, 0, 0, 0);
                        if (i == 0)
                        {
                            CurDocument.Open();
                        }
                        if (i < (Tabs.Count - 1))
                        {
                            CurDocument.NewPage();
                        }
                        CurDocument.Add(iTextSharp.text.Image.GetInstance(CurImage, (iTextSharp.text.BaseColor)null));
                        PBar.Invoke(new Action(() =>
                        {
                            PBar.Style = ProgressBarStyle.Continuous;
                            PBar.Value++;
                        }));
                    }
                    CurDocument.Close();
                }
                else
                {
                    MessageBox.Show("Keine Scanns vorhanden");
                }
                GC.Collect();
                return(true);
            }
            catch (Exception ex)
            {
                Program.MeldeFehler(ex.Message + "\n" + ex.StackTrace);
                Environment.Exit(1);
                return(false);
            }
        }
Exemple #28
0
        /// <summary>
        /// Create a new PDF document from contents
        /// </summary>
        /// <param name="path"></param>
        /// <param name="contents"></param>
        /// <param name="page"></param>
        /// <param name="marginLeft"></param>
        /// <param name="marginTop"></param>
        /// <param name="marginRight"></param>
        /// <param name="marginBottom"></param>
        public static void CreateNewPDF(string path, IEnumerable <object> contents, Content.Page page, double marginLeft = 5, double marginTop = 10, double marginRight = 5, double marginBottom = 10)
        {
            FileStream fs = new System.IO.FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);

            iTextSharp.text.Document doc = new iTextSharp.text.Document(page.ToPDF());
            PdfWriter writer             = PdfWriter.GetInstance(doc, fs);

            doc.SetMargins((float)marginLeft, (float)marginRight, (float)marginTop, (float)marginBottom);

            doc.Open();

            foreach (object content in contents)
            {
                var t = content.GetType();

                if (content.GetType().GetInterfaces().Contains(typeof(Content.IPDFContent)))
                {
                    if (content.GetType() == typeof(Content.PageBreak))
                    {
                        doc.NewPage();
                    }
                    else
                    {
                        Content.IPDFContent co = content as Content.IPDFContent;
                        doc.Add(co.ToPDF());
                    }
                }
                else
                {
                    if (content.GetType() == typeof(Geometries.PDFGeometry))
                    {
                        Geometries.PDFGeometry l = (Geometries.PDFGeometry)content;
                        l.ToPDF(writer);
                    }
                    else
                    {
                        doc.Add(new iTextSharp.text.Paragraph(content.ToString()));
                    }
                }
            }


            doc.Close();
        }
Exemple #29
0
        //image to pdf method
        public void Convert(string dir)
        {
            System.IO.DirectoryInfo di       = new System.IO.DirectoryInfo(dir);
            System.IO.FileInfo[]    pngfiles = di.GetFiles("*.png", System.IO.SearchOption.AllDirectories);
            System.IO.FileInfo[]    jpgfiles = di.GetFiles("*.jpg", System.IO.SearchOption.AllDirectories);

            Console.WriteLine(pngfiles.Length);
            Console.WriteLine(jpgfiles.Length);

            string[] paths = new string[pngfiles.Length + jpgfiles.Length];
            Console.WriteLine(paths.Length);
            var i = -1;

            foreach (var p in pngfiles)
            {
                i++;
                paths[i] = dir + "/" + p.ToString();
            }
            foreach (var p in jpgfiles)
            {
                i++;
                paths[i] = dir + "/" + p.ToString();
            }


            iTextSharp.text.Rectangle pageSize = null;

            using (var srcImage = new Bitmap(paths[0].ToString()))
            {
                pageSize = new iTextSharp.text.Rectangle(0, 0, srcImage.Width, srcImage.Height);
            }

            using (var ms = new MemoryStream())
            {
                var document = new iTextSharp.text.Document(pageSize, 0, 0, 0, 0);
                iTextSharp.text.pdf.PdfWriter.GetInstance(document, ms).SetFullCompression();
                document.Open();

                //progress.Maximum = paths.Length;
                //progress.Value = 0;
                var prg = 0;
                foreach (var ii in paths)
                {
                    label.Content = ii;
                    var image = iTextSharp.text.Image.GetInstance(ii.ToString());
                    document.SetPageSize(new iTextSharp.text.Rectangle(0, 0, image.Width, image.Height));
                    document.Add(image);

                    //progress.Value = prg;
                }
                document.Close();

                File.WriteAllBytes(dir + ".pdf", ms.ToArray());
                label.Content = "Conversion complete !";
            }
        }
Exemple #30
0
        private HttpResponseMessage GetPdfResponseForDictionary(Dictionary dictionary)
        {
            iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4);
            var memoryStream = new MemoryStream();

            iTextSharp.text.pdf.PdfWriter.GetInstance(document, memoryStream);

            document.Open();
            string ARIALUNI_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");

            iTextSharp.text.pdf.BaseFont baseFont = iTextSharp.text.pdf.BaseFont.CreateFont(
                ARIALUNI_TFF, iTextSharp.text.pdf.BaseFont.IDENTITY_H, iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, 14, iTextSharp.text.Font.NORMAL);

            uint rowNumber = 1;

            foreach (var phrasesPair in dictionary.PhrasesPairs.OrderBy(p => p.FirstPhrase.Text))
            {
                document.Add(new iTextSharp.text.Paragraph(
                                 string.Format("{0}) {1} - {2}", rowNumber++, phrasesPair.FirstPhrase.Text, phrasesPair.SecondPhrase.Text),
                                 font));
            }
            document.NewPage();
            rowNumber = 1;
            foreach (var phrasesPair in dictionary.PhrasesPairs.OrderBy(p => p.SecondPhrase.Text))
            {
                document.Add(new iTextSharp.text.Paragraph(
                                 string.Format("{0}) {1} - {2}", rowNumber++, phrasesPair.SecondPhrase.Text, phrasesPair.FirstPhrase.Text),
                                 font));
            }
            document.AddAuthor(dictionary.OwnerId);
            document.Close();

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);

            response.Content = new ByteArrayContent(memoryStream.ToArray());
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
            string filename = string.Format("{0}.pdf", dictionary.Name);

            response.Content.Headers.ContentDisposition.FileName = Uri.EscapeUriString(filename);
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
            return(response);
        }
        /// <summary>
        /// InCorrect answers paragraph
        /// </summary>
        private void WriterInCorrectAnswers(iTextSharp.text.Document doc)
        {
            iTextSharp.text.Paragraph InCorrectAnswers = new iTextSharp.text.Paragraph();
            InCorrectAnswers.Font.Color = new iTextSharp.text.BaseColor(Color.DarkRed);
            InCorrectAnswers.Alignment  = iTextSharp.text.Element.ALIGN_CENTER;
            InCorrectAnswers.Add($"\n\n\nInCorrect Answers\n\n");


            doc.Add(InCorrectAnswers);
            InCorrectAnswers.Clear();

            foreach (var question in report.InCorrects)
            {
                InCorrectAnswers.Font.Color = new iTextSharp.text.BaseColor(Color.Black);
                InCorrectAnswers.Alignment  = iTextSharp.text.Element.ALIGN_LEFT;
                InCorrectAnswers.Add(question.Text);
                doc.Add(InCorrectAnswers);
                InCorrectAnswers.Clear();


                InCorrectAnswers.Alignment = iTextSharp.text.Element.ALIGN_CENTER;
                foreach (var answer in question.Answers)
                {
                    if (answer.IsCorrect == "Yes")
                    {
                        InCorrectAnswers.Font.Color = new iTextSharp.text.BaseColor(Color.DarkGreen);
                    }
                    else if (report.YourAnswers[question.id] == answer.Text)
                    {
                        InCorrectAnswers.Font.Color = new iTextSharp.text.BaseColor(Color.DarkRed);
                    }
                    else
                    {
                        InCorrectAnswers.Font.Color = new iTextSharp.text.BaseColor(Color.DarkGray);
                    }


                    InCorrectAnswers.Add(answer.Text);
                    doc.Add(InCorrectAnswers);
                    InCorrectAnswers.Clear();
                }
            }
        }
Exemple #32
0
        public static void ConvertImageToPdf(string srcFilename, string dstFilename)
        {
            iTextSharp.text.Rectangle pageSize = null;

            using (var srcImage = new Bitmap(srcFilename))
            {
                pageSize = new iTextSharp.text.Rectangle(0, 0, srcImage.Width, srcImage.Height);
            }
            using (var ms = new MemoryStream())
            {
                var document = new iTextSharp.text.Document(pageSize, 0, 0, 0, 0);
                iTextSharp.text.pdf.PdfWriter.GetInstance(document, ms).SetFullCompression();
                document.Open();
                var image = iTextSharp.text.Image.GetInstance(srcFilename);
                document.Add(image);
                document.Close();

                File.WriteAllBytes(dstFilename, ms.ToArray());
            }
        }
Exemple #33
0
        private void convertJpegToPDFUsingItextSharp()
        {
            iTextSharp.text.Document Doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A2, 10, 10, 10, 10);
            //Store the document on the desktop
            string PDFOutput = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Output.pdf");
            PdfWriter writer = PdfWriter.GetInstance(Doc, new FileStream(PDFOutput, FileMode.Create, FileAccess.Write, FileShare.Read));

            //Open the PDF for writing
            Doc.Open();

            string Folder = "C:\\Images";
            foreach (string F in System.IO.Directory.GetFiles(Folder, "*.tif"))
            {
                //Insert a page
                Doc.NewPage();
                //Add image
                Doc.Add(new iTextSharp.text.Jpeg(new Uri(new FileInfo(F).FullName)));
            }

            //Close the PDF
            Doc.Close();
        }
Exemple #34
0
        protected void createPDF(Stream output)
        {
            //PrimaryAntibody tempAntibody = myConn.getPrimaryAntibodyByID(Convert.ToInt16(Request.QueryString["id"]));
            PrimaryAntibody tempAntibody = myConn.getPrimaryAntibodyByID(int.Parse(txtid.Value));
            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-Disposition", "attachment; filename=primary_antibody_" + tempAntibody.id + ".pdf");
            iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 72, 72, 72, 72);
            PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream);
            document.Open();
            //Page title and spacing
            iTextSharp.text.Chunk pageTitle = new iTextSharp.text.Chunk("Primary Antibody Record", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 20));
            document.Add(pageTitle);
            iTextSharp.text.Paragraph spacing = new iTextSharp.text.Paragraph(" ");
            document.Add(spacing);

            //Name
            iTextSharp.text.Paragraph tempParagraph = new iTextSharp.text.Paragraph();
            iTextSharp.text.Chunk tempLabel = new iTextSharp.text.Chunk("Name: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            iTextSharp.text.Chunk tempValue = new iTextSharp.text.Chunk(tempAntibody.name, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Type
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Type: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempAntibody.type, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Clone
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Clone: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempAntibody.clone, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Host Species
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Host Species: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempAntibody.hostSpecies, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Reactive Species
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Reactive Species: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempAntibody.reactiveSpecies, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Concentration
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Concentration: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempAntibody.concentration, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Working Dilution
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Working Dilution: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempAntibody.workingDilution, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Applications
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Applications: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempAntibody.applications, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Isotype
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Isotype: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempAntibody.isotype, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Antigen
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Antigen: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempAntibody.antigen, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Fluorophore
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Fluorophore: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempAntibody.fluorophore, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            document.Close();
        }
Exemple #35
0
        public static void SaveImages(List<ParsedImage> images, string outputFile)
        {
            var doc = new iTextSharp.text.Document();
            try
            {
                var writer = PdfWriter.GetInstance(doc, new FileStream(outputFile, FileMode.Create));
                writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_5);
                writer.CompressionLevel = PdfStream.BEST_COMPRESSION;
                doc.Open();

                foreach (var parsedImage in images)
                {
                    var image = iTextSharp.text.Image.GetInstance(parsedImage.Image, parsedImage.Format);
                    var width = parsedImage.Width;
                    var height = parsedImage.Height;
                    if ((parsedImage.PerformedRotation == RotateFlipType.Rotate90FlipNone) ||
                        (parsedImage.PerformedRotation == RotateFlipType.Rotate270FlipNone))
                    {
                        var temp = width;
                        width = height;
                        height = temp;
                    }

                    var size = new iTextSharp.text.Rectangle(width, height);
                    image.ScaleAbsolute(width, height);
                    image.CompressionLevel = PdfStream.BEST_COMPRESSION;
                    doc.SetPageSize(size);
                    doc.NewPage();
                    image.SetAbsolutePosition(0, 0);
                    doc.Add(image);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                doc.Close();
            }
        }
        public System.Web.Mvc.FileResult ExportPdf(long DocumentID)
        {
            iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 50, 50, 20, 70);
            MemoryStream output = new MemoryStream();
            PdfWriter writer = PdfWriter.GetInstance(pdfDoc, output);
            long userId = Convert.ToInt64(HttpContext.User.Identity.Name);
            OpenBookSystemMVC.OBISReference.Document doc = null;
            OBSDataSource.GetDocument(DocumentID, out doc);
            AccountInfo ai = null;
            OBSDataSource.GetUserProfile(userId, out ai);
            if (doc == null || ai == null)
            {
                return null;
            }

            string returnContent = doc.SimplifiedContent;
            if (ai.Preferences.DocumentFontSize == 0)
            {
                returnContent = returnContent.ToUpper();
            }

            pdfDoc.Open();

            iTextSharp.text.html.simpleparser.StyleSheet ST = new iTextSharp.text.html.simpleparser.StyleSheet();

            if (ai.Preferences != null)
            {
                iTextSharp.text.FontFactory.Register(Server.MapPath("/Content/fonts/verdana.ttf"), "Verdana");
                iTextSharp.text.FontFactory.Register(Server.MapPath("/Content/fonts/times.ttf"), "Times New Roman");
                iTextSharp.text.FontFactory.Register(Server.MapPath("/Content/fonts/calibri.ttf"), "Calibri");
                iTextSharp.text.FontFactory.Register(Server.MapPath("/Content/fonts/tahoma.ttf"), "Tahoma");

                iTextSharp.text.Font font = iTextSharp.text.FontFactory.GetFont(
                    ai.Preferences.DocumentFontName,
                    ai.Preferences.DocumentFontSize > 0 ? ai.Preferences.DocumentFontSize : 18);

                ST.LoadTagStyle(iTextSharp.text.html.HtmlTags.BODY, iTextSharp.text.html.HtmlTags.FACE, ai.Preferences.DocumentFontName);
            }
            else
            {
                ST.LoadTagStyle(iTextSharp.text.html.HtmlTags.BODY, iTextSharp.text.html.HtmlTags.FACE, "Times New Roman");
            }

            ST.LoadTagStyle(iTextSharp.text.html.HtmlTags.BODY, iTextSharp.text.html.HtmlTags.ENCODING, BaseFont.IDENTITY_H);

            List<iTextSharp.text.IElement> htmlElements = HTMLWorker.ParseToList(new StringReader(returnContent), ST);

            FormatImgElements(htmlElements);

            foreach (var item in htmlElements)
            {

                pdfDoc.Add(item);
            }

            pdfDoc.Close();

            var bytes = output.ToArray();

            return File(bytes, "application/pdf", string.Format("{0}.pdf", doc.Title));
        }
        public static Byte[] GetCreatePdf()
        {
            var doc = new iTextSharp.text.Document();
            var ms = new MemoryStream();
            var writer = PdfWriter.GetInstance(doc, ms);
            var random = new Random();

            doc.Open();

            for (var i = 0; i < 5; i++)
            {
                doc.Add(new iTextSharp.text.Paragraph(GetRandomString(random)));
            }

            doc.Close();

            return ms.ToArray();
        }
        private void AddCartaoSUSCompleto(long numeroCartaoSUS)
        {
            ISeguranca iseguranca = Factory.GetInstance<ISeguranca>();
            if (!iseguranca.VerificarPermissao(((ViverMais.Model.Usuario)Session["Usuario"]).Codigo, "ALTERAR_CARTAO_SUS", Modulo.CARTAO_SUS))
            {
                ClientScript.RegisterClientScriptBlock(typeof(String), "ok", "<script>alert('Você não tem permissão para acessar essa página. Em caso de dúViverMais, entre em contato.');window.location='../Home.aspx';</script>");
                return;
            }

            MemoryStream MStream = new MemoryStream();
            iTextSharp.text.Document doc = new iTextSharp.text.Document(new iTextSharp.text.Rectangle(295, 191));
            PdfWriter writer = PdfWriter.GetInstance(doc, MStream);

            //Monta o pdf
            doc.Open();
            iTextSharp.text.Paragraph p = new iTextSharp.text.Paragraph();
            p.IndentationLeft = -10;
            p.Font.Color = iTextSharp.text.Color.BLACK;
            iTextSharp.text.Phrase nome = new iTextSharp.text.Phrase(HiddenNomePaciente.Value + "\n");
            //paciente.Nome
            nome.Font.Size = 8;
            iTextSharp.text.Phrase nascimento = new iTextSharp.text.Phrase(HiddenDataNascimento.Value + "\t\t" + HiddenMunicipio.Value + "\n");
            nascimento.Font.Size = 8;
            iTextSharp.text.Phrase cartaosus = new iTextSharp.text.Phrase(numeroCartaoSUS + "\n");
            cartaosus.Font.Size = 12;
            PdfContentByte cb = writer.DirectContent;
            Barcode39 code39 = new Barcode39();
            code39.Code = numeroCartaoSUS.ToString();
            code39.StartStopText = true;
            code39.GenerateChecksum = false;
            code39.Extended = true;
            iTextSharp.text.Image imageEAN = code39.CreateImageWithBarcode(cb, null, null);

            iTextSharp.text.Image back = iTextSharp.text.Image.GetInstance(Server.MapPath("img/") + "back_card.JPG");
            back.SetAbsolutePosition(0, doc.PageSize.Height - back.Height);

            iTextSharp.text.Image front = iTextSharp.text.Image.GetInstance(Server.MapPath("img/") + "front_card.JPG");
            front.SetAbsolutePosition(0, doc.PageSize.Height - front.Height);

            iTextSharp.text.Phrase barcode = new iTextSharp.text.Phrase(new iTextSharp.text.Chunk(imageEAN, 36, -45));
            barcode.Font.Color = iTextSharp.text.Color.WHITE;

            p.SetLeading(1, 0.7f);
            p.Add(cartaosus);
            p.Add(nome);
            p.Add(nascimento);
            p.Add(barcode);
            doc.Add(p);

            doc.Add(back);
            doc.NewPage();
            doc.Add(front);

            doc.Close();
            //Fim monta pdf

            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.ClearHeaders();
            HttpContext.Current.Response.ContentType = "application/pdf";
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=CartaoSUS.pdf");
            HttpContext.Current.Response.BinaryWrite(MStream.GetBuffer());
            HttpContext.Current.Response.End();
        }
Exemple #39
0
        protected void createPDF(Stream output)
        {
            //Vector tempVector = myConn.getVectorByID(Convert.ToInt16(Request.QueryString["id"]));
            Vector tempVector = myConn.getVectorByID(2);
            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-Disposition", "attachment; filename=vector_" + tempVector.id + ".pdf");
            iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 72, 72, 72, 72);
            PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream);
            document.Open();
            //Page title and spacing
            iTextSharp.text.Chunk pageTitle = new iTextSharp.text.Chunk("Vector Record", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 20));
            document.Add(pageTitle);
            iTextSharp.text.Paragraph spacing = new iTextSharp.text.Paragraph(" ");
            document.Add(spacing);

            //Name
            iTextSharp.text.Paragraph tempParagraph = new iTextSharp.text.Paragraph();
            iTextSharp.text.Chunk tempLabel = new iTextSharp.text.Chunk("Vector Name: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            iTextSharp.text.Chunk tempValue = new iTextSharp.text.Chunk(tempVector.vectorName, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Multiple Cloning Site
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Multiple Cloning Site: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempVector.multipleCloningSite, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Antibiotic Resistance
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Antibiotic Resistance: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempVector.antibioticResistance, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Vector Size
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Vector Size: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempVector.vectorSize, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Promoter
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Promoter: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempVector.promoter, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Notes
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Notes: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempVector.notes, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            document.Close();
        }
 void SavePDF()
 {
     iTextSharp.text.Document document = new iTextSharp.text.Document();
     using (var stream = new MemoryStream ())
     {
         var writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, stream);
         writer.CloseStream = false;
         document.Open();
         foreach(Pixbuf pix in vimageslist1.Images)
         {
             if(pix.Width > pix.Height)
                 document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
             else
                 document.SetPageSize(iTextSharp.text.PageSize.A4);
             document.NewPage();
             var image = iTextSharp.text.Image.GetInstance(pix.SaveToBuffer ("jpeg"));
             image.SetAbsolutePosition(0,0);
             image.ScaleToFit(document.PageSize.Width, document.PageSize.Height);
             document.Add(image);
         }
         document.Close();
         stream.Position = 0;
         File = stream.ToArray ();
     }
 }
        protected void Exportchart(ArrayList chart)
        {
            string uid = Session["UserID"].ToString();
            MemoryStream msReport = new MemoryStream();

            try
            {
                document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 72, 72, 82, 72);
                iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, msReport);
                document.AddAuthor("Test");
                document.AddSubject("Export to PDF");
                document.Open();

                for (int i = 0; i < chart.Count; i++)
                {
                    iTextSharp.text.Chunk c = new iTextSharp.text.Chunk("Export chart to PDF", iTextSharp.text.FontFactory.GetFont("VERDANA", 15));
                    iTextSharp.text.Paragraph p = new iTextSharp.text.Paragraph();
                    p.Alignment = iTextSharp.text.Element.ALIGN_CENTER;
                    iTextSharp.text.Image hImage = null;
                    hImage = iTextSharp.text.Image.GetInstance(MapPath(chart[i].ToString()));

                    float NewWidth = 500;
                    float MaxHeight = 400;

                    if (hImage.Width <= NewWidth) { NewWidth = hImage.Width; } float NewHeight = hImage.Height * NewWidth / hImage.Width; if (NewHeight > MaxHeight)
                    {
                        NewWidth = hImage.Width * MaxHeight / hImage.Height;
                        NewHeight = MaxHeight;
                    }

                    float ratio = hImage.Width / hImage.Height;
                    hImage.ScaleAbsolute(NewWidth, NewHeight);
                    document.Add(p);
                    document.Add(hImage);
                }
                // close it
                document.Close();
                string filename = "Appraisal Overview for " + Session["Name"].ToString() + ".pdf";
                Response.AddHeader("Content-type", "application/pdf");
                Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
                Response.OutputStream.Write(msReport.GetBuffer(), 0, msReport.GetBuffer().Length);

            }
            catch (System.Threading.ThreadAbortException ex)
            {
                throw new Exception("Error occured: " + ex);
            }
        }
Exemple #42
0
        protected void createPDF(Stream output)
        {
            //Construct tempConstruct = myConn.getConstructByID(Convert.ToInt16(Request.QueryString["id"]));
            Construct tempConstruct = myConn.getConstructByID(2);
            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-Disposition", "attachment; filename=construct_" + tempConstruct.id + ".pdf");
            iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 72, 72, 72, 72);
            PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream);
            document.Open();
            //Page title and spacing
            iTextSharp.text.Chunk pageTitle = new iTextSharp.text.Chunk("Construct Record", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 20));
            document.Add(pageTitle);
            iTextSharp.text.Paragraph spacing = new iTextSharp.text.Paragraph(" ");
            document.Add(spacing);

            //Name
            iTextSharp.text.Paragraph tempParagraph = new iTextSharp.text.Paragraph();
            iTextSharp.text.Chunk tempLabel = new iTextSharp.text.Chunk("Construct Name: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            iTextSharp.text.Chunk tempValue = new iTextSharp.text.Chunk(tempConstruct.name, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Insert
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Insert: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempConstruct.insert, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Vector
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Vector: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempConstruct.vector, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Species
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Species: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempConstruct.species, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Antibiotic Resistance
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Antibiotic Resistance: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempConstruct.antibioticResistance, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //5' Digest Site
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("5' Digest Site: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempConstruct.digestSite5, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //3' Digest Site
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Working Dilution: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempConstruct.digestSite3, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            //Notes
            tempParagraph = new iTextSharp.text.Paragraph();
            tempLabel = new iTextSharp.text.Chunk("Notes: ", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempValue = new iTextSharp.text.Chunk(tempConstruct.notes, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10));
            tempParagraph.Add(tempLabel);
            tempParagraph.Add(tempValue);
            document.Add(tempParagraph);

            document.Close();
        }
Exemple #43
0
        private void createPDF(String tempfilename, String newPath, Random random)
        {
            //MessageBox.Show("PDF");

            string newFileName = tempfilename + ".pdf";
            newPath = System.IO.Path.Combine(newPath, newFileName);
            int sizeofwrite = random.Next(1, 10000);

            if (!System.IO.File.Exists(newPath))
            {

                // step 1: creation of a document-object
                iTextSharp.text.Document myDocument = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4.Rotate());

                try
                {
                    // step 2:
                    // Now create a writer that listens to this doucment and writes the document to desired Stream.
                    iTextSharp.text.pdf.PdfWriter.GetInstance(myDocument, new FileStream(newPath, FileMode.Create));

                    // step 3:  Open the document now using
                    myDocument.Open();

                    for (int x = 0; x < sizeofwrite; x++)
                    {
                        Byte[] b = new Byte[1];
                        random.NextBytes(b);

                        // step 4: Now add some contents to the document
                        myDocument.Add(new iTextSharp.text.Paragraph(b[0].ToString()));
                    }
                }
                catch (iTextSharp.text.DocumentException de)
                {
                    Console.Error.WriteLine(de.Message);
                }
                catch (IOException ioe)
                {
                    Console.Error.WriteLine(ioe.Message);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex.Message);
                }
                finally
                {
                    // step 5: Remember to close the documnet
                    myDocument.Close();
                    textBox4.AppendText("Created file: " + newPath.ToString() + System.Environment.NewLine + "SIZE: " + sizeofwrite.ToString() + "\r\n\r\n");
                }
            }
        }
Exemple #44
0
        public void PrintException(string exceptionmessage)
               {
                    string errorfilepath = data["source_dir"] + @"\ERROR.pdf";

                    FileStream fs = new FileStream(errorfilepath, FileMode.Create, FileAccess.Write, FileShare.None);
                    iTextSharp.text.Document pdf1 = new iTextSharp.text.Document();
                    iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdf1, fs);
                    pdf1.Open();
                    pdf1.Add(new iTextSharp.text.Paragraph(exceptionmessage));
                    pdf1.Close();

                   //string newFile = data["temp_directory"] + "\\" + System.Guid.NewGuid().ToString() + ".pdf";
                   System.Diagnostics.Process process = new System.Diagnostics.Process();
                   System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                   startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;//.Hidden;
                   startInfo.FileName = data["PDF_PRINT"];
                   startInfo.Arguments = " \"-$\" \"" + data["PDF_PRINT_KEY"] + "\" -paper 1 -scale " + data["PAPER_SCALE"] + " -xoffset " + data["PAPER_OFFSET_X"] + " -yoffset " + data["PAPER_OFFSET_Y"] + " -preproc -raster -chgbin " + data["DEFAULT_PRINTER_TRAY"] + " -printer \"" + data["DEFAULT_PRINTER"] + "\" \"" + errorfilepath + "\"";
                   process.StartInfo = startInfo;

                   
                   process.Start();
                   process.WaitForExit();
                   process.Dispose();
                   System.Threading.Thread.Sleep(1000);
                

                   //test
            /*
                   string errorfilepath = @"C:\Users\Administrator.EYEDOC\Documents\Visual Studio 2013\Projects\FIX_HL7_BILLING\FIX_HL7_BILLING\ERROR.pdf";
                   FileStream fs = new FileStream(@"C:\Users\Administrator.EYEDOC\Documents\Visual Studio 2013\Projects\FIX_HL7_BILLING\FIX_HL7_BILLING\ERROR.pdf", FileMode.Create, FileAccess.Write, FileShare.None);
                   iTextSharp.text.Document pdf1 = new iTextSharp.text.Document();
                   iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdf1, fs);
                   pdf1.Open();
                   string timenow = DateTime.Now.ToLongTimeString();
                   pdf1.Add(new iTextSharp.text.Paragraph(timenow));
                   pdf1.Close(); 
             */

                    /*
                   //try ASPOSE////////////////////////////////////////////////////////////////////////////////this works. just need the license key.  
                   PdfViewer viewer = new PdfViewer();
                   viewer.BindPdf(errorfilepath);//Set attributes for printing
                   viewer.AutoResize = true;         //Print the file with adjusted size
                   viewer.AutoRotate = true;         //Print the file with adjusted rotation
                   viewer.PrintPageDialog = false;   //Do not produce the page number dialog when printing

                   //Create objects for printer and page settings and PrintDocument
                   System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();
                   System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();
                   System.Drawing.Printing.PrintDocument prtdoc = new System.Drawing.Printing.PrintDocument();

                   //Set printer name
                   ps.PrinterName = prtdoc.PrinterSettings.PrinterName;
                   //ps.PrinterName = "Canon Front iR3245";
                   //Print document using printer and page settings
                   viewer.PrintDocumentWithSettings(pgs, ps);

                   //Close the PDF file after priting
                   viewer.Close();
                         ////////////////////////////////////////////////////////////////// 
                    */

                   //caution using this method bc we have lots of things using pdfprint already and recall we need extra instances of the program to avoid file corruption.  
            /*
                   // string newFile = data["temp_directory"] + "\\" + System.Guid.NewGuid().ToString() + ".pdf"; //not used
                   System.Diagnostics.Process process = new System.Diagnostics.Process();
                   System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                   startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;//.Hidden;
                   startInfo.FileName = data["PDF_PRINT"];
                   startInfo.Arguments = " \"-$\" \"" + data["PDF_PRINT_KEY"] + "\" -paper 1 -scale " + data["PAPER_SCALE"] + " -xoffset " + data["PAPER_OFFSET_X"] + " -yoffset " + data["PAPER_OFFSET_Y"] + " -preproc -raster -chgbin " + data["DEFAULT_PRINTER_TRAY"] + " -printer \"" + data["DEFAULT_PRINTER"] + "\" \"" + errorfilepath + "\"";
                   process.StartInfo = startInfo;
                   //process.StartInfo.UseShellExecute = false;//hijack print console
                   // process.StartInfo.RedirectStandardOutput = true;//hijack print console
                   // var sb = new StringBuilder();//hijack print console
                   //process.OutputDataReceived += (sender, args) => sb.AppendLine(args.Data);//hijack print console
                   process.Start();
                   // process.BeginOutputReadLine(); //hijack output print
                   process.WaitForExit();
                   process.Dispose();
                   //System.Threading.Thread.Sleep(1000);
                */

                   //end test    


                   
                }
        /// <summary>
        /// a megadott file elérési úttal elkészíti a pdf dokumentumot
        /// </summary>
        /// <param name="financedAmount"></param>
        /// <param name="calcValues"></param>
        /// <param name="pdfFileWithPath"></param>
        /// <returns></returns>
        public void CreateLeasingDocument(string financedAmount, System.Collections.Specialized.StringCollection calcValues, string pdfFileWithPath)
        {
            iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 36, 36, 36, 36); //marginTop : 72

            try
            {
                // writer letrehozas    
                iTextSharp.text.pdf.PdfWriter.GetInstance(document, new System.IO.FileStream(pdfFileWithPath, System.IO.FileMode.Create));

                // lablec
                iTextSharp.text.HeaderFooter footer = new iTextSharp.text.HeaderFooter(new iTextSharp.text.Phrase(), true);
                footer.Border = iTextSharp.text.Rectangle.NO_BORDER;
                footer.Alignment = iTextSharp.text.HeaderFooter.ALIGN_CENTER;
                document.Footer = footer;

                // dokumentum megnyitas
                document.Open();

                iTextSharp.text.Chapter chapter1 = new iTextSharp.text.Chapter(2);
                chapter1.NumberDepth = 0;

                //fejlec kep
                iTextSharp.text.Image imgHeader = GetHeaderImageFile();
                imgHeader.Alignment = iTextSharp.text.Image.ALIGN_LEFT;
                imgHeader.Alt = "NE VEDD MEG, BÉRELD!";

                iTextSharp.text.Table hTable = new iTextSharp.text.Table(1, 1);
                iTextSharp.text.Cell hCell = new iTextSharp.text.Cell(imgHeader);
                hTable.AutoFillEmptyCells = true;
                hTable.TableFitsPage = true;
                hTable.WidthPercentage = 100;
                hTable.AddCell(hCell);
                hTable.Alignment = iTextSharp.text.Table.ALIGN_LEFT;

                chapter1.Add(hTable);

                iTextSharp.text.Color defaultTextColor = new iTextSharp.text.Color(0, 0, 128);

                //uj sor, tavtarto a tabla es a fejleckep kozott
                chapter1.Add(new iTextSharp.text.Paragraph(" "));

                iTextSharp.text.pdf.BaseFont default_ttf = iTextSharp.text.pdf.BaseFont.CreateFont(CompanyGroup.Helpers.ConfigSettingsParser.GetString("FontFile", "c:\\Windows\\Fonts\\calibri.ttf"), iTextSharp.text.pdf.BaseFont.IDENTITY_H, iTextSharp.text.pdf.BaseFont.EMBEDDED);
                iTextSharp.text.Font titlefont = new iTextSharp.text.Font(default_ttf, 16, iTextSharp.text.Font.BOLDITALIC, defaultTextColor);
                iTextSharp.text.Font defaultFont = new iTextSharp.text.Font(default_ttf, 15, iTextSharp.text.Font.NORMAL, defaultTextColor);

                //cimsor
                iTextSharp.text.Paragraph pgTitle = new iTextSharp.text.Paragraph("Finanszírozási ajánlat", titlefont);
                chapter1.Add(pgTitle);

                //tablazat
                iTextSharp.text.Table table1 = new iTextSharp.text.Table(2, 1);
                table1.BorderColor = table1.DefaultCellBorderColor = defaultTextColor;
                table1.Padding = 2;
                table1.Spacing = 1;
                table1.AutoFillEmptyCells = true;
                table1.Alignment = iTextSharp.text.Table.ALIGN_LEFT;
                table1.WidthPercentage = 80.0f;
                table1.Widths = new float[] { 60, 20 };

                iTextSharp.text.Paragraph tmpParagraph = new iTextSharp.text.Paragraph("A konfiguráció nettó vételára:", defaultFont);
                iTextSharp.text.Cell cell1 = new iTextSharp.text.Cell(tmpParagraph);
                cell1.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
                cell1.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                table1.AddCell(cell1);

                tmpParagraph = new iTextSharp.text.Paragraph(financedAmount + " Ft", defaultFont);
                iTextSharp.text.Cell cell2 = new iTextSharp.text.Cell(tmpParagraph);
                cell2.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                cell2.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                table1.AddCell(cell2);

                chapter1.Add(table1);

                //5 oszlopos tabla 
                iTextSharp.text.Table table2 = new iTextSharp.text.Table(5);
                table2.BorderColor = defaultTextColor;
                table2.Padding = 2;
                table2.Spacing = 1;
                table2.AutoFillEmptyCells = true;
                table2.Alignment = iTextSharp.text.Table.ALIGN_LEFT;
                table2.WidthPercentage = 100.0f;
                table2.Widths = new float[] { 20, 20, 20, 20, 20 };

                //első sor
                tmpParagraph = new iTextSharp.text.Paragraph("Önerő", defaultFont);
                cell1 = new iTextSharp.text.Cell(tmpParagraph);
                cell1.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
                cell1.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                cell1.Header = true;
                cell1.Colspan = 4;
                cell1.BorderColor = defaultTextColor;
                table2.AddCell(cell1);

                tmpParagraph = new iTextSharp.text.Paragraph("0 Ft", defaultFont);
                cell2 = new iTextSharp.text.Cell(tmpParagraph);
                cell2.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                cell2.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                cell2.BorderColor = defaultTextColor;
                table2.AddCell(cell2);

                //második sor
                //table2.AddCell("");
                tmpParagraph = new iTextSharp.text.Paragraph("Deviza: HUF", defaultFont);
                iTextSharp.text.Cell tmpCell = new iTextSharp.text.Cell(tmpParagraph);
                tmpCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                tmpCell.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                tmpCell.BorderColor = defaultTextColor;
                tmpCell.Rowspan = 2;
                table2.AddCell(tmpCell);

                tmpParagraph = new iTextSharp.text.Paragraph("Futamidő hónapokban", defaultFont);
                cell1 = new iTextSharp.text.Cell(tmpParagraph);
                cell1.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
                cell1.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                cell1.BorderColor = defaultTextColor;
                cell1.Colspan = 4;
                table2.AddCell(cell1);

                //harmadik sor
                tmpParagraph = new iTextSharp.text.Paragraph("24", defaultFont);
                cell2 = new iTextSharp.text.Cell(tmpParagraph);
                cell2.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                cell2.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                cell2.BorderColor = defaultTextColor;
                table2.AddCell(cell2);

                tmpParagraph = new iTextSharp.text.Paragraph("36", defaultFont);
                iTextSharp.text.Cell cell3 = new iTextSharp.text.Cell(tmpParagraph);
                cell3.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                cell3.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                cell3.BorderColor = defaultTextColor;
                table2.AddCell(cell3);

                tmpParagraph = new iTextSharp.text.Paragraph("48", defaultFont);
                iTextSharp.text.Cell cell4 = new iTextSharp.text.Cell(tmpParagraph);
                cell4.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                cell4.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                cell4.BorderColor = defaultTextColor;
                table2.AddCell(cell4);

                tmpParagraph = new iTextSharp.text.Paragraph("60", defaultFont);
                iTextSharp.text.Cell cell5 = new iTextSharp.text.Cell(tmpParagraph);
                cell5.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                cell5.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                cell5.BorderColor = defaultTextColor;
                table2.AddCell(cell5);

                //negyedik sor
                tmpParagraph = new iTextSharp.text.Paragraph("Tartós bérlet", defaultFont);
                cell1 = new iTextSharp.text.Cell(tmpParagraph);
                cell1.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                cell1.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                cell1.BorderColor = defaultTextColor;
                table2.AddCell(cell1);

                tmpParagraph = new iTextSharp.text.Paragraph(GetItemByPositionFromStringCollection(0, calcValues), defaultFont);
                cell2 = new iTextSharp.text.Cell(tmpParagraph);
                cell2.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                cell2.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                cell2.BorderColor = defaultTextColor;
                table2.AddCell(cell2);

                tmpParagraph = new iTextSharp.text.Paragraph(GetItemByPositionFromStringCollection(1, calcValues), defaultFont);
                cell3 = new iTextSharp.text.Cell(tmpParagraph);
                cell3.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                cell3.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                cell3.BorderColor = defaultTextColor;
                table2.AddCell(cell3);

                tmpParagraph = new iTextSharp.text.Paragraph(GetItemByPositionFromStringCollection(2, calcValues), defaultFont);
                cell4 = new iTextSharp.text.Cell(tmpParagraph);
                cell4.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                cell4.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                cell4.BorderColor = defaultTextColor;
                table2.AddCell(cell4);

                tmpParagraph = new iTextSharp.text.Paragraph(GetItemByPositionFromStringCollection(3, calcValues), defaultFont);
                cell5 = new iTextSharp.text.Cell(tmpParagraph);
                cell5.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                cell5.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                cell5.BorderColor = defaultTextColor;
                table2.AddCell(cell5);

                //ötödik sor
                table2.AddCell("");
                tmpParagraph = new iTextSharp.text.Paragraph("Nettó havidíjak", defaultFont);
                cell1 = new iTextSharp.text.Cell(tmpParagraph);
                cell1.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
                cell1.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                cell1.BorderColor = defaultTextColor;
                cell1.Colspan = 4;
                table2.AddCell(cell1);

                //hatodik sor
                //tmpParagraph = new iTextSharp.text.Paragraph( "A kalkulált díjak biztosítási díjat is tartalmaznak.", defaultFont );
                //cell1 = new iTextSharp.text.Cell( tmpParagraph );
                //cell1.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
                //cell1.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                //cell1.BorderColor = defaultTextColor;
                //cell1.Colspan = 5;
                //table2.AddCell(cell1);

                chapter1.Add(table2);

                chapter1.Add(new iTextSharp.text.Paragraph(" "));

                //szoveg
                iTextSharp.text.Font smallFont = new iTextSharp.text.Font(default_ttf, 9, iTextSharp.text.Font.ITALIC, defaultTextColor);
                iTextSharp.text.Paragraph sText = new iTextSharp.text.Paragraph("HUF alapú finanszírozás, a havi díj az 1 havi Buborhoz kötött", smallFont);
                chapter1.Add(sText);

                //uj sor
                chapter1.Add(new iTextSharp.text.Paragraph(" "));

                //szoveg
                iTextSharp.text.Font bold_10_Font = new iTextSharp.text.Font(default_ttf, 10, iTextSharp.text.Font.BOLD, defaultTextColor);
                sText = new iTextSharp.text.Paragraph("Ajánlatunkat ajánlati kötöttség nélkül tettük meg!", bold_10_Font);
                chapter1.Add(sText);

                //szoveg
                sText = new iTextSharp.text.Paragraph("Az ügylet megkötéséhez a refinanszírozó jóváhagyása szükséges.", bold_10_Font);
                chapter1.Add(sText);

                //uj sor
                chapter1.Add(new iTextSharp.text.Paragraph(" "));

                ////szoveg
                //var bold_12_Font = new iTextSharp.text.Font( default_ttf, 12, iTextSharp.text.Font.BOLD, defaultTextColor );
                //sText = new iTextSharp.text.Paragraph( "Szerződéskötési díj:          0 Ft", bold_12_Font );
                //chapter1.Add(sText);

                ////uj sor
                //chapter1.Add(new iTextSharp.text.Paragraph(" "));

                //szoveg
                sText = new iTextSharp.text.Paragraph("A tartós bérlet alapvető jellemzői", bold_10_Font);
                chapter1.Add(sText);

                //szoveg
                iTextSharp.text.Font normal_10_Font = new iTextSharp.text.Font(default_ttf, 10, iTextSharp.text.Font.NORMAL, defaultTextColor);

                sText = new iTextSharp.text.Paragraph("A bérleti díjakat ÁFA terheli, mely visszaigényelhető", normal_10_Font);
                sText.IndentationLeft = 50;
                chapter1.Add(sText);

                //szoveg
                sText = new iTextSharp.text.Paragraph("Az eszköz a bérbeadó könyveiben kerül aktiválásra", normal_10_Font);
                sText.IndentationLeft = 50;
                chapter1.Add(sText);

                //szoveg
                sText = new iTextSharp.text.Paragraph("A havi díj költségként elszámolható, csökkentve ezáltal az adóalapot", normal_10_Font);
                sText.IndentationLeft = 50;
                chapter1.Add(sText);

                //uj sor
                chapter1.Add(new iTextSharp.text.Paragraph(" "));

                //szoveg
                sText = new iTextSharp.text.Paragraph("Ha bármilyen kérdése merülne fel a konstrukciót illetően, forduljon hozzánk bizalommal!", bold_10_Font);
                chapter1.Add(sText);

                //uj sor
                chapter1.Add(new iTextSharp.text.Paragraph(" "));

                //szoveg
                sText = new iTextSharp.text.Paragraph("Kublik Ádám", bold_10_Font);
                chapter1.Add(sText);

                //szoveg
                sText = new iTextSharp.text.Paragraph("értékesítési vezető", normal_10_Font);
                chapter1.Add(sText);

                //szoveg
                sText = new iTextSharp.text.Paragraph("HRP Finance", bold_10_Font);
                chapter1.Add(sText);

                //szoveg
                sText = new iTextSharp.text.Paragraph("Tel.: +36 1 452 46 16", normal_10_Font);
                chapter1.Add(sText);

                //szoveg
                sText = new iTextSharp.text.Paragraph("mob.: +36 70 452 46 16", normal_10_Font);
                chapter1.Add(sText);

                //szoveg
                sText = new iTextSharp.text.Paragraph("mail: [email protected]", normal_10_Font);
                chapter1.Add(sText);

                document.Add(chapter1);
            }
            catch (iTextSharp.text.DocumentException documentException)
            {
                throw documentException;
            }
            catch (System.IO.IOException ioeException)
            {
                throw ioeException;
            }
            finally
            {
                // dokumentum bezarasa  
                document.Close();
            }
        }
Exemple #46
0
 protected void OnButtonPDFClicked(object sender, EventArgs e)
 {
     FileChooserDialog fc=
         new FileChooserDialog("Укажите файл для сохранения документа",
                               this,
                               FileChooserAction.Save,
                               "Отмена",ResponseType.Cancel,
                               "Сохранить",ResponseType.Accept);
     fc.CurrentName = DocInfo.TypeName + " " + entryNumber.Text + ".pdf";
     fc.Show();
     if(fc.Run() == (int) ResponseType.Accept)
     {
         fc.Hide();
         iTextSharp.text.Document document = new iTextSharp.text.Document();
         using (var stream = new FileStream(fc.Filename, FileMode.Create, FileAccess.Write, FileShare.None))
         {
             iTextSharp.text.pdf.PdfWriter.GetInstance(document, stream);
             document.Open();
             foreach(DocumentImage img in Images)
             {
                 if(img.Image.Width > img.Image.Height)
                     document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
                 else
                     document.SetPageSize(iTextSharp.text.PageSize.A4);
                 document.NewPage();
                 var image = iTextSharp.text.Image.GetInstance(img.file);
                 image.SetAbsolutePosition(0,0);
                 image.ScaleToFit(document.PageSize.Width, document.PageSize.Height);
                 document.Add(image);
             }
             document.Close();
         }
     }
     fc.Destroy();
 }
Exemple #47
0
        // Background worker
        public void PDFBackgroundWorker_DoWork_TextPDF(object sender, DoWorkEventArgs e)
        {
            int i = 0;
            int ii = 1;
            exportFilePath = string.Empty;

                if (JobType == PDFJobType.TextPDF)
                {
                    exportFilePath = directoryName + "\\" + FileNoExt + ".pdf";

                    while (System.IO.File.Exists(exportFilePath))
                    {
                        exportFilePath = directoryName + "\\" + FileNoExt + "_" + ii + ".pdf";
                        ii++;
                    }

                    using (FileStream fs = new FileStream(exportFilePath, FileMode.Create, FileAccess.Write, FileShare.None))
                    {
                        iTextSharp.text.Document doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.B4);

                        // iTextSharp.text. Document doc = new Document(PageSize.A2);
                        // doc.SetMargins(100, 200, 0, 0);
                        //Document doc = new Document(PageSize.A5, 36, 72, 108, 180);
                        //Document doc = new Document(PageSize.A3.Rotate(),400,0,0,0);
                        //var doc = new Document(new iTextSharp.text.Rectangle(100f, 300f));
                        iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, fs);
                        iTextSharp.text.pdf.BaseFont bfTimes = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.TIMES_BOLD, iTextSharp.text.pdf.BaseFont.CP1252, false);
                        // doc.SetPageSize(PageSize.A1);
                        // doc.SetMargins(76, 0, 0, 0);
                        doc.SetMarginMirroring(false);
                        iTextSharp.text.Font times = new iTextSharp.text.Font(bfTimes, 14, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.CYAN);

                        if (PDFBackgroundWorker.CancellationPending)
                        {
                            e.Cancel = true;
                            PDFBackgroundWorker.ReportProgress(i);
                            return;
                        }

                        using (StreamReader read = new StreamReader(InputFilename))
                        {

                            string text = read.ReadToEnd();
                            // AddDocMetaData();
                            doc.AddTitle(GameTitle);
                            doc.AddSubject("");
                            doc.AddKeywords(GameTitle + ",  " + FileNoExt + " : by Hypermint,  ");
                            doc.AddCreator("HLM-Chk");
                            doc.AddAuthor(GameTitle);
                            doc.AddHeader(FileNoExt, GameTitle);
                            doc.Open();
                            iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph();
                            paragraph.Alignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                            paragraph.Add(text);
                            doc.Add(paragraph);

                            //Paragraph paragraph = new Paragraph(text);
                            doc.Close();
                        }

                    }
                }
        }