예제 #1
0
 public byte[] TiffToPDF(Stream file)
 {
     _logger.LogDebug($"Start convert tiff file");
     byte[] buff;
     try
     {
         using (MemoryStream memoryStream = new MemoryStream())
             using (PdfDocument document = new PdfDocument())
             {
                 document.PageSettings.Margins.All = 0;
                 PdfTiffImage tiffImage  = new PdfTiffImage(file);
                 int          frameCount = tiffImage.FrameCount;
                 for (int i = 0; i < frameCount; i++)
                 {
                     PdfPage     page     = document.Pages.Add();
                     PdfGraphics graphics = page.Graphics;
                     tiffImage.ActiveFrame = i;
                     graphics.DrawImage(tiffImage, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height);
                 }
                 document.Save(memoryStream);
                 memoryStream.Position = 0;
                 buff = memoryStream.ToArray();
                 _logger.LogDebug("FileInfoPDFService.TiffToPDF....OK");
                 return(buff);
             }
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
     }
     return(null);
 }
예제 #2
0
        public IActionResult ConvertToPDF(IList <IFormFile> files)
        {
            //Creating the new PDF document
            PdfDocument document = new PdfDocument();

            foreach (var formFile in files)
            {
                if (formFile.Length > 0)
                {
                    MemoryStream file = new MemoryStream();
                    formFile.CopyTo(file);
                    if (formFile.ContentType == "image/tiff")
                    {
                        //Get the image from stream and draw frame by frame
                        PdfTiffImage tiffImage = new PdfTiffImage(file);

                        int frameCount = tiffImage.FrameCount;
                        for (int i = 0; i < frameCount; i++)
                        {
                            //Add pages to the document
                            var page = document.Pages.Add();
                            //Getting page size to fit the image within the page
                            SizeF pageSize = page.GetClientSize();
                            //Selecting frame in TIFF
                            tiffImage.ActiveFrame = i;
                            //Draw TIFF frame
                            page.Graphics.DrawImage(tiffImage, 0, 0, pageSize.Width, pageSize.Height);
                        }
                    }
                    else
                    {
                        //Loading the image
                        PdfImage image = PdfImage.FromStream(file);
                        //Adding new page
                        PdfPage page = page = document.Pages.Add();
                        //Drawing image to the PDF page
                        page.Graphics.DrawImage(image, new PointF(0, 0));
                    }
                    file.Dispose();
                }
            }
            //Saving the PDF to the MemoryStream
            MemoryStream stream = new MemoryStream();

            document.Save(stream);

            //Set the position as '0'.
            stream.Position = 0;

            //Download the PDF document in the browser
            FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");

            fileStreamResult.FileDownloadName = "ImageToPDF.pdf";

            return(fileStreamResult);
        }
예제 #3
0
        private static void DrawCmykTiff(PdfPage page, Stream cmykImageStream, PdfFont titleFont)
        {
            PdfBrush brush = new PdfBrush();

            page.Graphics.DrawString("CMYK TIFF", titleFont, brush, 20, 50);

            PdfTiffImage cmykTiff = new PdfTiffImage(cmykImageStream);

            page.Graphics.DrawImage(cmykTiff, 20, 90, 570, 0);

            page.Graphics.CompressAndClose();
        }
예제 #4
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            PdfFixedDocument document = new PdfFixedDocument();
            PdfTiffImage     tiff     = new PdfTiffImage(input);

            for (int i = 0; i < tiff.FrameCount; i++)
            {
                tiff.ActiveFrame = i;
                PdfPage page = document.Pages.Add();
                page.Graphics.DrawImage(tiff, 0, 0, page.Width, page.Height);
            }

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.tifftopdf.pdf") };
            return(output);
        }
