Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Portuguese
  4. Salvando Arquivos em Pdf (Exemplo)
QtWS25 Last Chance

Salvando Arquivos em Pdf (Exemplo)

Scheduled Pinned Locked Moved Portuguese
9 Posts 5 Posters 5.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    francomartins
    wrote on last edited by
    #1

    @
    QString caminho = getenv("USERPROFILE");
    caminho+="/DESKTOP/TESTE.PDF";
    QPrinter* printer = new QPrinter;
    printer->setOutputFileName(caminho);
    printer->setOutputFormat(QPrinter::PdfFormat);
    printer->setOrientation(QPrinter::Portrait);
    QPainter* painter = new QPainter(printer);
    painter->drawText(30,150,"Alô Mundo do Pdf");
    painter->end();
    QMessageBox::information(this,"Teste Pdf","Arquivo" +caminho+ "gerado com sucesso !!");
    @

    No projeto esta bem maior , mais a base e essa . Quem quiser pode acrescentar algo !!!

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Renatosantos
      wrote on last edited by
      #2

      Bem útil! se eu esquecer já sei onde procurar. :)

      Qt Developer.

      "Imagination is more important than knowledge."
      http://twitter.com/Renatos20

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Arcturus
        wrote on last edited by
        #3

        Pergunta básica:
        Acredito que possa usar esse código para salvar um arquivo texto só alterando a extensão para .txt, certo?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          francomartins
          wrote on last edited by
          #4

          Normalmente Nao uso o QPainter para exportar pra .txt
          Uso o QFile;
          @
          QFile destino;
          destino.setFileName("D:/TESTE.TXT");
          destino.open(QFile::WriteOnly | QFile::Text);
          destino.write(QString("Escrevendo em TXT !!! ").toLatin1());
          destino.close();@

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Arcturus
            wrote on last edited by
            #5

            Valeu

            1 Reply Last reply
            0
            • F Offline
              F Offline
              felipe.c.sousa
              wrote on last edited by
              #6

              Completando a informação do txt, assim seria o modo de leitura:

              @QString fileName = QFileDialog(this, Qt::Widget).getOpenFileName(this,"Abrir Arquivo Txt",getenv("HOME"),"Arquivos Txt(*.txt)");
              QFile arquivo(fileName);
              arquivo.open(QIODevice::ReadOnly);
              QTextStream *texto = new QTextStream(&arquivo);
              QStringList listaLinhasArquivos;
              while(!texto->atEnd()){
              listaLinhasArquivos << texto->readLine();
              }
              arquivo.close();@

              From all, to all.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Renatosantos
                wrote on last edited by
                #7

                Essa é a especialização do felipe.c.sousa :D

                Qt Developer.

                "Imagination is more important than knowledge."
                http://twitter.com/Renatos20

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  MichelSM
                  wrote on last edited by
                  #8

                  Alguém sabe como usar isto no android?
                  tanto o pdf quanto o txt?
                  o pdf parece que não tem como deste jeito né, mas o txt tem?
                  usei este mesmo código mas não consegui achar o arquivo depois, alguém tem alguma dica?

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    MichelSM
                    wrote on last edited by
                    #9

                    Sobre achar era simples de resolver só ajustar o diretório...
                    e o txt funciona perfeitamente, mas pdf não por causa do QPrint
                    que não se tem suporte ainda...
                    mas será que não existe outra maneira? tentei gerar um pdf no computador, e depois abrir ele como txt, copiei o texto e gerei um txt com o mesmo, funciona mas editar ele é o problema, não consegui ver como se poderia fazer isso como txt, se alguém tem uma ideia agradeço

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved