Example #1
0
 // ---------------------------------------------------------------------------
 public void Write(Stream stream)
 {
     using (ZipFile zip = new ZipFile())
     {
         Stationery      s           = new Stationery();
         StampStationery ss          = new StampStationery();
         byte[]          stationery  = s.CreateStationary();
         byte[]          sStationery = ss.ManipulatePdf(
             ss.CreatePdf(), stationery
             );
         byte[] insertPages = ManipulatePdf(sStationery, stationery);
         zip.AddEntry(RESULT1, insertPages);
         // reorder the pages in the PDF
         PdfReader reader = new PdfReader(insertPages);
         reader.SelectPages("3-41,1-2");
         using (MemoryStream ms = new MemoryStream())
         {
             using (PdfStamper stamper = new PdfStamper(reader, ms))
             {
             }
             zip.AddEntry(RESULT2, ms.ToArray());
         }
         zip.AddEntry(Utility.ResultFileName(s.ToString() + ".pdf"), stationery);
         zip.AddEntry(Utility.ResultFileName(ss.ToString() + ".pdf"), sStationery);
         zip.Save(stream);
     }
 }
Example #2
0
 // --------------------------------------------------------------------------- 
 public void Write(Stream stream)
 {
     using (ZipFile zip = new ZipFile())
     {
         Stationery s = new Stationery();
         StampStationery ss = new StampStationery();
         byte[] stationery = s.CreateStationary();
         byte[] sStationery = ss.ManipulatePdf(
           ss.CreatePdf(), stationery
         );
         byte[] insertPages = ManipulatePdf(sStationery, stationery);
         zip.AddEntry(RESULT1, insertPages);
         // reorder the pages in the PDF
         PdfReader reader = new PdfReader(insertPages);
         reader.SelectPages("3-41,1-2");
         using (MemoryStream ms = new MemoryStream())
         {
             using (PdfStamper stamper = new PdfStamper(reader, ms))
             {
             }
             zip.AddEntry(RESULT2, ms.ToArray());
         }
         zip.AddEntry(Utility.ResultFileName(s.ToString() + ".pdf"), stationery);
         zip.AddEntry(Utility.ResultFileName(ss.ToString() + ".pdf"), sStationery);
         zip.Save(stream);
     }
 }
        // --------------------------------------------------------------------------- 
        public void Write(Stream stream)
        {
            using (ZipFile zip = new ZipFile())
            {
                // previous example
                Stationery s = new Stationery();
                StampStationery ss = new StampStationery();
                byte[] stationery = s.CreateStationary();
                byte[] sStationery = ss.CreatePdf();

                zip.AddEntry(RESULT, ManipulatePdf(sStationery, stationery));
                zip.AddEntry(ORIGINAL, sStationery);
                zip.AddEntry(Utility.ResultFileName(s.ToString() + ".pdf"), stationery);
                zip.Save(stream);
            }
        }
Example #4
0
        // ---------------------------------------------------------------------------
        public void Write(Stream stream)
        {
            using (ZipFile zip = new ZipFile())
            {
                // previous example
                Stationery      s           = new Stationery();
                StampStationery ss          = new StampStationery();
                byte[]          stationery  = s.CreateStationary();
                byte[]          sStationery = ss.CreatePdf();

                zip.AddEntry(RESULT, ManipulatePdf(sStationery, stationery));
                zip.AddEntry(ORIGINAL, sStationery);
                zip.AddEntry(Utility.ResultFileName(s.ToString() + ".pdf"), stationery);
                zip.Save(stream);
            }
        }