예제 #5
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            PdfFixedDocument document = new PdfFixedDocument();
            PdfTiffImage tiff = new PdfTiffImage(input);

            for (int i = 0; i < tiff.FrameCount; i++)
            {
                tiff.ActiveFrame = i;
                PdfPage page = document.Pages.Add();
                page.Graphics.DrawImage(tiff, 0, 0, page.Width, page.Height);
            }

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.tifftopdf.pdf") };
            return output;
        }
        public ActionResult MultiColumnHTML(string InsideBrowser)
        {
            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;

            dataPath = basePath + @"/PDF/";

            //Create a PDF document
            PdfDocument doc = new PdfDocument();

            doc.PageSettings.Size = new SizeF(870, 732);

            //Add a page
            PdfPage page = doc.Pages.Add();


            PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
            PdfPen        pen   = new PdfPen(Color.Black, 1f);

            //Create font
            PdfStandardFont font       = new PdfStandardFont(PdfFontFamily.Helvetica, 11.5f);
            FileStream      fontstream = new FileStream(dataPath + "Calibri.ttf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            PdfTrueTypeFont heading    = new PdfTrueTypeFont(fontstream, 14f, PdfFontStyle.Bold);

            font = new PdfStandardFont(PdfFontFamily.Helvetica, 8.5f);

            //Adding Header
            this.AddMulticolumnHeader(doc, "Syncfusion Essential PDF", "MultiColumnText Demo");

            //Adding Footer
            this.AddFooter(doc, "@Copyright 2015");

            #region htmlText

            string longtext = "<font color='#FF0000F'><b>PDF</b></font> stands for <i>\"Portable Document Format\"</i>." +
                              " The key word is <i>portable</i>, intended to combine the qualities of <u>authenticity," +
                              " reliability and ease of use together into a single packaged concept</u>.<br/><br/>" +
                              "Adobe Systems invented PDF technology in the early 1990s to smooth the " +
                              "process of moving text and graphics from publishers to printing-presses." +
                              " <font color='#FF0000F'><b>PDF</b></font> turned out to be the very essence of paper, brought to life in a computer." +
                              " In creating PDF, Adobe had almost unwittingly invented nothing less than a " +
                              "bridge between the paper and computer worlds. <br/><br/>To be truly portable, an authentic electronic " +
                              "document would have to appear exactly the same way on any computer at any time," +
                              " at no cost to the user. It will deliver the exact same results in print or on-screen " +
                              "with near-total reliability. ";
            #endregion


            //Rendering HtmlText
            PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(longtext, font, brush);

            // Formatting Layout
            PdfLayoutFormat format = new PdfLayoutFormat();
            format.Layout = PdfLayoutType.OnePage;

            //Drawing htmlString
            richTextElement.Draw(page, new RectangleF(0, 15, 190, page.GetClientSize().Height), format);

            FileStream imageStream = new FileStream(dataPath + "PDFImage.png", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            ////Drawing Image
            PdfBitmap image = new PdfBitmap(imageStream);
            page.Graphics.DrawImage(image, new PointF(50, 295));

            #region HtmlText
            longtext = "<font color='#FF0000F'><b>PDF</b></font> is used for representing two-dimensional documents in " +
                       "a manner independent of the application software, hardware, and operating system.<sup>[1]</sup>" +
                       "<br/><br/>Each PDF file encapsulates a complete description of a fixed-layout 2-D document " +
                       "(and, with Acrobat 3-D, embedded 3-D documents) that includes the text, fonts, images, " +
                       "and 2-D vector graphics which comprise the documents." +
                       " <br/><br/><b>PDF</b> is an open standard that was officially published on July 1, 2008 by the ISO as" +
                       "ISO 32000-1:2008.<sub>[2]</sub><br/><br/>" +
                       "The PDF combines the technologies such as A sub-set of the PostScript page description programming " +
                       "language, a font-embedding/replacement system to allow fonts to travel with the documents and a " +
                       "structured storage system to bundle these elements and any associated content into a single file," +
                       "with data compression where appropriate.";
            #endregion

            richTextElement = new PdfHTMLTextElement(longtext, font, brush);

            richTextElement.Draw(page, new RectangleF(0, 375, 190, page.GetClientSize().Height), format);

            #region HtmlText
            ////HtmlString
            string longText = "<font color='#0000F8'>Essential PDF</font> is a <u><i>.NET</i></u> " +
                              "library with the capability to produce Adobe PDF files " +
                              "It features a full-fledged object model for the easy creation of PDF files from any .NET language. " +
                              " It does not use any external libraries and is built from scratch in C#. ";
            #endregion


            ////Rendering HtmlText
            richTextElement = new PdfHTMLTextElement(longText, font, brush);


            //Drawing htmlString
            richTextElement.Draw(page, new RectangleF(195, 15, 225, page.GetClientSize().Height), format);
            FileStream gifStream = new FileStream(dataPath + "Essen PDF.gif", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            ////Drawing Image
            PdfImage image1 = new PdfTiffImage(gifStream);
            page.Graphics.DrawImage(image1, new PointF(225, 100));

            #region HtmlText
            string htmlText = "Essential PDF supports many features for creating a PDF document including <b>" +
                              "drawing text, images, tables and other shapes</b>. " +
                              "<br/><br/><font face='TimesRoman'>The generated PDF document can also be protected using <I>" +
                              "40 Bit and 128 Bit encryption.</I></font><br/>" +
                              "<p>Essential PDF is compatible with Microsoft Visual Studio .NET 2005 and 2008. " +
                              "It is also compatible with the Express editions of Visual Studio.NET. <br/><br/>" +
                              "The Essential PDF library can be used in any .NET environment including C#, VB.NET and managed C++.</p>" +
                              "The PDF file that is created using Essential PDF can be viewed using Adobe Acrobat or the free " +
                              "version of <u> Acrobat Viewer from Adobe only.</u>" +
                              "<font color='#0000F8'><b><br/><br/>Essential PDF</b></font> It can be used on the server " +
                              "side (ASP.NET or any other environment) or with Windows Forms applications. " +
                              "The library is 100% managed, being written in C#.<br/><br/> " +
                              "<font color='#FF0000F'>PdfDocument</font> is a top-level object in Essential PDF which implies a " +
                              "representation of a PDF document. <br/><br/> " +
                              "The document contains a collection of sections that are represented by the <font color='#FF0000F'>PdfSection</font> class, " +
                              "which is a logical entity containing a collection of pages and their settings. <br/><br/> Pages (which are represented by <font color='#FF0000F'>PdfPage</font> class) " +
                              "are the main destinations of the graphics output.<br/><br/>" +
                              "A document can be saved through its <font color='#0000F8'>Save()</font> method. It can be saved either to a file or stream.<br/><br/>" +
                              "In order to use the Essential PDF library in your project, add the PdfConfig component found in the toolbox to a project to enable support for PDF. ";

            #endregion

            //Rendering HtmlText
            PdfHTMLTextElement richTextElement1 = new PdfHTMLTextElement(htmlText, font, brush);


            //Drawing htmlString
            richTextElement1.Draw(page, new RectangleF(195, 200, 225, page.GetClientSize().Height), format);


            #region HtmlText
            htmlText = "<p>Every Syncfusion license includes a <i>one-year subscription</i> for unlimited technical support and new releases." +
                       "Syncfusion licenses each product on a simple per-developer basis and charges no royalties," +
                       "runtimes, or server deployment fees. A licensee can install his/her " +
                       "license on multiple personal machines at <u>no extra charge.</u></p>"
                       + "<p> At Syncfusion we are very excited about the Microsoft .NET platform.<br/><br/> " +
                       "We believe that one of the key benefits of <font color='#0000F8'>.NET</font> is improved programmer productivity. " +
                       "Solutions that used to take a very long time with traditional tools can now be " +
                       "implemented in a much shorter time period with the <font color='#0000F8'>.NET</font> platform.</p>" +
                       "Essential Studio includes seven component libraries in one great package." +
                       "Essential Studio is available with full source code. It incorporates a " +
                       "unique debugging support system that allows switching between 'Debug' and " +
                       "\'Release\' versions of our library with a single click from inside the Visual" +
                       "Studio.NET IDE. <br/><br/> <p> To ensure the highest quality of support possible," +
                       "we use a state of the art <font color='#0000F8'>Customer Relationship Management software (CRM)</font> " +
                       "based Developer Support System called Direct-Trac. Syncfusion Direc-Trac is a " +
                       "support system that is uniquely tailored for developer needs. Support incidents " +
                       "can be created and tracked to completion 24 hours a day, 7 days a week.</p><br/><br/> " +
                       "We have a simple, royalty-free licensing model. Components are licensed to a single user." +
                       " We recognize that you often work at home or on your laptop in addition to your work machine." +
                       "Therefore, our license permits our products to be installed in more than one location." +
                       " At Syncfusion, we stand behind our products 100%. <br/><br/>We have top notch management" +
                       ", architects, product managers, sales people, support personnel, and developers " +
                       "all working with you, the customer, as their focal point.";
            #endregion


            richTextElement = new PdfHTMLTextElement(htmlText, font, brush);

            //Drawing htmlString
            richTextElement.Draw(page, new RectangleF(425, 15, 225, page.GetClientSize().Height), format);

            #region HtmlText
            htmlText = "Each licensed control would need to have an entry in the licx file. This would mean that if you were using 20 licensed controls, you would have 20 different entries complete with a full version number in your licx file." +
                       "<br/><br/> This posed major problems when upgrading to a newer version since these entries would need to have their version numbers changed. This also made trouble shooting licensing issues very difficult. ";
            #endregion


            richTextElement = new PdfHTMLTextElement(htmlText, font, brush);

            //Drawing htmlString
            richTextElement.Draw(page, new RectangleF(425, 500, 225, page.GetClientSize().Height), format);
            MemoryStream stream = new MemoryStream();

            //Save the PDF document
            doc.Save(stream);

            stream.Position = 0;

            //Close the PDF document
            doc.Close(true);

            //Download the PDF document in the browser.
            FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");
            fileStreamResult.FileDownloadName = "MultiColumnHtmlText.pdf";
            return(fileStreamResult);
        }
예제 #7
0
        public IActionResult TiffToPDF(string submit1, string submit, string InsideBrowser)
        {
            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = string.Empty;

            dataPath = basePath + @"/PDF/";

            //Load TIFF image to stream
            FileStream imageFileStream = new FileStream(dataPath + "image.tiff", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            if (submit1 == "View TIFF image")
            {
                return(File(imageFileStream, "application/image", "image.tiff"));
            }
            else
            {
                //Create a new PDF document
                PdfDocument document = new PdfDocument();

                //Add a section to the PDF document
                PdfSection section = document.Sections.Add();

                //Declare the PDF page
                PdfPage page;

                //Declare PDF page graphics
                PdfGraphics graphics;

                //Load Multi-frame Tiff image
                PdfTiffImage tiffImage = new PdfTiffImage(imageFileStream);

                //Get the frame count
                int frameCount = tiffImage.FrameCount;

                //Access each frame draw into the page
                for (int i = 0; i < frameCount; i++)
                {
                    page = section.Pages.Add();

                    section.PageSettings.Margins.All = 0;

                    graphics = page.Graphics;

                    tiffImage.ActiveFrame = i;

                    graphics.DrawImage(tiffImage, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height);
                }

                MemoryStream stream = new MemoryStream();

                document.Save(stream);

                document.Close();

                stream.Position = 0;

                //Download the PDF document in the browser.
                FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");
                fileStreamResult.FileDownloadName = "TiffToPDF.pdf";
                return(fileStreamResult);
            }
        }
        public ActionResult TiffToPDF(string viewTemplate, string createPDF)
        {
            string dataPath = _hostingEnvironment.WebRootPath + @"/PDF/";

            //Load TIFF image to stream
            FileStream imageFileStream = new FileStream(dataPath + "image.tiff", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            if (viewTemplate == "View Template")
            {
                return(File(imageFileStream, "application/image", "image.tiff"));
            }
            else if (createPDF == "Generate PDF")
            {
                //Create a new PDF document
                PdfDocument document = new PdfDocument();

                //Set margin to the page
                document.PageSettings.Margins.All = 0;

                //Load Multiframe Tiff image
                PdfTiffImage tiffImage = new PdfTiffImage(imageFileStream);

                //Get the frame count
                int frameCount = tiffImage.FrameCount;

                //Access each frame and draw into the page
                for (int i = 0; i < frameCount; i++)
                {
                    //Add new page for each frames
                    PdfPage page = document.Pages.Add();

                    //Get page graphics
                    PdfGraphics graphics = page.Graphics;

                    //Set active frame.
                    tiffImage.ActiveFrame = i;

                    //Draw Tiff image into page
                    graphics.DrawImage(tiffImage, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height);
                }

                //Save PDF document
                MemoryStream stream = new MemoryStream();

                document.Save(stream);

                //Close the PDF document
                document.Close(true);

                stream.Position = 0;

                //Download the PDF document in the browser.
                FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");
                fileStreamResult.FileDownloadName = "TiffToPDF.pdf";
                return(fileStreamResult);
            }
            else
            {
                return(View());
            }
        }