Create a new PDF page and insert some text.

    Notes:
        Function combining Document.newPage() and Page.insertText().
        For parameter details see these methods.
433082
def insertPage(
        doc,
        pno,
        text=None,
        fontsize=11,
        width=595,
        height=842,
        fontname="helv",
        fontfile=None,
        color=None,
    ):
    
    page = doc.newPage(pno=pno, width=width, height=height)
    if not bool(text):
        return 0
    rc = page.insertText(
            (50, 72),
            text,
            fontsize=fontsize,
            fontname=fontname,
            fontfile=fontfile,
            color=color,
         )
    return rc
386752
static function insert_cached_document(CPDF_Adapter $pdf, $id, $new_page = true) {
    $res = self::__query("SELECT font_name FROM page_fonts WHERE id='" . pg_escape_string($id) . "'");

    // Ensure that the fonts needed by the cached document are loaded into
    // the pdf
    while ($row = pg_fetch_assoc($res)) 
      $pdf->get_cpdf()->selectFont($row["font_name"]);
    
    $res = self::__query("SELECT data FROM page_cache WHERE id='" . pg_escape_string($id) . "'");

    if ( $new_page )
      $pdf->new_page();

    $first = true;
    while ($row = pg_fetch_assoc($res)) {

      if ( !$first ) 
        $pdf->new_page();
      else 
        $first = false;        
      
      $page = $pdf->reopen_serialized_object($row["data"]);
      //$pdf->close_object();
      $pdf->add_object($page, "add");

    }
      
  }
128862
public static void main(String args[]) {
        if (args.length != 4) {
            System.err.println("arguments: srcfile destfile1 destfile2 pagenumber");
        }
        else {
            try {
				int pagenumber = Integer.parseInt(args[3]);
                
				// we create a reader for a certain document
				PdfReader reader = new PdfReader(args[0]);
				// we retrieve the total number of pages
				int n = reader.getNumberOfPages();
				System.out.println("There are " + n + " pages in the original file.");
                
				if (pagenumber < 2 || pagenumber > n) {
					throw new DocumentException("You can't split this document at page " + pagenumber + "; there is no such page.");
				}
                
				// step 1: creation of a document-object
				Document document1 = new Document(reader.getPageSizeWithRotation(1));
				Document document2 = new Document(reader.getPageSizeWithRotation(pagenumber));
				// step 2: we create a writer that listens to the document
				PdfWriter writer1 = PdfWriter.getInstance(document1, new FileOutputStream(args[1]));
				PdfWriter writer2 = PdfWriter.getInstance(document2, new FileOutputStream(args[2]));
				// step 3: we open the document
				document1.open();
				PdfContentByte cb1 = writer1.getDirectContent();
				document2.open();
				PdfContentByte cb2 = writer2.getDirectContent();
				PdfImportedPage page;
				int rotation;
				int i = 0;
				// step 4: we add content
				while (i < pagenumber - 1) {
					i++;
					document1.setPageSize(reader.getPageSizeWithRotation(i));
					document1.newPage();
					page = writer1.getImportedPage(reader, i);
					rotation = reader.getPageRotation(i);
					if (rotation == 90 || rotation == 270) {
						cb1.addTemplate(page, 0, -1f, 1f, 0, 0, reader.getPageSizeWithRotation(i).getHeight());
					}
					else {
						cb1.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
					}
				}
				while (i < n) {
					i++;
					document2.setPageSize(reader.getPageSizeWithRotation(i));
					document2.newPage();
					page = writer2.getImportedPage(reader, i);
					rotation = reader.getPageRotation(i);
					if (rotation == 90 || rotation == 270) {
						cb2.addTemplate(page, 0, -1f, 1f, 0, 0, reader.getPageSizeWithRotation(i).getHeight());
					}
					else {
						cb2.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
					}
					System.out.println("Processed page " + i);
				}
				// step 5: we close the document
				document1.close();
				document2.close();
            }
            catch(Exception e) {
                e.printStackTrace();
            }
        }
    }
1214968
def insert(self, document):
        

        doc_id = self._get_doc_id(document)
        data = self._read()
        data[doc_id] = dict(document)
        self._write(data)

        return doc_id
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()
1029958
def pdf_insert(
    dest: str,
    source: str,
    pages: [str] = None,
    index: int = None,
    output: str = None,
):
    
    if output is not None and os.path.isfile(output):
        ans = input(
            "The file '%s' already exists. "
            "Overwrite? Yes/Abort [Y/a]: " % output
        ).lower()
        if ans not in ["y", ""]:
            return

    writer = PdfFileWriter()
    # read pages from file1
    destfile = open(dest, "rb")
    destreader = PdfFileReader(destfile)
    for page in destreader.pages:
        writer.addPage(page)

    # read pages from file2
    srcfile = open(source, "rb")
    srcreader = PdfFileReader(srcfile)

    # if no page numbers are given insert all pages
    index = limit(index - 1, 0, len(destreader.pages))
    if pages is None:
        for i, page in enumerate(srcreader.pages):
            if index is None:
                writer.addPage(page)
            else:
                writer.insertPage(page, index + i)
    else:
        pages = parse_rangearg(pages, len(srcreader.pages))
        for i, pagenr in enumerate(pages):
            page = srcreader.getPage(pagenr)
            if index is None:
                writer.addPage(page)
            else:
                writer.insertPage(page, index + i)

    if output is None:
        # Write into Temporary File first and then overwrite dest file
        ans = input(
            "Overwrite the file '%s'? Yes/Abort [Y/a]: " % dest
        ).lower()
        if ans in ["y", ""]:
            tempfile = NamedTemporaryFile(delete=False)
            writer.write(tempfile)
            tempfile.close()
            move(tempfile.name, dest)
    else:
        with open(output, "wb") as outfile:
            writer.write(outfile)
    destfile.close()
    srcfile.close()