Example #5
0
        // ---------------------------------------------------------------------------
        public void Write(Stream stream)
        {
            using (ZipFile zip = new ZipFile())
            {
                // previous example
                Stationery s          = new Stationery();
                byte[]     stationary = s.CreatePdf(s.CreateStationary());
                // reader for the src file
                PdfReader reader = new PdfReader(stationary);
                // initializations
                int pow = 1;

                do
                {
                    Rectangle pageSize = reader.GetPageSize(1);
                    Rectangle newSize  = (pow % 2) == 0
                      ? new Rectangle(pageSize.Width, pageSize.Height)
                      : new Rectangle(pageSize.Height, pageSize.Width)
                    ;
                    Rectangle unitSize = new Rectangle(pageSize.Width, pageSize.Height);
                    for (int i = 0; i < pow; i++)
                    {
                        unitSize = new Rectangle(unitSize.Height / 2, unitSize.Width);
                    }
                    int n = (int)Math.Pow(2, pow);
                    int r = (int)Math.Pow(2, pow / 2);
                    int c = n / r;

                    using (MemoryStream ms = new MemoryStream())
                    {
                        // step 1
                        using (Document document = new Document(newSize, 0, 0, 0, 0))
                        {
                            // step 2
                            PdfWriter writer = PdfWriter.GetInstance(document, ms);
                            // step 3
                            document.Open();
                            // step 4
                            PdfContentByte  cb = writer.DirectContent;
                            PdfImportedPage page;
                            Rectangle       currentSize;
                            float           offsetX, offsetY, factor;
                            int             total = reader.NumberOfPages;

                            for (int i = 0; i < total;)
                            {
                                if (i % n == 0)
                                {
                                    document.NewPage();
                                }
                                currentSize = reader.GetPageSize(++i);
                                factor      = Math.Min(
                                    unitSize.Width / currentSize.Width,
                                    unitSize.Height / currentSize.Height
                                    );
                                offsetX = unitSize.Width * ((i % n) % c)
                                          + (unitSize.Width - (currentSize.Width * factor)) / 2f
                                ;
                                offsetY = newSize.Height
                                          - (unitSize.Height * (((i % n) / c) + 1))
                                          + (unitSize.Height - (currentSize.Height * factor)) / 2f
                                ;
                                page = writer.GetImportedPage(reader, i);
                                cb.AddTemplate(page, factor, 0, 0, factor, offsetX, offsetY);
                            }
                        }
                        zip.AddEntry(string.Format(RESULT, n), ms.ToArray());
                        ++pow;
                    }
                } while (pow < 5);
                zip.AddEntry(Utility.ResultFileName(s.ToString() + ".pdf"), stationary);
                zip.Save(stream);
            }
        }
Example #6
0
        // ---------------------------------------------------------------------------     
        public void Write(Stream stream)
        {
            using (ZipFile zip = new ZipFile())
            {
                // previous example
                Stationery s = new Stationery();
                byte[] stationary = s.CreatePdf(s.CreateStationary());
                // reader for the src file
                PdfReader reader = new PdfReader(stationary);
                // initializations
                int pow = 1;

                do
                {
                    Rectangle pageSize = reader.GetPageSize(1);
                    Rectangle newSize = (pow % 2) == 0
                      ? new Rectangle(pageSize.Width, pageSize.Height)
                      : new Rectangle(pageSize.Height, pageSize.Width)
                    ;
                    Rectangle unitSize = new Rectangle(pageSize.Width, pageSize.Height);
                    for (int i = 0; i < pow; i++)
                    {
                        unitSize = new Rectangle(unitSize.Height / 2, unitSize.Width);
                    }
                    int n = (int)Math.Pow(2, pow);
                    int r = (int)Math.Pow(2, pow / 2);
                    int c = n / r;

                    using (MemoryStream ms = new MemoryStream())
                    {
                        // step 1
                        using (Document document = new Document(newSize, 0, 0, 0, 0))
                        {
                            // step 2
                            PdfWriter writer = PdfWriter.GetInstance(document, ms);
                            // step 3
                            document.Open();
                            // step 4
                            PdfContentByte cb = writer.DirectContent;
                            PdfImportedPage page;
                            Rectangle currentSize;
                            float offsetX, offsetY, factor;
                            int total = reader.NumberOfPages;

                            for (int i = 0; i < total; )
                            {
                                if (i % n == 0)
                                {
                                    document.NewPage();
                                }
                                currentSize = reader.GetPageSize(++i);
                                factor = Math.Min(
                                    unitSize.Width / currentSize.Width,
                                    unitSize.Height / currentSize.Height
                                );
                                offsetX = unitSize.Width * ((i % n) % c)
                                  + (unitSize.Width - (currentSize.Width * factor)) / 2f
                                ;
                                offsetY = newSize.Height
                                  - (unitSize.Height * (((i % n) / c) + 1))
                                  + (unitSize.Height - (currentSize.Height * factor)) / 2f
                                ;
                                page = writer.GetImportedPage(reader, i);
                                cb.AddTemplate(page, factor, 0, 0, factor, offsetX, offsetY);
                            }
                        }
                        zip.AddEntry(string.Format(RESULT, n), ms.ToArray());
                        ++pow;
                    }
                } while (pow < 5);
                zip.AddEntry(Utility.ResultFileName(s.ToString() + ".pdf"), stationary);
                zip.Save(stream);
            }
        }