예제 #1
0
        private static Box ReadBox(PdfLibWrapper pdf, int fileHandle, int page, string boxName)
        {
            var boxLeft   = (float)pdf.pcos_get_number(fileHandle, $"pages[{page}]/{boxName}[0]");
            var boxBottom = (float)pdf.pcos_get_number(fileHandle, $"pages[{page}]/{boxName}[1]");
            var boxRight  = (float)pdf.pcos_get_number(fileHandle, $"pages[{page}]/{boxName}[2]");
            var boxTop    = (float)pdf.pcos_get_number(fileHandle, $"pages[{page}]/{boxName}[3]");
            var box       = new Box {
                Left = boxLeft, Bottom = boxBottom, Width = boxRight - boxLeft, Height = boxTop - boxBottom
            };

            return(box);
        }
예제 #2
0
        private static SourcePage GetSourcePage(PdfLibWrapper pdf, int sourcePdf, int pageIndex)
        {
            var pageWidth     = (float)pdf.pcos_get_number(sourcePdf, $"pages[{pageIndex}]/width");
            var pageHeight    = (float)pdf.pcos_get_number(sourcePdf, $"pages[{pageIndex}]/height");
            var rotationAngle = GetPageRotationAngle(pdf, sourcePdf, pageIndex);

            return(new SourcePage
            {
                SheetSize = new Size {
                    Width = pageWidth, Height = pageHeight
                },
                RotationAngle = rotationAngle,
                //MediaBox = ReadBox(pdf, sourcePdf, pageIndex, "MediaBox"),
                CropBox = ReadBox(pdf, sourcePdf, pageIndex, "CropBox"),
                Number = pageIndex + 1
            });
        }
예제 #3
0
        private static float GetPageRotationAngle(PdfLibWrapper pdf, int fileHandle, int page)
        {
            var objtype = pdf.pcos_get_string(fileHandle, $"type:pages[{page}]/Rotate");

            if (objtype == "number")
            {
                return((float)pdf.pcos_get_number(fileHandle, $"pages[{page}]/Rotate"));
            }

            return(0.0f);
        }
예제 #4
0
        public SourceFile Get(int albumId)
        {
            var fileName     = $"9999.{albumId}.0.pdf";
            var fullFilePath = Path.Combine(_storageFolderPath, fileName);
            var pdf          = new PdfLibWrapper("W900205-010045-139339-E74DE2-79Q6F2");
            var sourcePdf    = pdf.open_pdi_document(fullFilePath, string.Empty);
            var pagesCount   = (int)pdf.pcos_get_number(sourcePdf, "length:pages");

            var file = new SourceFile {
                FileName = fullFilePath
            };

            for (var pageIndex = 0; pageIndex < pagesCount; pageIndex++)
            {
                file.Pages.Add(GetSourcePage(pdf, sourcePdf, pageIndex));
            }

            return(file);
        }
예제 #5
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);
            }
        }