adds a new page to the end of the PDF object.

 returns the new page object.

 unless the media box is specified, it defaults to US Letter: [0, 0, 612.0, 792.0]
502416
def new_page(mediabox = [0, 0, 612.0, 792.0], _location = -1)
      p = PDFWriter.new(mediabox)
      insert(-1, p)
      p
    end
192880
def create_page(pagename):
    
    page = pagename.lstrip("/").rstrip("/")
    _, _ext = os.path.splitext(pagename)

    # If the file doesn't have an extension, we'll just create one
    if not _ext or _ext == "":
        page += ".jade"

    if not page.endswith(PAGE_FORMAT):
        error("Can't create '%s'" % page)
        print("Invalid filename format")
        print("Filename must be in: '%s'" % " | ".join(PAGE_FORMAT))
    else:
        engine = Yass(CWD)
        markup = "jade"
        if page.endswith(".md"):
            markup = "md"
        if page.endswith(".html"):
            markup = "html"

        dest_file = os.path.join(engine.pages_dir, page)
        dest_dir = os.path.dirname(dest_file)

        content = TPL_HEADER
        content += TPL_BODY[markup]

        if os.path.isfile(dest_file):
            error("File exists already")
            print("Location: %s" % dest_file)

        else:
            if not os.path.isdir(dest_dir):
                os.makedirs(dest_dir)
            with open(dest_file, "w") as f:
                f.write(content)

            print("New page created: '%s'" % page)
            print("Location: %s" % dest_file)


    footer()
1366816
def create_page(title, space, parrent_page_id=nil)
            params = { 'type' => 'page',
                'title' => title,
                'space' => {'key' => space},
                'body' => {
                    'storage' => {
                        'value' => ("#{ @body_message.to_json.gsub("&&", "&amp;&amp;").gsub(/\\u001b.../, "   ") }").force_encoding('UTF-8'),
                        'representation' => 'storage'
                        }
                    }
                }
            if parrent_page_id
                params['ancestors'] = [{'type' => 'page', 'id' => parrent_page_id}]
            end

            uri = URI.parse(@base_url)
            https = Net::HTTP.new(uri.host,uri.port)
            https.use_ssl = true
            # https.set_debug_output $stderr
            req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
            req.basic_auth(@user, @password)
            req['Accept'] = 'application/json'
            req.body = "#{params.to_json}"
            response = https.request(req)
            response = JSON.parse(response.body)
            if response["statusCode"] == 400
                puts response.inspect
                puts req.body.inspect
                puts "Create page: Error reporting to confluence: #{response["message"]}"
                raise "Create page: Error reporting to confluence: #{response["message"]}"
            else
                puts "Reported page creation."
            end
        end
348618
def write_pdf(pdf_obj, destination):
    
    reader = PdfFileReader(pdf_obj)  # Create new PDF object
    writer = PdfFileWriter()

    page_count = reader.getNumPages()

    # add the "watermark" (which is the new pdf) on the existing page
    for page_number in range(page_count):
        page = reader.getPage(page_number)
        writer.addPage(page)

    # finally, write "output" to a real file
    with open(destination, "wb") as outputStream:
        writer.write(outputStream)
802491
def append_memory_pdf_to_writer(input_pdf: bytes,
                                writer: PdfFileWriter,
                                start_recto: bool = True) -> None:
    
    if not input_pdf:
        return
    if start_recto and writer.getNumPages() % 2 != 0:
        writer.addBlankPage()
        # ... suitable for double-sided printing
    infile = io.BytesIO(input_pdf)
    reader = PdfFileReader(infile)
    for page_num in range(reader.numPages):
        writer.addPage(reader.getPage(page_num))
1243985
def compile(options = {})

            load_all_objects unless loaded?

            #
            # A valid document must have at least one page.
            #
            append_page if pages.empty?

            #
            # Allocates object numbers and creates references.
            # Invokes object finalization methods.
            #
            physicalize(options)

            #
            # Sets the PDF version header.
            #
            version, level = version_required
            @header.major_version = version[0,1].to_i
            @header.minor_version = version[2,1].to_i

            set_extension_level(version, level) if level > 0

            self
        end
1350365
function newDocument($pageSize=array(0,0,612,792)){
    $this->numObj=0;
    $this->objects = array();

    $this->numObj++;
    $this->o_catalog($this->numObj,'new');

    $this->numObj++;
    $this->o_outlines($this->numObj,'new');

    $this->numObj++;
    $this->o_pages($this->numObj,'new');

    $this->o_pages($this->numObj,'mediaBox',$pageSize);
    $this->currentNode = 3;

    $this->numObj++;
    $this->o_procset($this->numObj,'new');

    $this->numObj++;
    $this->o_info($this->numObj,'new');

    $this->numObj++;
    $this->o_page($this->numObj,'new');

    // need to store the first page id as there is no way to get it to the user during
    // startup
    $this->firstPageId = $this->currentContents;
    }
