PDF File Processing component comparison (ASPOSE.PDF,SPIRE.PDF,ITEXT7)

Source: Internet
Author: User


 public interface IPdfComponentFunc
    {
        string ComponentName { get; }
        void ToJpeg(string absoluteFilePath, string outputPath);
        void ToTxt(string absoluteFilePath, string outputPath);
        void FromXps(string absoluteFilePath, string outputPath);
        void InsertPage(string absoluteFilePath, string outputPath);
        void AddWaterprint(string absoluteFilePath, string outputPath);
    } 






Function believe that the name will know, then the next is three different components of the code implementation.



Aspose.pdf (because the trial version can only turn 4 pages, Rage made a cracked version)


public class AsposePdfComponent: IPdfComponentFunc
    {
        public string ComponentName => "Aspose.Pdf";

        private const string Key = "PExpY2Vuc2U + DQogIDxEYXRhPg0KICAgIDxMaWNlbnNlZFRvPlNoYW5naGFpIEh1ZHVuIEluZm9ybWF0aW9uIFRlY2hub2xvZ3kgQ28uLCBMdGQ8L0xpY2Vuc2VkVG8 + DQogICAgPEVtYWlsVG8 + MzE3NzAxODA5QHFxLmNvbTwvRW1haWxUbz4NCiAgICA8TGljZW5zZVR5cGU + RGV2ZWxvcGVyIE9FTTwvTGljZW5zZVR5cGU + DQogICAgPExpY2Vuc2VOb3RlPkxpbWl0ZWQgdG8gMSBkZXZlbG9wZXIsIHVubGltaXRlZCBwaHlzaWNhbCBsb2NhdGlvbnM8L0xpY2Vuc2VOb3RlPg0KICAgIDxPcmRlcklEPjE2MDkwMjAwNDQwMDwvT3JkZXJJRD4NCiAgICA8VXNlcklEPjI2NjE2NjwvVXNlcklEPg0KICAgIDxPRU0 + VGhpcyBpcyBhIHJlZGlzdHJpYnV0YWJsZSBsaWNlbnNlPC9PRU0 + DQogICAgPFByb2R1Y3RzPg0KICAgICAgPFByb2R1Y3Q + QXNwb3NlLlRvdGFsIGZvciAuTkVUPC9Qcm9kdWN0Pg0KICAgIDwvUHJvZHVjdHM + DQogICAgPEVkaXRpb25UeXBlPkVudGVycHJpc2U8L0VkaXRpb25UeXBlPg0KICAgIDxTZXJpYWxOdW1iZXI + NzM4MDNhYmUtYzZkMi00MTY3LTg2MTgtN2I0NDViNDRmOGY0PC9TZXJpYWxOdW1iZXI + DQogICAgPFN1YnNjcmlwdGlvbkV4cGlyeT4yMDE3MDkwNzwvU3Vic2NyaXB0aW9uRXhwaXJ5Pg0KICAgIDxMaWNlbnNlVmVyc2lvbj4zLjA8L0xpY2Vuc2VWZXJzaW9uPg0KICAgIDxMaWNlbnNlSW5zdHJ1Y3Rpb25zPmh0dHA6Ly93d3cuYXNwb3NlLmNvbS9jb3Jw b3JhdGUvcHVyY2hhc2UvbGljZW5zZS1pbnN0cnVjdGlvbnMuYXNweDwvTGljZW5zZUluc3RydWN0aW9ucz4NCiAgPC9EYXRhPg0KICA8U2lnbmF0dXJlPm5LNVVUR3dZMWVJSEtIV0d2NW5sQUxXUy81bDEzWkFuamlvdnlBcGNqQis0ZjNGbm5yOWhjeUlzazlvVzQySWp0ZFYra2JHZlNSMUV4OUozSGlkaThCeE43aHFiR1BERXNaWGo2RlYxaGl1N2MxWmUyNEp3VGc2UnpsNUNJRHY1YVhxbDQyczBkSGw4eXpreDRBM2RTTU5KTzRiQ094a2V2OFBiOWxSaUc3ST08L1NpZ25hdHVyZT4NCjwvTGljZW5zZT4 = ";
        private static Stream LStream = (Stream) new MemoryStream (Convert.FromBase64String (Key));
        public AsposePdfComponent ()
        {
            SetPdfLicense ();
        }

        public void SetPdfLicense ()
        {
            var l = new Aspose.Pdf.License ();
            //l.SetLicense(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.lic"));
            l.SetLicense (LStream);
        }


        public void AddWaterprint (string absoluteFilePath, string outputPath)
        {
            var watermarkImgPath = Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "DefaultResource", "waterMarkImg.jpeg");
            using (var pdfDocument = new Document (absoluteFilePath))
            using (BackgroundArtifact background = new BackgroundArtifact ())
            {
                foreach (Page aPdfPage in pdfDocument.Pages)
                {
                    ImageStamp imageStamp = new ImageStamp (watermarkImgPath);
                    imageStamp.XIndent = 300;
                    imageStamp.YIndent = aPdfPage.PageInfo.Height-200;
                    imageStamp.Height = 81;
                    imageStamp.Width = 80;
                    aPdfPage.AddStamp (imageStamp);
                }


                pdfDocument.Save (outputPath);
            }
        }

        public void FromXps (string absoluteFilePath, string outputPath)
        {
            // Instantiate LoadOption object using XPS load option
            Aspose.Pdf.LoadOptions options = new XpsLoadOptions ();

            // Create document object
            Aspose.Pdf.Document document = new Aspose.Pdf.Document (absoluteFilePath, options);

            // Save the resulting PDF document
            document.Save (outputPath);
        }

        public void InsertPage (string absoluteFilePath, string outputPath)
        {
            var insertPageImgPath = Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "DefaultResource", "insertPage.jpeg");
            using (var pdfDocument = new Document (absoluteFilePath))
            using (BackgroundArtifact background = new BackgroundArtifact ())
            {
                // Add a new page to document object
                Page page = pdfDocument.Pages.Insert (2);
                page.AddImage (insertPageImgPath, page.Rect);

                pdfDocument.Save (outputPath);
            }
        }

        public void ToJpeg (string absoluteFilePath, string outputPath)
        {
            using (var pdfDocument = new Document (absoluteFilePath))
            {
                for (var i = 1; i <pdfDocument.Pages.Count + 1; i ++)
                {

                    using (FileStream imageStream = new FileStream (Path.Combine (outputPath, i.ToString () + ".jpeg"), FileMode.Create))
                    {
                        // Quality [0-100], 100 is Maximum
                        // create Resolution object
                        Resolution resolution = new Resolution (300);
                        JpegDevice jpegDevice = new JpegDevice (resolution, 100);

                        // convert a particular page and save the image to stream
                        jpegDevice.Process (pdfDocument.Pages [i], imageStream);

                        // close stream
                        imageStream.Close ();
                    }
                }
            }
        }

        public void ToTxt (string absoluteFilePath, string outputPath)
        {
            var txtAbsorber = new TextAbsorber ();
            using(var pdfDocument = new Document (absoluteFilePath))
             {
                 pdfDocument.Pages.Accept (txtAbsorber);
                 File.WriteAllText (outputPath, txtAbsorber.Text);
             }
         }
     }





