Пример #1
0
        /// <summary>
        /// 4up layout requires matching paper orientation instead of the opposite paper orientation.
        /// This method achieves that happy state.
        /// </summary>
        protected override void SetPaperSize(PaperTarget paperTarget)
        {
            var size = paperTarget.GetPaperDimensions(_inputPdf.PixelHeight, _inputPdf.PixelWidth);

            _paperWidth  = size.X;
            _paperHeight = size.Y;
        }
Пример #2
0
 protected virtual void SetPaperSize(PaperTarget paperTarget)
 {
     _paperWidth  = paperTarget.GetPaperDimensions(_inputPdf.PixelWidth, _inputPdf.PixelHeight).X;
     _paperHeight = paperTarget.GetPaperDimensions(_inputPdf.PixelWidth, _inputPdf.PixelHeight).Y;
 }
Пример #3
0
        public override void Layout(XPdfForm inputPdf, string inputPath, string outputPath, PaperTarget paperTarget, bool rightToLeft, bool showCropMarks)
        {
            if (!showCropMarks && Math.Abs(_bleedMM) < kBleedMicroDeltaMM)
            {
                File.Copy(inputPath, outputPath, true);         // we don't have any value to add, so just deliver a copy of the original
            }
            else
            {
                //_rightToLeft = rightToLeft;
                _inputPdf      = inputPdf;
                _showCropMarks = showCropMarks;

                PdfDocument outputDocument = new PdfDocument();
                outputDocument.PageLayout = PdfPageLayout.SinglePage;

                // Despite the name, PixelWidth is the same as PointWidth, just as an integer instead of
                // double precision.  We may as well use all the precision we can get.
                _paperWidth  = _inputPdf.PointWidth;
                _paperHeight = _inputPdf.PointHeight;

                // NB: Setting outputDocument.Settings.TrimMargins.All does not do what we want: it either
                // shrinks or expands the MediaBox/CropBox/BleedBox sizes.  It does not change either
                // TrimBox or ArtBox.

                for (int idx = 1; idx <= _inputPdf.PageCount; idx++)
                {
                    using (XGraphics gfx = GetGraphicsForNewPage(outputDocument))
                    {
                        DrawPage(gfx, idx);
                    }
                }

                if (Math.Abs(_bleedMM) > kBleedMicroDeltaMM)
                {
                    var tempPath = Path.ChangeExtension(Path.Combine(Path.GetDirectoryName(outputPath),
                                                                     Path.GetRandomFileName()), "pdf");
                    outputDocument.Save(tempPath);
                    outputDocument.Close();
                    outputDocument = PdfReader.Open(tempPath, PdfDocumentOpenMode.Import);
                    var         bleedMargin = new XUnit(_bleedMM, XGraphicsUnit.Millimeter);
                    PdfDocument realOutput  = new PdfDocument();
                    realOutput.PageLayout = PdfPageLayout.SinglePage;
                    var trimLocation = new XPoint(bleedMargin.Point, bleedMargin.Point);
                    foreach (var page in outputDocument.Pages)
                    {
                        var trimBox = new PdfRectangle(trimLocation, new XSize(page.MediaBox.Width - 2 * bleedMargin.Point, page.MediaBox.Height - 2 * bleedMargin.Point));
                        // All of the boxes start out the same size: MediaBox, CropBox, BleedBox, ArtBox, and TrimBox.
                        // MediaBox is presumably the physical paper size.
                        // Set CropBox the same as MediaBox.  CropBox limits what you see in Adobe Acrobat Reader DC and even Acrobat Pro.
                        // Also set BleedBox the same as MediaBox.  See https://i0.wp.com/makingcomics.spiltink.org/wp-content/uploads/2015/05/averageamericancomicsized.jpg.
                        page.BleedBox = page.MediaBox;
                        page.CropBox  = page.MediaBox;
                        page.ArtBox   = trimBox;
                        page.TrimBox  = trimBox;
                        realOutput.AddPage(page);
                    }
                    outputDocument.Close();
                    File.Delete(tempPath);
                    realOutput.Save(outputPath);
                }
                else
                {
                    outputDocument.Save(outputPath);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Produce a new pdf with rearranged pages
        /// </summary>
        /// <param name="inputPdf">the source pdf</param>
        /// <param name="inputPath">the path to the source pdf (used by null layouter)</param>
        /// <param name="outputPath"></param>
        /// <param name="paperTarget">The size of the pages of the output pdf</param>
        /// <param name="rightToLeft">Is this a right-to-left language?  Might be better-named "backToFront"</param>
        /// <param name="showCropMarks">For commercial printing, make a Trimbox, BleedBox, and crop marks</param>
        public virtual void Layout(XPdfForm inputPdf, string inputPath, string outputPath, PaperTarget paperTarget, bool rightToLeft, bool showCropMarks)
        {
            _rightToLeft   = rightToLeft;
            _inputPdf      = inputPdf;
            _showCropMarks = showCropMarks;

            PdfDocument outputDocument = new PdfDocument();

            // Show single pages
            // (Note: one page contains two pages from the source document.
            //  If the number of pages of the source document can not be
            //  divided by 4, the first pages of the output document will
            //  each contain only one page from the source document.)
            outputDocument.PageLayout = PdfPageLayout.SinglePage;

            // Determine width and height
            SetPaperSize(paperTarget);


            int inputPages            = _inputPdf.PageCount;
            int numberOfSheetsOfPaper = inputPages / 4;

            if (numberOfSheetsOfPaper * 4 < inputPages)
            {
                numberOfSheetsOfPaper += 1;
            }
            int numberOfPageSlotsAvailable = 4 * numberOfSheetsOfPaper;
            int vacats = numberOfPageSlotsAvailable - inputPages;

            LayoutInner(outputDocument, numberOfSheetsOfPaper, numberOfPageSlotsAvailable, vacats);

//            if(true)
//                foreach (PdfPage page in outputDocument.Pages)
//                {
//
//                   var  gfx = XGraphics.FromPdfPage(page);
//                    gfx.DrawImage(page, 0.0,0.0);
//                    page.MediaBox = new PdfRectangle(new XPoint(m.X2, m.Y1), new XPoint(m.X1, m.Y2));
//                }
            outputDocument.Save(outputPath);
        }
Пример #5
0
        public override void Layout(XPdfForm inputPdf, string inputPath, string outputPath, PaperTarget paperTarget, bool rightToLeft, bool showCropMarks)
        {
            if (!showCropMarks)
            {
                File.Copy(inputPath, outputPath, true);    // we don't have any value to add, so just deliver a copy of the original
            }
            else
            {
                //_rightToLeft = rightToLeft;
                _inputPdf      = inputPdf;
                _showCropMarks = showCropMarks;

                PdfDocument outputDocument = new PdfDocument();
                outputDocument.PageLayout = PdfPageLayout.SinglePage;

                _paperWidth  = _inputPdf.PixelWidth;
                _paperHeight = _inputPdf.PixelHeight;
//	            if (showCropMarks)
//	            {
//					_paperWidth.Millimeter += (2.0 * LayoutMethod.kMillimetersBetweenTrimAndMediaBox);
//					_paperHeight.Millimeter += (2.0 * LayoutMethod.kMillimetersBetweenTrimAndMediaBox);
//	            }
                for (int idx = 1; idx <= _inputPdf.PageCount; idx++)
                {
                    using (XGraphics gfx = GetGraphicsForNewPage(outputDocument))
                    {
                        DrawPage(gfx, idx);
                    }
                }

                outputDocument.Save(outputPath);
            }
        }