154589
def steal_page(self, page):
        
        if page.doc == self:
            return
        self.fs.mkdir_p(self.path)

        new_page = ImgPage(self, self.nb_pages)
        logger.info("%s --> %s" % (str(page), str(new_page)))
        new_page._steal_content(page)
760286
def add(self, document, watermark):
        """"""
        # 5a. Create output PDF file name
        output_filename = self.output_filename

        def pypdf3():
            """Much slower than PyPDF3 method."""
            # 5b. Get our files ready
            document_reader = PdfFileReader(document)
            output_file = PdfFileWriter()

            # Number of pages in input document
            page_count = document_reader.getNumPages()

            # Watermark objects
            watermark_reader = PdfFileReader(watermark)
            wtrmrk_page = watermark_reader.getPage(0)
            wtrmrk_width = (wtrmrk_page.mediaBox.getWidth() / 2) + 0
            wtrmrk_height = (wtrmrk_page.mediaBox.getHeight() / 2) + 80
            wtrmrk_rotate = -int(Info(watermark_reader).rotate) if Info(watermark_reader).rotate is not None else 0

            # 5c. Go through all the input file pages to add a watermark to them
            for page_number in range(page_count):
                # Merge the watermark with the page
                if not self.underneath:
                    input_page = document_reader.getPage(page_number)
                    if wtrmrk_rotate is not 0:
                        input_page.mergeRotatedTranslatedPage(wtrmrk_page, wtrmrk_rotate, wtrmrk_width, wtrmrk_height)
                    else:
                        wtrmrk_width = 0
                        wtrmrk_height = 0
                        input_page.mergeTranslatedPage(wtrmrk_page, wtrmrk_width, wtrmrk_height)
                else:
                    size = Info(document_reader).dimensions
                    input_page = PageObject().createBlankPage(document_reader, size['w'], size['h'])
                    if wtrmrk_rotate is not 0:
                        input_page.mergeRotatedTranslatedPage(wtrmrk_page, wtrmrk_rotate, wtrmrk_width, wtrmrk_height)
                    else:
                        wtrmrk_width = 0
                        wtrmrk_height = 0
                        input_page.mergeTranslatedPage(wtrmrk_page, wtrmrk_width, wtrmrk_height)
                    input_page.mergePage(document_reader.getPage(page_number))

                # Add page from input file to output document
                output_file.addPage(input_page)

            # 5d. finally, write "output" to PDF
            with open(output_filename, "wb") as outputStream:
                output_file.write(outputStream)
            return output_filename

        def pdfrw():
            """Faster than PyPDF3 method by as much as 15x."""
            # TODO: Fix issue where watermark is improperly placed on large pagesize PDFs
            # print(Info(document).size)
            # print(Info(watermark).size)
            # print('\n')

            # Open both the source files
            wmark_trailer = PdfReader(watermark)
            trailer = PdfReader(document)

            # Handle different sized pages in same document with
            # a memoization cache, so we don't create more watermark
            # objects than we need to (typically only one per document).

            wmark_page = wmark_trailer.pages[0]
            wmark_cache = {}

            # Process every page
            for pagenum, page in enumerate(trailer.pages, 1):

                # Get the media box of the page, and see
                # if we have a matching watermark in the cache
                mbox = tuple(float(x) for x in page.MediaBox)
                odd = pagenum & 1
                key = mbox, odd
                wmark = wmark_cache.get(key)
                if wmark is None:

                    # Create and cache a new watermark object.
                    wmark = wmark_cache[key] = PageMerge().add(wmark_page)[0]

                    # The math is more complete than it probably needs to be,
                    # because the origin of all pages is almost always (0, 0).
                    # Nonetheless, we illustrate all the values and their names.

                    page_x, page_y, page_x1, page_y1 = mbox
                    page_w = page_x1 - page_x
                    page_h = page_y1 - page_y  # For illustration, not used

                    # Scale the watermark if it is too wide for the page
                    # (Could do the same for height instead if needed)
                    if wmark.w > page_w:
                        wmark.scale(1.0 * page_w / wmark.w)

                    # Always put watermark at the top of the page
                    # (but see horizontal positioning for other ideas)
                    wmark.y += page_y1 - wmark.h

                    # For odd pages, put it at the left of the page,
                    # and for even pages, put it on the right of the page.
                    if odd:
                        wmark.x = page_x
                    else:
                        wmark.x += page_x1 - wmark.w

                    # Optimize the case where the watermark is same width
                    # as page.
                    if page_w == wmark.w:
                        wmark_cache[mbox, not odd] = wmark

                # Add the watermark to the page
                PageMerge(page).add(wmark, prepend=self.underneath).render()

            # Write out the destination file
            PdfWriter(output_filename, trailer=trailer).write()

        if self.method is 'pypdf3':
            return pypdf3()
        else:
            return pdfrw()
