Пример #1
0
        private static void GeneratePap720Pdf(PdfLibWrapper pdf)
        {
            var sourceFilePath = @"base_source.pdf";
            var layout         = LayoutRepository.GetAll().Single(l => l.PapCode == 720);

            pdf.begin_page_ext(layout.SheetWidth, layout.SheetHeight, string.Empty);

            foreach (var page in layout.Pages)
            {
                var sourcePdf = pdf.open_pdi_document(sourceFilePath, string.Empty);

                var pdfPage = pdf.open_pdi_page(sourcePdf, 1, "");
                // todo: move mirroring setting to Layout
                pdf.fit_pdi_page(pdfPage, 0, 0, $"boxsize={{{page.Width} {page.Height}}} fitmethod=meet scale={{-1 1}}");
                pdf.close_pdi_page(pdfPage);

                foreach (var pageElement in page.Elements)
                {
                    pdf.setcolor("stroke", "rgb", 1.0, 1.0, 0.0, 0.0);
                    pdf.rect(pageElement.Left, pageElement.Bottom, pageElement.Width, pageElement.Height);
                    pdf.stroke();

                    var fontHandle = pdf.load_font(pageElement.Resource.FontName, "unicode", "errorpolicy=return");
                    pdf.setfont(fontHandle, pageElement.Resource.FontSize);
                    pdf.fit_textline(
                        pageElement.Resource.FileName,
                        pageElement.Left,
                        pageElement.Bottom,
                        string.Empty);
                }
            }

            pdf.end_page_ext(string.Empty);
        }
Пример #2
0
        private static void BuildPdf(PdfLibWrapper pdf, OutputFile outputFile)
        {
            foreach (var outputPage in outputFile.Pages)
            {
                pdf.begin_page_ext(outputFile.SheetSize.Width, outputFile.SheetSize.Height, string.Empty);

                foreach (var tile in outputPage.Tiles)
                {
                    var sourcePdf = pdf.open_pdi_document(tile.SourceFilePath, string.Empty);
                    // "pdiusebox=media" means that all content of the source pdf will be used, not only visible part (crop box), see pdflib api reference
                    var sourcePage = pdf.open_pdi_page(sourcePdf, tile.SourcePage.Number, "pdiusebox=media");

                    var matchboxString       = BuildPdfMatchboxString(tile.MediaBox, tile.CutBox, tile.SourcePage.CropBox);
                    var orientationString    = BuildPdfOrientationString(tile.MediaRotationAngle);
                    var boxsizeString        = BuildPdfBoxsizeString(tile.MediaBox);
                    var fitmethodString      = "fitmethod=clip"; // will cut everything that overflows fitbox boundaries
                    var tilePlacementOptions = $"{matchboxString} {boxsizeString} {orientationString} {fitmethodString}";

                    pdf.fit_pdi_page(sourcePage, tile.MediaBox.Left, tile.MediaBox.Bottom, tilePlacementOptions);

                    // todo: tech info
                    var font = pdf.load_font("Helvetica", "unicode", "");
                    pdf.setfont(font, 20);
                    pdf.fit_textline(matchboxString, tile.MediaBox.Left + 40, tile.MediaBox.Bottom + 30, string.Empty);

                    pdf.close_pdi_page(sourcePage);
                }

                pdf.end_page_ext(string.Empty);
            }
        }
Пример #3
0
        private static void DrawSourcePdf(PdfLibWrapper pdf)
        {
            var sourcePdf  = pdf.open_pdi_document("base_source.pdf", string.Empty);
            var pagesCount = pdf.pcos_get_number(sourcePdf, "length:pages");

            Console.WriteLine($"Pages count in source pdf: {pagesCount}");

            for (var pageNumber = 1; pageNumber <= pagesCount; pageNumber++)
            {
                var page = pdf.open_pdi_page(sourcePdf, pageNumber, "");

                pdf.begin_page_ext(500, 500, string.Empty);
                pdf.setcolor("stroke", "rgb", 1.0, 0.0, 0.0, 0.0);
                pdf.rect(5, 5, 490, 490);
                pdf.stroke();
                pdf.fit_pdi_page(page, 10, 10, "boxsize={480 480} fitmethod=entire");
                pdf.close_pdi_page(page);
                pdf.end_page_ext(string.Empty);
            }
        }