1166954
def outputPDF(self,**kwargs):
        
        import pylatex as pl
        geometry_options = {"tmargin": "2cm", "lmargin": "2cm"}
        doc = pl.Document(geometry_options=geometry_options)
        #Following option avoids float error when to many unplaced figs or tabs
        # (to force placing floats also \clearpage can be used after a section for example)
        doc.append(pl.utils.NoEscape(r'\extrafloats{100}'))
        doc.append(pl.utils.NoEscape(r'\title{'+self.title+'}'))
        if self.addTime:
            from time import localtime, strftime
            doc.append(pl.utils.NoEscape(r'\date{'+strftime("%Y-%m-%d %H:%M:%S", localtime())+r'}'))
        else: doc.append(pl.utils.NoEscape(r'\date{\today}'))
        if self.author: doc.append(pl.utils.NoEscape(r'\author{'+self.author+'}'))
        doc.append(pl.utils.NoEscape(r'\maketitle'))

        # Append introduction
        if self.p:
            with doc.create(pl.Section('Introduction')):
                doc.append(renewliner(self.p))

        # Sections
        c = count(1)
        for section in self.sections:
            section.sectionsPDF(walkTrace=(next(c),),doc=doc)

        # Append conclusion
        if self.conclusion:
            with doc.create(pl.Section('Conclusion')):
                doc.append(renewliner(self.conclusion))

        # Generate pdf
        doc.generate_pdf(self.outfile,**kwargs)
27075
@Override
	public void onEndPage(final PdfWriter writer, final Document document) {
		final int pageN = writer.getPageNumber();
		final String text = pageN + " / ";
		final float len = bf.getWidthPoint(text, 8);
		cb.beginText();
		cb.setFontAndSize(bf, 8);
		final float width = document.getPageSize().getWidth();
		cb.setTextMatrix(width / 2, 30);
		cb.showText(text);
		cb.endText();
		cb.addTemplate(template, width / 2 + len, 30);
	}
436868
function insertComment(documentId, annotationId, comment) {
  let list = document.querySelector(`pdf-annotate-screenreader-comment-list-${annotationId}`);
  let promise;

  if (!list) {
    promise = renderScreenReaderComments(documentId, annotationId, []).then(() => {
      list = document.querySelector(`pdf-annotate-screenreader-comment-list-${annotationId}`);
      return true;
    });
  } else {
    promise = Promise.resolve(true);
  }

  promise.then(() => {
    insertScreenReaderComment(comment);
  });
}
625387
function(pages, callback) {
      // Use eachSeries to make sure that conversion has done page by page
      async.eachSeries(pages, function(page, callbackmap) {
        var inputStream = fs.createReadStream(input);
        var outputFile = options.outputdir + options.outputname + '_' + page + '.' + options.type;

        convertPdf2Img(inputStream, outputFile, parseInt(page), function(error, result) {
          if (error) {
            return callbackmap(error);
          }

          stdout.push(result);
          return callbackmap(error, result);
        });
      }, function(e) {
        if (e) callback(e);

        return callback(null, {
          result: 'success',
          message: stdout
        });
      });
    }
861385
function Text(doc, content) {
    if (!doc) {
        throw new Error('document argument required');
    }

    if (!(doc instanceof bindings.Document)) {
        throw new Error('document argument must be an instance of Document');
    }

    if (!content) {
        throw new Error('content argument required');
    }

    return new bindings.Text(doc, content);
}
195954
def _new_page(self):
        
        self._current_page = Drawing(*self._pagesize)
        if self._bgimage:
            self._current_page.add(self._bgimage)
        self._pages.append(self._current_page)
        self.page_count += 1
        self._position = [1, 0]
439158
public void add(PdfContentByte other) {
        if (other.writer != null && writer != other.writer)
            throw new RuntimeException("Inconsistent writers. Are you mixing two documents?");
        content.append(other.content);
    }
570760
def fill_document(self):
        """"""
        with self.create(Section('A section')):
            self.append('Some regular text and some ')
            self.append(italic('italic text. '))

            with self.create(Subsection('A subsection')):
                self.append('Also some crazy characters: $&#{}')
172340
void add_document(Document doc)
    {
        doc.feature().normalize();
        documents_.add(doc);
        composite_.add_vector(doc.feature());
    }
836200
function insertContent(pageNum) {
        var $page = $pages.eq(pageNum - 1).find('.crocodoc-page-inner');
        var $content = $(util.template(config.template, {
            pageInfo: config.pageInfos[pageNum - 1] || config.defaultInfo
        }));

        $page.append($content);
        // listen for click events on the buttons
        $page.find('.front').on('click', function (event) {
            showPageInfo(pageNum);
            event.stopPropagation();
        });
    }
277750
def combine_pdf_as_bytes(pdfs: List[BytesIO]) -> bytes:
    
    writer = PdfWriter()
    for pdf in pdfs:
        writer.addpages(PdfReader(pdf).pages)
    bio = BytesIO()
    writer.write(bio)
    bio.seek(0)
    output = bio.read()
    bio.close()
    return output