簡體   English   中英

頁面未在此范圍內聲明 - qt creator - PoDoFo

[英]page was not declared in this scope - qt creator - PoDoFo

我在SO上發現了類似的問題:錯誤:'Page'未在此范圍內聲明,但由於我不處理頭文件,因此情況不同。

從下面的代碼中可以看出,我正在使用PoDoFo庫嘗試將pdf文件內容打印到屏幕上

#include <iostream>
#include <podofo/podofo.h>
using namespace std;
int main()
{
  //load a new document
  //PoDoFo::PdfMemDocument pdf("myDoc.pdf");

  // this load a doc on my disk

  PoDoFo::PdfMemDocument doc;
  doc.Load("myDoc.pdf");

  //iterate over each page"
  for(int pn = 0; pn < doc.GetPageCount(); ++pn){
    PoDoFo::PdfPage* page = doc.GetPage(pn);
  }

  //
  PoDoFo::PdfContentsTokenizer tok(page);
  const char* token = nullptr;
  PoDoFo::PdfVariant var;
  PoDoFo::EPdfContentsType type;
  while (tok.ReadNext(type, token, var)) {
    if (type == PoDoFo::ePdfContentsType_Keyword) {

    }
  }
  if (var.IsArray()) {
    PoDoFo::PdfArray& a = var.GetArray();
    for (size_t i = 0; i < a.GetSize(); ++i)
      if (a[i].IsString()) { }

  }
}

這是錯誤:

/home/coder/QtProjects/finalProject/main.cpp:19: error: ‘page’ was not declared in this scope
  PoDoFo::PdfContentsTokenizer tok(page);

希望你能幫我解決這個問題。

謝謝!

我懷疑你的花括號不在正確的位置,根據@Scheff的注釋,頁面變量的范圍包含在for循環中,並且你試圖在循環結束后做更多的操作。 我感動}for循環,我想大概應該是在下面的代碼,它應該工作,雖然我也懷疑閉幕}中的while循環,最后if還可能在錯誤的地方。

#include <iostream>
#include <podofo/podofo.h>
using namespace std;
int main()
{
  //load a new document
  //PoDoFo::PdfMemDocument pdf("myDoc.pdf");

  // this load a doc on my disk

  PoDoFo::PdfMemDocument doc;
  doc.Load("myDoc.pdf");
  PoDoFo::PdfPage* page 
  //iterate over each page"
  for(int pn = 0; pn < doc.GetPageCount(); ++pn){
    PoDoFo::PdfPage* page = doc.GetPage(pn);


  //
    PoDoFo::PdfContentsTokenizer tok(page);
    const char* token = nullptr;
    PoDoFo::PdfVariant var;
    PoDoFo::EPdfContentsType type;
    while (tok.ReadNext(type, token, var)) {
      if (type == PoDoFo::ePdfContentsType_Keyword) {

      }
    }
    if (var.IsArray()) {
      PoDoFo::PdfArray& a = var.GetArray();
      for (size_t i = 0; i < a.GetSize(); ++i)
        if (a[i].IsString()) { }

    }
 }  
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM