static public BaseFont GetBaseFont(string familyName)
        {
            if (familyName == null)
            {
                familyName = "";
            }
            string   enc      = LibPDFTools.GetDefaultEncoding(familyName);
            BaseFont baseFont = BaseFont.CreateFont(familyName, enc, BaseFont.NOT_EMBEDDED);

            return(baseFont);
        }
Exemple #2
0
        public string[] Split(string url, string splittedFilesDirectoryName, string prefixOfFileName)
        {
            var bytes = LibPDFTools.GetBytes(url);

            switch (LibPDFTools.GetImageFileType(bytes))
            {
            case ImageFileType.PDF:
                return(SplitPdf(url, splittedFilesDirectoryName, prefixOfFileName));

            case ImageFileType.TIFF:
                return(SplitTiff(bytes, splittedFilesDirectoryName, prefixOfFileName));

            default:
                throw new ArgumentException();
            }
        }
        public PdfReader CreatePdfReader(byte[] bytes, PdfConcatenatorOption option)
        {
            PdfReader reader;

            switch (LibPDFTools.GetImageFileType(bytes))
            {
            case ImageFileType.PDF:
                reader = LibPDFTools.CreatePdfReader(bytes, QueryPassword, true);
                break;

            case ImageFileType.TIFF:
                reader = LibPDFTools.CreatePdfReaderFromTiff(bytes, option.GetBounds(), option.Margins);
                break;

            default:
                reader = LibPDFTools.CreatePdfReaderFromImage(bytes, option.GetBounds(), option.Margins);
                break;
            }
            return(reader);
        }
 public static byte[] GetBytes(string url)
 {
     return(LibPDFTools.GetBytes(LibPDFTools.ToUri(url)));
 }
Exemple #5
0
        public void Append(byte[] bytes)
        {
            using (var ms = new MemoryStream(bytes))
            {
                switch (LibPDFTools.GetImageFileType(bytes))
                {
                case ImageFileType.PDF:
                    using (var pdfDoc = new PDFLibNet.PDFWrapper(""))
                    {
                        pdfDoc.LoadPDF(ms);
                        for (var i = 1; i <= pdfDoc.PageCount; i++)
                        {
                            pdfDoc.CurrentPage = i;
                            pdfDoc.CurrentX    = 0;
                            pdfDoc.CurrentY    = 0;
                            pdfDoc.RenderDPI   = this.resolution;

                            Bitmap pageBuffer = null;
                            using (var oPictureBox = new PictureBox())
                            {
                                pdfDoc.RenderPage(oPictureBox.Handle);
                                pageBuffer          = new Bitmap(pdfDoc.PageWidth, pdfDoc.PageHeight);
                                pdfDoc.ClientBounds = new System.Drawing.Rectangle(0, 0, pdfDoc.PageWidth, pdfDoc.PageHeight);
                                using (var g = Graphics.FromImage(pageBuffer))
                                {
                                    var hdc = g.GetHdc();
                                    pdfDoc.DrawPageHDC(hdc);
                                    g.ReleaseHdc();
                                }
                            }
                            SaveAddTiffPage(pageBuffer);
                            pageBuffer.Dispose();

                            currPageNum++;
                        }
                    }
                    break;

                case ImageFileType.TIFF:
                {
                    using (var image = System.Drawing.Image.FromStream(ms))
                    {
                        var fd            = new System.Drawing.Imaging.FrameDimension(image.FrameDimensionsList[0]);
                        int numberOfPages = image.GetFrameCount(fd);

                        for (int pageNum = 0; pageNum < numberOfPages; pageNum++)
                        {
                            image.SelectActiveFrame(fd, pageNum);
                            if (currPageNum == 0)
                            {
                                backbuffer = (System.Drawing.Image)image.Clone();
                                backbuffer.Save(outStream, codec, encoderParameters_MultiFrame);
                            }
                            else
                            {
                                backbuffer.SaveAdd(image, encoderParameters_FrameDimensionPage);
                            }
                            currPageNum++;
                        }
                    }
                }
                break;

                default:
                {
                    var pageBuffer = System.Drawing.Image.FromStream(ms);
                    SaveAddTiffPage(pageBuffer);
                }
                    currPageNum++;
                    break;
                }
            }
        }
Exemple #6
0
 public void Append(string url)
 {
     Append(LibPDFTools.GetBytes(url));
 }
Exemple #7
0
        private string[] SplitPdf(string url, string splittedFilesDirectoryName, string prefixOfFileName)
        {
            PdfReader reader = LibPDFTools.CreatePdfReader(url, QueryPassword, false);

            try
            {
                reader.ConsolidateNamedDestinations();
                IList <Dictionary <string, object> > bookmarks = SimpleBookmark.GetBookmark(reader);
                int      numberOfPages = reader.NumberOfPages;
                string[] splittedFiles = new string[numberOfPages];
                Directory.CreateDirectory(splittedFilesDirectoryName);

                for (int i = 1; i <= numberOfPages; i++)
                {
                    string splittedFile = Path.Combine(splittedFilesDirectoryName, prefixOfFileName + i.ToString("D10") + ".pdf");
                    splittedFiles[i - 1] = splittedFile;

                    //extract bookmarks on the page
                    IList <Dictionary <string, object> > bookmark = null;
                    if (bookmarks != null)
                    {
                        bookmark = new List <Dictionary <string, object> >(bookmarks);
                        int[] rs;
                        rs    = new int[4];
                        rs[0] = 1;
                        rs[1] = i - 1;
                        rs[2] = i + 1;
                        rs[3] = numberOfPages;
                        SimpleBookmark.EliminatePages(bookmark, rs);
                        rs    = new int[2];
                        rs[0] = rs[1] = i;
                        SimpleBookmark.ShiftPageNumbers(bookmark, 1 - i, rs);
                    }

                    using (var document = new Document(reader.GetPageSizeWithRotation(i)))
                    {
                        using (var outStream = new FileStream(splittedFile, FileMode.Create, FileAccess.Write))
                        {
                            using (var writer = new PdfCopy(document, outStream))
                            {
                                document.Open();
                                PdfImportedPage page = writer.GetImportedPage(reader, i);
                                writer.AddPage(page);
                                if (bookmark != null)
                                {
                                    writer.Outlines = bookmark;
                                }
                                writer.Close();
                            }
                            outStream.Close();
                        }
                        document.Close();
                    }
                }
                return(splittedFiles);
            }
            finally
            {
                reader.Close();
            }
        }
        public PdfReader CreatePdfReader(string url, PdfConcatenatorOption option)
        {
            var bytes = LibPDFTools.GetBytes(LibPDFTools.ToUri(url));

            return(CreatePdfReader(bytes, option));
        }