216357
function init() {
		$_option = 'pressbooks_theme_options_' . $this->getSlug();
		$_page = $_option;
		$_section = $this->getSlug() . '_options_section';

		if ( false === get_option( $_option ) ) {
			add_option( $_option, $this->defaults );
		}

		add_settings_section(
			$_section,
			$this->getTitle(),
			[ $this, 'display' ],
			$_page
		);

		$custom_styles = Container::get( 'Styles' );
		$v2_compatible = $custom_styles->isCurrentThemeCompatible( 2 );

		if ( $v2_compatible ) {
			add_settings_field(
				'pdf_body_font_size',
				__( 'Body Font Size', 'pressbooks' ),
				[ $this, 'renderBodyFontSizeField' ],
				$_page,
				$_section,
				[
					__( 'Heading sizes are proportional to the body font size and will also be affected by this setting.', 'pressbooks' ),
					'pt',
					'label_for' => 'pdf_body_font_size',
				]
			);

			add_settings_field(
				'pdf_body_line_height',
				__( 'Body Line Height', 'pressbooks' ),
				[ $this, 'renderBodyLineHightField' ],
				$_page,
				$_section,
				[
					'',
					'em',
					'label_for' => 'pdf_body_line_height',
				]
			);
		}

		add_settings_field(
			'pdf_page_size',
			__( 'Page Size', 'pressbooks' ),
			[ $this, 'renderPageSizeField' ],
			$_page,
			$_section,
			[
				__( 'Digest (5.5&quot; &times; 8.5&quot;)', 'pressbooks' ),
				__( 'US Trade (6&quot; &times; 9&quot;)', 'pressbooks' ),
				__( 'US Letter (8.5&quot; &times; 11&quot;)', 'pressbooks' ),
				__( 'Custom (8.5&quot; &times; 9.25&quot;)', 'pressbooks' ),
				__( 'Duodecimo (5&quot; &times; 7.75&quot;)', 'pressbooks' ),
				__( 'Pocket (4.25&quot; &times; 7&quot;)', 'pressbooks' ),
				__( 'A4 (21cm &times; 29.7cm)', 'pressbooks' ),
				__( 'A5 (14.8cm &times; 21cm)', 'pressbooks' ),
				__( '5&quot; &times; 8&quot;', 'pressbooks' ),
				__( 'Custom&hellip;', 'pressbooks' ),
				'label_for' => 'pdf_page_size',
			]
		);

		add_settings_field(
			'pdf_page_width',
			__( 'Page Width', 'pressbooks' ),
			[ $this, 'renderPageWidthField' ],
			$_page,
			$_section,
			[
				__( 'Page width must be expressed in CSS-compatible units, e.g. &lsquo;5.5in&rsquo; or &lsquo;10cm&rsquo;.' ),
				'label_for' => 'pdf_page_width',
			]
		);

		add_settings_field(
			'pdf_page_height',
			__( 'Page Height', 'pressbooks' ),
			[ $this, 'renderPageHeightField' ],
			$_page,
			$_section,
			[
				__( 'Page height must be expressed in CSS-compatible units, e.g. &lsquo;8.5in&rsquo; or &lsquo;10cm&rsquo;.' ),
				'label_for' => 'pdf_page_height',
			]
		);

		if ( $v2_compatible ) {
			add_settings_field(
				'pdf_page_margins',
				__( 'Margins', 'pressbooks' ),
				[ $this, 'renderMarginsField' ],
				$_page,
				$_section,
				[
					__( 'Customize your book&rsquo;s margins using the fields below.', 'pressbooks' ),
				]
			);

			add_settings_field(
				'pdf_page_margin_outside',
				__( 'Outside Margin', 'pressbooks' ),
				[ $this, 'renderOutsideMarginField' ],
				$_page,
				$_section,
				[
					__( 'Margins must be expressed in CSS-compatible units, e.g. &lsquo;8.5in&rsquo; or &lsquo;10cm&rsquo;.', 'pressbooks' ),
					'label_for' => 'pdf_page_margin_outside',
				]
			);

			add_settings_field(
				'pdf_page_margin_inside',
				__( 'Inside Margin', 'pressbooks' ),
				[ $this, 'renderInsideMarginField' ],
				$_page,
				$_section,
				[
					__( 'Margins must be expressed in CSS-compatible units, e.g. &lsquo;8.5in&rsquo; or &lsquo;10cm&rsquo;.', 'pressbooks' ),
					'label_for' => 'pdf_page_margin_inside',
				]
			);

			add_settings_field(
				'pdf_page_margin_top',
				__( 'Top Margin', 'pressbooks' ),
				[ $this, 'renderTopMarginField' ],
				$_page,
				$_section,
				[
					__( 'Margins must be expressed in CSS-compatible units, e.g. &lsquo;8.5in&rsquo; or &lsquo;10cm&rsquo;.', 'pressbooks' ),
					'label_for' => 'pdf_page_margin_top',
				]
			);

			add_settings_field(
				'pdf_page_margin_bottom',
				__( 'Bottom Margin', 'pressbooks' ),
				[ $this, 'renderBottomMarginField' ],
				$_page,
				$_section,
				[
					__( 'Margins must be expressed in CSS-compatible units, e.g. &lsquo;8.5in&rsquo; or &lsquo;10cm&rsquo;.', 'pressbooks' ),
					'label_for' => 'pdf_page_margin_bottom',
				]
			);
		}

		add_settings_field(
			'pdf_hyphens',
			__( 'Hyphens', 'pressbooks' ),
			[ $this, 'renderHyphenationField' ],
			$_page,
			$_section,
			[
				__( 'Enable hyphenation', 'pressbooks' ),
			]
		);

		add_settings_field(
			'pdf_paragraph_separation',
			__( 'Paragraph Separation', 'pressbooks' ),
			[ $this, 'renderParagraphSeparationField' ],
			$_page,
			$_section,
			[
				'indent' => __( 'Indent paragraphs', 'pressbooks' ),
				'skiplines' => __( 'Skip lines between paragraphs', 'pressbooks' ),
			]
		);

		add_settings_field(
			'pdf_sectionopenings',
			__( 'Section Openings', 'pressbooks' ),
			[ $this, 'renderSectionOpeningsField' ],
			$_page,
			$_section,
			[
				'openauto' => __( 'Left or right page section opening (for print PDF)', 'pressbooks' ),
				'openright' => __( 'Right page section openings (for print PDF)', 'pressbooks' ),
				'remove' => __( 'No blank pages (for web PDF)', 'pressbooks' ),
			]
		);

		add_settings_field(
			'pdf_toc',
			__( 'Table of Contents', 'pressbooks' ),
			[ $this, 'renderTOCField' ],
			$_page,
			$_section,
			[
				__( 'Display table of contents', 'pressbooks' ),
			]
		);

		add_settings_field(
			'pdf_crop_marks',
			__( 'Crop Marks', 'pressbooks' ),
			[ $this, 'renderCropMarksField' ],
			$_page,
			$_section,
			[
				__( 'Display crop marks', 'pressbooks' ),
			]
		);

		if ( CustomCss::isCustomCss() ) {
			add_settings_field(
				'pdf_romanize_parts',
				__( 'Romanize Part Numbers', 'pressbooks' ),
				[ $this, 'renderRomanizePartsField' ],
				$_page,
				$_section,
				[
					__( 'Convert part numbers into Roman numerals', 'pressbooks' ),
				]
			);
		}

		add_settings_field(
			'pdf_footnotes_style',
			__( 'Footnote Style', 'pressbooks' ),
			[ $this, 'renderFootnoteStyleField' ],
			$_page,
			$_section,
			[
				'footnotes' => __( 'Regular footnotes', 'pressbooks' ),
				'endnotes' => __( 'Display as chapter endnotes', 'pressbooks' ),
			]
		);

		add_settings_field(
			'widows',
			__( 'Widows', 'pressbooks' ),
			[ $this, 'renderWidowsField' ],
			$_page,
			$_section,
			[
				'label_for' => 'widows',
			]
		);

		add_settings_field(
			'orphans',
			__( 'Orphans', 'pressbooks' ),
			[ $this, 'renderOrphansField' ],
			$_page,
			$_section,
			[
				'label_for' => 'orphans',
			]
		);

		if ( $v2_compatible ) {
			add_settings_field(
				'running_content',
				__( 'Running Heads & Feet', 'pressbooks' ),
				[ $this, 'renderRunningContentField' ],
				$_page,
				$_section,
				[
					__( 'Running content appears in either running heads or running feet (at the top or bottom of the page) depending on your theme.', 'pressbooks' ),
				]
			);

			add_settings_field(
				'running_content_front_matter_left',
				__( 'Front Matter Left Page Running Content', 'pressbooks' ),
				[ $this, 'renderRunningContentFrontMatterLeftField' ],
				$_page,
				$_section,
				[
					'%book_title%' => __( 'Book Title', 'pressbooks' ),
					'%book_subtitle%' => __( 'Book Subtitle', 'pressbooks' ),
					'%book_author%' => __( 'Book Author', 'pressbooks' ),
					'%section_title%' => __( 'Front Matter Title', 'pressbooks' ),
					'%section_author%' => __( 'Front Matter Author', 'pressbooks' ),
					'%section_subtitle%' => __( 'Front Matter Subtitle', 'pressbooks' ),
					'%blank%' => __( 'Blank', 'pressbooks' ),
					'' => __( 'Custom&hellip;', 'pressbooks' ),
					'label_for' => 'running_content_front_matter_left',
				]
			);

			add_settings_field(
				'running_content_front_matter_right',
				__( 'Front Matter Right Page Running Content', 'pressbooks' ),
				[ $this, 'renderRunningContentFrontMatterRightField' ],
				$_page,
				$_section,
				[
					'%book_title%' => __( 'Book Title', 'pressbooks' ),
					'%book_subtitle%' => __( 'Book Subtitle', 'pressbooks' ),
					'%book_author%' => __( 'Book Author', 'pressbooks' ),
					'%section_title%' => __( 'Front Matter Title', 'pressbooks' ),
					'%section_author%' => __( 'Front Matter Author', 'pressbooks' ),
					'%section_subtitle%' => __( 'Front Matter Subtitle', 'pressbooks' ),
					'%blank%' => __( 'Blank', 'pressbooks' ),
					'' => __( 'Custom&hellip;', 'pressbooks' ),
					'label_for' => 'running_content_front_matter_right',
				]
			);

			add_settings_field(
				'running_content_introduction_left',
				__( 'Introduction Left Page Running Content', 'pressbooks' ),
				[ $this, 'renderRunningContentIntroductionLeftField' ],
				$_page,
				$_section,
				[
					'%book_title%' => __( 'Book Title', 'pressbooks' ),
					'%book_subtitle%' => __( 'Book Subtitle', 'pressbooks' ),
					'%book_author%' => __( 'Book Author', 'pressbooks' ),
					'%section_title%' => __( 'Introduction Title', 'pressbooks' ),
					'%section_author%' => __( 'Introduction Author', 'pressbooks' ),
					'%section_subtitle%' => __( 'Introduction Subtitle', 'pressbooks' ),
					'%blank%' => __( 'Blank', 'pressbooks' ),
					'' => __( 'Custom&hellip;', 'pressbooks' ),
					'label_for' => 'running_content_introduction_left',
				]
			);

			add_settings_field(
				'running_content_introduction_right',
				__( 'Introduction Right Page Running Content', 'pressbooks' ),
				[ $this, 'renderRunningContentIntroductionRightField' ],
				$_page,
				$_section,
				[
					'%book_title%' => __( 'Book Title', 'pressbooks' ),
					'%book_subtitle%' => __( 'Book Subtitle', 'pressbooks' ),
					'%book_author%' => __( 'Book Author', 'pressbooks' ),
					'%section_title%' => __( 'Introduction Title', 'pressbooks' ),
					'%section_author%' => __( 'Introduction Author', 'pressbooks' ),
					'%section_subtitle%' => __( 'Introduction Subtitle', 'pressbooks' ),
					'%blank%' => __( 'Blank', 'pressbooks' ),
					'' => __( 'Custom&hellip;', 'pressbooks' ),
					'label_for' => 'running_content_introduction_right',
				]
			);

			add_settings_field(
				'running_content_part_left',
				__( 'Part Left Page Running Content', 'pressbooks' ),
				[ $this, 'renderRunningContentPartLeftField' ],
				$_page,
				$_section,
				[
					'%book_title%' => __( 'Book Title', 'pressbooks' ),
					'%book_subtitle%' => __( 'Book Subtitle', 'pressbooks' ),
					'%book_author%' => __( 'Book Author', 'pressbooks' ),
					'%part_number%' => __( 'Part Number', 'pressbooks' ),
					'%part_title%' => __( 'Part Title', 'pressbooks' ),
					'%blank%' => __( 'Blank', 'pressbooks' ),
					'' => __( 'Custom&hellip;', 'pressbooks' ),
					'label_for' => 'running_content_part_left',
				]
			);

			add_settings_field(
				'running_content_part_right',
				__( 'Part Right Page Running Content', 'pressbooks' ),
				[ $this, 'renderRunningContentPartRightField' ],
				$_page,
				$_section,
				[
					'%book_title%' => __( 'Book Title', 'pressbooks' ),
					'%book_subtitle%' => __( 'Book Subtitle', 'pressbooks' ),
					'%book_author%' => __( 'Book Author', 'pressbooks' ),
					'%part_number%' => __( 'Part Number', 'pressbooks' ),
					'%part_title%' => __( 'Part Title', 'pressbooks' ),
					'%blank%' => __( 'Blank', 'pressbooks' ),
					'' => __( 'Custom&hellip;', 'pressbooks' ),
					'label_for' => 'running_content_part_right',
				]
			);

			add_settings_field(
				'running_content_chapter_left',
				__( 'Chapter Left Page Running Content', 'pressbooks' ),
				[ $this, 'renderRunningContentChapterLeftField' ],
				$_page,
				$_section,
				[
					'%book_title%' => __( 'Book Title', 'pressbooks' ),
					'%book_subtitle%' => __( 'Book Subtitle', 'pressbooks' ),
					'%book_author%' => __( 'Book Author', 'pressbooks' ),
					'%part_number%' => __( 'Part Number', 'pressbooks' ),
					'%part_title%' => __( 'Part Title', 'pressbooks' ),
					'%section_title%' => __( 'Chapter Title', 'pressbooks' ),
					'%section_author%' => __( 'Chapter Author', 'pressbooks' ),
					'%section_subtitle%' => __( 'Chapter Subtitle', 'pressbooks' ),
					'%blank%' => __( 'Blank', 'pressbooks' ),
					'' => __( 'Custom&hellip;', 'pressbooks' ),
					'label_for' => 'running_content_chapter_left',
				]
			);

			add_settings_field(
				'running_content_chapter_right',
				__( 'Chapter Right Page Running Content', 'pressbooks' ),
				[ $this, 'renderRunningContentChapterRightField' ],
				$_page,
				$_section,
				[
					'%book_title%' => __( 'Book Title', 'pressbooks' ),
					'%book_subtitle%' => __( 'Book Subtitle', 'pressbooks' ),
					'%book_author%' => __( 'Book Author', 'pressbooks' ),
					'%part_number%' => __( 'Part Number', 'pressbooks' ),
					'%part_title%' => __( 'Part Title', 'pressbooks' ),
					'%section_title%' => __( 'Chapter Title', 'pressbooks' ),
					'%section_author%' => __( 'Chapter Author', 'pressbooks' ),
					'%section_subtitle%' => __( 'Chapter Subtitle', 'pressbooks' ),
					'%blank%' => __( 'Blank', 'pressbooks' ),
					'' => __( 'Custom&hellip;', 'pressbooks' ),
					'label_for' => 'running_content_chapter_right',
				]
			);

			add_settings_field(
				'running_content_back_matter_left',
				__( 'Back Matter Left Page Running Content', 'pressbooks' ),
				[ $this, 'renderRunningContentBackMatterLeftField' ],
				$_page,
				$_section,
				[
					'%book_title%' => __( 'Book Title', 'pressbooks' ),
					'%book_subtitle%' => __( 'Book Subtitle', 'pressbooks' ),
					'%book_author%' => __( 'Book Author', 'pressbooks' ),
					'%section_title%' => __( 'Back Matter Title', 'pressbooks' ),
					'%section_author%' => __( 'Back Matter Author', 'pressbooks' ),
					'%section_subtitle%' => __( 'Back Matter Subtitle', 'pressbooks' ),
					'%blank%' => __( 'Blank', 'pressbooks' ),
					'' => __( 'Custom&hellip;', 'pressbooks' ),
					'label_for' => 'running_content_back_matter_left',
				]
			);

			add_settings_field(
				'running_content_back_matter_right',
				__( 'Back Matter Right Page Running Content', 'pressbooks' ),
				[ $this, 'renderRunningContentBackMatterRightField' ],
				$_page,
				$_section,
				[
					'%book_title%' => __( 'Book Title', 'pressbooks' ),
					'%book_subtitle%' => __( 'Book Subtitle', 'pressbooks' ),
					'%book_author%' => __( 'Book Author', 'pressbooks' ),
					'%section_title%' => __( 'Back Matter Title', 'pressbooks' ),
					'%section_author%' => __( 'Back Matter Author', 'pressbooks' ),
					'%section_subtitle%' => __( 'Back Matter Subtitle', 'pressbooks' ),
					'%blank%' => __( 'Blank', 'pressbooks' ),
					'' => __( 'Custom&hellip;', 'pressbooks' ),
					'label_for' => 'running_content_back_matter_right',
				]
			);
		}

		if ( ! $v2_compatible ) {
			add_settings_field(
				'pdf_fontsize',
				__( 'Increase Font Size', 'pressbooks' ),
				[ $this, 'renderFontSizeField' ],
				$_page,
				$_section,
				[
					__( 'Increases font size and line height for greater accessibility', 'pressbooks' ),
				]
			);
		}

		/**
		 * Add custom settings fields.
		 *
		 * @since 3.9.7
		 *
		 * @param string $arg1
		 * @param string $arg2
		 */
		do_action( 'pb_theme_options_pdf_add_settings_fields', $_page, $_section );

		register_setting(
			$_option,
			$_option,
			[ $this, 'sanitize' ]
		);
	}
90064
protected Element createPageElement()
    {
        String pstyle = "";
        PDRectangle layout = getCurrentMediaBox();
        if (layout != null)
        {
            /*System.out.println("x1 " + layout.getLowerLeftX());
            System.out.println("y1 " + layout.getLowerLeftY());
            System.out.println("x2 " + layout.getUpperRightX());
            System.out.println("y2 " + layout.getUpperRightY());
            System.out.println("rot " + pdpage.findRotation());*/
            
            float w = layout.getWidth();
            float h = layout.getHeight();
            final int rot = pdpage.getRotation();
            if (rot == 90 || rot == 270)
            {
                float x = w; w = h; h = x;
            }
            
            pstyle = "width:" + w + UNIT + ";" + "height:" + h + UNIT + ";";
            pstyle += "overflow:hidden;";
        }
        else
            log.warn("No media box found");
        
        Element el = doc.createElement("div");
        el.setAttribute("id", "page_" + (pagecnt++));
        el.setAttribute("class", "page");
        el.setAttribute("style", pstyle);
        return el;
    }
866980
def page(self, number, *args, **kwargs):
        

        page = super().page(number, *args, **kwargs)
        number = int(number) # we know this will work

        # easier access
        num_pages, body, tail, padding, margin = \
            self.num_pages, self.body, self.tail, self.padding, self.margin

        # put active page in middle of main range
        main_range = list(map(int, [
            math.floor(number-body/2.0)+1,  # +1 = shift odd body to right
            math.floor(number+body/2.0)]))
        # adjust bounds
        if main_range[0] < 1:
            main_range = list(map(abs(main_range[0]-1).__add__, main_range))
        if main_range[1] > num_pages:
            main_range = list(map((num_pages-main_range[1]).__add__, main_range))

        # Determine leading and trailing ranges; if possible and appropriate,
        # combine them with the main range, in which case the resulting main
        # block might end up considerable larger than requested. While we
        # can't guarantee the exact size in those cases, we can at least try
        # to come as close as possible: we can reduce the other boundary to
        # max padding, instead of using half the body size, which would
        # otherwise be the case. If the padding is large enough, this will
        # of course have no effect.
        # Example:
        #     total pages=100, page=4, body=5, (default padding=2)
        #     1 2 3 [4] 5 6 ... 99 100
        #     total pages=100, page=4, body=5, padding=1
        #     1 2 3 [4] 5 ... 99 100
        # If it were not for this adjustment, both cases would result in the
        # first output, regardless of the padding value.
        if main_range[0] <= tail+margin:
            leading = []
            main_range = [1, max(body, min(number+padding, main_range[1]))]
            main_range[0] = 1
        else:
            leading = list(range(1, tail+1))
        # basically same for trailing range, but not in ``left_align`` mode
        if self.align_left:
            trailing = []
        else:
            if main_range[1] >= num_pages-(tail+margin)+1:
                trailing = []
                if not leading:
                    # ... but handle the special case of neither leading nor
                    # trailing ranges; otherwise, we would now modify the
                    # main range low bound, which we just set in the previous
                    # section, again.
                    main_range = [1, num_pages]
                else:
                    main_range = [min(num_pages-body+1, max(number-padding, main_range[0])), num_pages]
            else:
                trailing = list(range(num_pages-tail+1, num_pages+1))

        # finally, normalize values that are out of bound; this basically
        # fixes all the things the above code screwed up in the simple case
        # of few enough pages where one range would suffice.
        main_range = [max(main_range[0], 1), min(main_range[1], num_pages)]

        # make the result of our calculations available as custom ranges
        # on the ``Page`` instance.
        page.main_range = list(range(main_range[0], main_range[1]+1))
        page.leading_range = leading
        page.trailing_range = trailing
        page.page_range = reduce(lambda x, y: x+((x and y) and [False])+y,
            [page.leading_range, page.main_range, page.trailing_range])

        page.__class__ = DiggPage
        return page
1340506
protected function addPage()
    {
        try {
            $values = $this->defaultPage;
            $values['TemplateName'] = $this->templateManager->getTemplate()->getTemplateName();

            $result = $this->pageManager
                ->set(null)
                ->save($values)
            ;

            if (! $result) {
                $this->errorMessage = "An error occoured during the saving of the new page";
            }

            return $result;
        } catch (\Exception $ex) {
            $this->errorMessage = "An error occoured during the saving of the new page. The reported error is: " . $ex->getMessage();

            return false;
        }
    }
585283
public void writeEndPage() throws IOException {
		writer.openElement("document");
		writer.textElement("id", Integer.toString(_page.Id));
		writer.textElement("group", "0");
		writer.textElement("timestamp", formatTimestamp(_rev.Timestamp));
		writer.textElement("title", _page.Title.toString());
		writer.textElement("body", _rev.Text);
		writer.closeElement();
		_rev = null;
		_page = null;
	}
246595
function doInitialUpgrade() {
		$_option = $this->getSlug();
		$options = get_option( 'pressbooks_theme_options_' . $_option, $this->defaults );

		// Replace pdf_page_size with pdf_page_width and pdf_page_height
		if ( isset( $options['pdf_page_size'] ) ) {
			switch ( $options['pdf_page_size'] ) {
				case 1:
					$options['pdf_page_width'] = '5.5in';
					$options['pdf_page_height'] = '8.5in';
					break;
				case 2:
					$options['pdf_page_width'] = '6in';
					$options['pdf_page_height'] = '9in';
					break;
				case 3:
					$options['pdf_page_width'] = '8.5in';
					$options['pdf_page_height'] = '11in';
					break;
				case 4:
					$options['pdf_page_width'] = '8.5in';
					$options['pdf_page_height'] = '9.25in';
					break;
				case 5:
					$options['pdf_page_width'] = '5in';
					$options['pdf_page_height'] = '7.75in';
					break;
				case 6:
					$options['pdf_page_width'] = '4.25in';
					$options['pdf_page_height'] = '7in';
					break;
				case 7:
					$options['pdf_page_width'] = '21cm';
					$options['pdf_page_height'] = '29.7cm';
					break;
				case 8:
					$options['pdf_page_width'] = '14.8cm';
					$options['pdf_page_height'] = '21cm';
					break;
				case 9:
					$options['pdf_page_width'] = '5in';
					$options['pdf_page_height'] = '8in';
					break;
				default:
					$options['pdf_page_width'] = '5.5in';
					$options['pdf_page_height'] = '8.5in';
			}
			unset( $options['pdf_page_size'] );
		}

		// Substitute human-readable values
		if ( ! isset( $options['pdf_paragraph_separation'] ) || 1 === absint( $options['pdf_paragraph_separation'] ) ) {
			$options['pdf_paragraph_separation'] = 'indent';
		} elseif ( 2 === absint( $options['pdf_paragraph_separation'] ) ) {
			$options['pdf_paragraph_separation'] = 'skiplines';
		}

		if ( ! isset( $options['pdf_blankpages'] ) || 1 === absint( $options['pdf_blankpages'] ) ) {
			$options['pdf_blankpages'] = 'include';
		} elseif ( 2 === absint( $options['pdf_blankpages'] ) ) {
			$options['pdf_blankpages'] = 'remove';
		}

		if ( ! isset( $options['pdf_footnotes_style'] ) || 1 === absint( $options['pdf_footnotes_style'] ) ) {
			$options['pdf_footnotes_style'] = 'footnotes';
		} elseif ( 2 === absint( $options['pdf_footnotes_style'] ) ) {
			$options['pdf_footnotes_style'] = 'endnotes';
		}

		// Add missing defaults.
		foreach ( $this->defaults as $key => $value ) {
			if ( ! isset( $options[ $key ] ) ) {
				$options[ $key ] = $value;
			}
		}

		update_option( 'pressbooks_theme_options_' . $_option, $options );
	}