Do not want the code too long, so the other two components of the code implementation is not affixed.



Every time you implement an interface, the program automatically adds it to the drop-down list of components (Usecomponent), as shown in.















Considering the current open source ecological internationalization, so all written in English, I am more lazy, there is not much language.



Demo How to use it on GitHub, it's just a post-run interface diagram.



Usage component: Aspose, number of executions: 10, Time: 27473 ms











End language





Simply say my side of a pre-study results, I tested a bunch of previously problematic PDFs, and finally found:



Aspose.pdf:1, there are some bug issues with the ability to go from XPS to PDF, and some XPS documents throw exceptions directly. 2, to the function of PDF to image is dependent on the System font library, if the missing PDF file font, the turn out is garbled. Having contacted their technical team to see if they can improve both of these issues, I will use it and I am currently impressed with the best in my side.



Spire.pdf:1,pdf to the image faster than aspose, but unfortunately, with the image of the PDF to the image directly thrown out of the exception. 2, the format of the TXT is much worse than the aspose, but there is nothing wrong with the content.



Itext7:1, like Spire, with a picture of the PDF processing directly thrown exception, and Itext no XPS to PDF and to the JPEG function (I searched the document did not find)






It is worth mentioning that the fastest is ITEXT7, although its function is not complete, followed by spire, but Aspose turned out of the things rarely will be problematic, txt format basically restore the original format of the PDF, the reverse view spire and itext This is very bad, all densely lined up.






This is only achieved I think the better of the three components to compare, if there are other better components of classmates to recommend, I can add to the component, you can also go straight to GitHub to fork the code and then expand their own components for research.



Recently put their website into. NET core2.0, really feel the good intentions of Microsoft, Microsoft is so open source, as from C #, but now in the people with Web group only hope that the C # System of open source ecology will be better, or I will go to nodejs (laughter).



PDF File Processing component comparison (ASPOSE.PDF,SPIRE.PDF,ITEXT7)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.