Logo Search packages:      
Sourcecode: codeblocks version File versions  Download package

int wxPdfDocument::ImportPage ( int  pageno )

Imports a page from an external PDF document.

Imports a page from the current external PDF document. As the bounding box of the template the ArtBox of the imported page is used. If the page does not have an explicit ArtBox, the CropBox will be used instead; if there is no explicit CropBox then the MediaBox will be used.

Parameters:
pagenopage number of the page to be imported
Returns:
Index of imported page - for use in UseTemplate(). A value of 0 is returned if the page number is out of range or no source was selected.
See also:
SetSourceFile()

Definition at line 293 of file pdftemplate.cpp.

References wxPdfStream::GetBuffer(), wxPdfParser::GetContent(), wxPdfParser::GetPageArtBox(), wxPdfParser::GetPageResources(), wxPdfParser::GetPdfVersion(), wxPdfTemplate::m_buffer, m_currentParser, m_h, wxPdfTemplate::m_h, m_importVersion, m_k, m_templateId, m_w, wxPdfTemplate::m_w, wxPdfTemplate::m_x, wxPdfTemplate::m_y, wxPdfTemplate::SetParser(), and wxPdfTemplate::SetResources().

{
  int templateId = 0;
  if (m_currentParser != NULL)
  {
    if (pageno > 0 && pageno <= m_currentParser->GetPageCount())
    {
      wxPdfObject* resources = m_currentParser->GetPageResources(pageno-1);
      wxPdfArrayDouble* artBox = m_currentParser->GetPageArtBox(pageno-1);

      m_templateId++;
      wxPdfTemplate* pageTemplate = new wxPdfTemplate(m_templateId);

      wxArrayPtrVoid contents;
      m_currentParser->GetContent(pageno-1, contents);
      size_t j;
      for (j = 0; j < contents.GetCount(); j++)
      {
        wxPdfStream* pageContent = (wxPdfStream*) contents[j];
        wxMemoryOutputStream* os = pageContent->GetBuffer();
        wxMemoryInputStream is(*os);
        pageTemplate->m_buffer.Write(is);
        delete pageContent;
      }

      (*m_templates)[m_templateId] = pageTemplate;
      pageTemplate->SetParser(m_currentParser);
      pageTemplate->SetResources(resources);
      if (artBox != NULL)
      {
        double x1 = (*artBox)[0];
        double x2 = (*artBox)[2];
        double y1 = (*artBox)[1];
        double y2 = (*artBox)[3];
        double swap;
        if (x1 > x2)
        {
          swap = x1;
          x1 = x2;
          x2 = swap;
        }
        if (y1 > y2)
        {
          swap = y1;
          y1 = y2;
          y2 = swap;
        }
        pageTemplate->m_x = x1 / m_k;
        pageTemplate->m_y = y1 / m_k;
        pageTemplate->m_w = (x2 - x1) / m_k;
        pageTemplate->m_h = (y2 - y1) / m_k;
        delete artBox;
      }
      else
      {
        pageTemplate->m_x = 0;
        pageTemplate->m_y = 0;
        pageTemplate->m_w = m_w;
        pageTemplate->m_h = m_h;
      }
      if (m_importVersion < m_currentParser->GetPdfVersion())
      {
        m_importVersion = m_currentParser->GetPdfVersion();
      }

      templateId = m_templateId; 
    }
  }
  return templateId;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index