1296244
def add_pdf(self, post_data):
        '''
        
        '''

        img_entity = self.request.files['file'][0]
        img_desc = post_data['desc']
        filename = img_entity["filename"]

        if filename and allowed_file_pdf(filename):
            pass
        else:
            return False

        _, hou = os.path.splitext(filename)
        signature = str(uuid.uuid1())
        outfilename = '{0}{1}'.format(signature, hou)
        outpath = 'static/upload/{0}'.format(signature[:2])
        if os.path.exists(outpath):
            pass
        else:
            os.makedirs(outpath)
        with open(os.path.join(outpath, outfilename), "wb") as fout:
            fout.write(img_entity["body"])

        sig_save = os.path.join(signature[:2], signature)
        path_save = os.path.join(signature[:2], outfilename)
        create_pdf = MEntity.create_entity(signature, path_save, img_desc,
                                           kind=post_data['kind'] if 'kind' in post_data else '2')
        if self.entity_ajax == False:
            self.redirect('/entity/{0}{1}'.format(sig_save, hou.lower()))
        else:
            if create_pdf:
                output = {'path_save': path_save}
            else:
                output = {'path_save': ''}
            return json.dump(output, self)
1109655
def upload_pdf(self, pdf):
        
        return self._post(
            'platform/setpdf',
            files={
                'pdf': pdf,
            },
            result_processor=lambda x: x['s_media_id'],
        )