private static void AddLineSeparator(Page page, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, Config config, Package package)
        {
            if (package.LineSeparator.ImageStream == null)
            {
                return;
            }

            // for drawing line separator between headerfooter and body, we need to add header/footer offsets to page margins
            var bodyMargin = PageSetting.GetBodyMargin(package, config);

            ImageStamp imageStamp = new ImageStamp(package.LineSeparator.ImageStream)
            {
                TopMargin           = bodyMargin.TopPoints,
                BottomMargin        = bodyMargin.BottomPoints,
                LeftMargin          = bodyMargin.LeftPoints,
                RightMargin         = bodyMargin.RightPoints,
                HorizontalAlignment = horizontalAlignment,
                VerticalAlignment   = verticalAlignment,
                Width  = page.PageInfo.Width - bodyMargin.LeftPoints - bodyMargin.RightPoints,
                Height = 1
            };

            page.AddStamp(imageStamp);
        }
Ejemplo n.º 2
0
        private string AppendFiles(Config config, Package package, Document sourceDocument)
        {
            License license = new License();

            license.SetLicense(config.AsposeLicenseFile);

            foreach (Section section in package.Sections.OrderBy(s => s.Order))
            {
                package.LogProgress(package.LogId, "Creating package section \"" + section.Name + "\"");
                foreach (Item item in section.Items.OrderBy(i => i.Order))
                {
                    Document document = null;
                    switch (item.ItemType)
                    {
                    case ItemType.AuxiliaryDocument:
                        package.LogProgress(package.LogId, "Appending document \"" + item.Name);
                        if (item.AuxiliaryDocument.PageCount <= 0)
                        {
                            continue;
                        }
                        document = new Document(config.DocumentsConvertedFolder + item.AuxiliaryDocument.ConvertedFile);
                        break;

                    case ItemType.Report:
                        package.LogProgress(package.LogId, "Appending report \"" + item.Name);
                        if (item.ReportFilter.PageCount <= 0)
                        {
                            continue;
                        }
                        document = new Document(config.ReportOutputPath + item.ReportFilter.ReportPath);
                        break;
                    }

                    if (document == null)
                    {
                        continue;
                    }
                    int startPageNumber = item.StartPageNumber;

                    foreach (Page page in document.Pages)
                    {
                        if (item.ItemType == ItemType.AuxiliaryDocument && (item.AuxiliaryDocument.DocumentType == DocumentType.Excel || item.AuxiliaryDocument.DocumentType == DocumentType.Pdf))
                        {
                            PageSetting.SetPageSize(page, package.PageSetting.Paper);
                        }

                        sourceDocument.Pages.Add(page);
                        package.PdfPackagePageNumbers.Add(new PdfPackagePageNumber
                        {
                            PdfPageNumber     = sourceDocument.Pages.Count - 1,
                            ContentPageNumber = startPageNumber
                        });
                        startPageNumber++;
                    }
                }
                package.LogProgress(package.LogId, "Completed appending section \"" + section.Name + "\"");
            }

            string fileName     = string.Format("{0}_{1}.pdf", package.Name.Replace(" ", "_"), DateTime.Now.ToString("yyyyMMddHHmmss"));
            string packagedFile = config.DocumentsConvertedFolder + @"\" + fileName;

            if (sourceDocument.Pages.Count > 0)
            {
                sourceDocument.Pages.Delete(1);
            }

            sourceDocument.Save(packagedFile);

            PageSetting.AddMargins(packagedFile, package, config);
            HeaderFooterFactory.Create(package, packagedFile, config);
            return(fileName);
        }