Results 1 to 5 of 5

Thread: PDF Page Cut Off

  1. #1
    Join Date
    Nov 2012
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default PDF Page Cut Off

    i created a pdf with QtextDocument. I have a table in the pdf but the bottom of the page cuts the text instead of printing on a new page(for example my table has 300 rows, page 1 shows 1-50,page 2 shows 100-50 and so on. is there anyway to prevent the overflow.
    this is the standered pdf :


    Qt Code:
    1. 1.
    2. // QPrinter *printer=new QPrinter(QPrinter::HighResolution);
    3.  
    4. 2.
    5. // printer->setPaperSize(QPrinter::A4);
    6.  
    7. 3.
    8. // printer->setOutputFormat(QPrinter::PdfFormat);
    9.  
    10. 4.
    11. // printer->setOrientation(QPrinter::Portrait);
    12.  
    13. 5.
    14. // printer->setFullPage(true);
    15.  
    16. 6.
    17. // printer->setOutputFileName(fileName);
    18.  
    19.  
    20.  
    21. //and this is the table
    22.  
    23.  
    24. 1.
    25. // Print Table
    26.  
    27. 2.
    28. QTableWidget *table=new QTableWidget();
    29.  
    30. 3.
    31. m_mainApp->m_table->SetTableWidget(table);
    32.  
    33. 4.
    34. table->setGeometry(0,0,printer.pageRect().width(),printer.pageRect().height());
    35.  
    36. 5.
    37. table->setAutoScroll(false);
    38.  
    39. 6.
    40. m_mainApp->m_table->InitTablePrint(index,printer.pageRect().width());
    41.  
    42. 7.
    43. int nbPage=m_mainApp->m_table->GetNbPrintPage(index,printer.pageRect().height());
    44.  
    45. 8.
    46. for(int page=0;page<nbPage;page++)
    47.  
    48. 9.
    49. {
    50.  
    51. 10.
    52. m_mainApp->m_table->currentIndex=-1;
    53.  
    54. 11.
    55. m_mainApp->m_table->InitTablePrint(index,printer.pageRect().width());
    56.  
    57. 12.
    58. m_mainApp->m_table->FillTablePrint(index,printer.pageRect().height(),page);
    59.  
    60. 13.
    61. painter.save();
    62.  
    63. 14.
    64. QTextDocument *editor=QTableWidget2QTextDocument(table);
    65.  
    66. 15.
    67. painter.scale(printer.resolution()/(screenResolution*1.5f), printer.resolution()/(screenResolution*1.5f));
    68.  
    69. 16.
    70. editor->drawContents(&painter);
    71.  
    72. 17.
    73. painter.restore();
    74.  
    75. 18.
    76. printer.newPage();
    77.  
    78. 19.
    79. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: PDF Page Cut Off

    you have to figure out how many rows to print on each page and draw 'separate' tables
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Nov 2012
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: PDF Page Cut Off

    1. how would i draw the seperators sorry im just starting so coding is weak.
    2. what if i cant draw separate tables

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: PDF Page Cut Off

    use a table that will fit on a page and pass data to it
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Nov 2012
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: PDF Page Cut Off

    so i didnt set this code up it was given to me and the person who gave it to me isnt able to be around to help here is what i got so far.


    this function prints and painter on a pdf, it prints a text document table and renders a graph
    Qt Code:
    1. int index=ui->m_tableWidgetLogger->currentRow();
    2. if(index<0)
    3. return;
    4. QPrinter screenPrinter(QPrinter::ScreenResolution);
    5. int screenResolution = screenPrinter.resolution();
    6. QPrinter printer(QPrinter::HighResolution);
    7. printer.setOrientation(QPrinter::Portrait);
    8. printer.setPaperSize(QPrinter::A4);
    9. printer.setOutputFormat(QPrinter::PdfFormat);
    10. printer.setOutputFileName(fileName);
    11.  
    12. QPainter painter;
    13. painter.begin(&printer);
    14.  
    15. QPen pen(Qt::black, 2, Qt::SolidLine);
    16. painter.setPen(pen);
    17. painter.drawRoundRect(0,0,7400,1050,25,25);
    18. // QPen pen(Qt::black, 20, Qt::SolidLine);
    19. // painter.setPen(pen);
    20. // QLineF line(10,10,15000,10);
    21. // painter.drawLine(line);
    22. painter.scale(0.75f,0.75f);
    23. // painter.setFont(QFont("Helvetica",24,QFont::Bold));
    24. // QRect rect(0,0,painter.viewport().width(),painter.fontMetrics().height());
    25. // painter.drawText(rect,"report",QTextOption(Qt::AlignCenter));
    26.  
    27. // Print Summary
    28.  
    29. QTableWidget *summaryTab=new QTableWidget();
    30.  
    31. m_mainApp->m_table->SetTableWidget(summaryTab);
    32.  
    33. summaryTab->setGeometry(6,8,printer.pageRect().width(),printer.pageRect().height());
    34. summaryTab->setAutoScroll(false);
    35.  
    36. m_mainApp->m_table->InitTableSummary(summaryTab);
    37. m_mainApp->m_table->FillTableSummary(summaryTab,index);
    38. summaryTab->setAlternatingRowColors(true);
    39. summaryTab->setFrameShape(QFrame::NoFrame);
    40.  
    41.  
    42.  
    43. painter.save();
    44.  
    45. QTextDocument *editor = QTableWidget2QTextBrowser(summaryTab);
    46.  
    47. painter.scale(printer.resolution()/(screenResolution*2.5f),printer.resolution()/screenResolution*.5f);
    48. editor->drawContents(&painter);
    49. painter.restore();
    50.  
    51. if(m_mainApp->mLoggerList[index].recCurrentAddress)
    52. {
    53.  
    54.  
    55. // Print Graph
    56.  
    57. QwtPlotRenderer renderer;
    58. renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground,false);
    59. renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames,true);
    60. renderer.render(m_plot,&painter,QRect(0,printer.height()/2,printer.width(),printer.height()/2.2));
    61.  
    62.  
    63. printer.newPage();
    64.  
    65.  
    66. // Print Table
    67.  
    68. QTableWidget *table=new QTableWidget();
    69. m_mainApp->m_table->SetTableWidget(table);
    70. table->setGeometry(0,0,printer.pageRect().width(),printer.pageRect().height());
    71. table->setAutoScroll(true);
    72.  
    73. m_mainApp->m_table->InitTablePrint(index,printer.pageRect().width());
    74. int nbPage=m_mainApp->m_table->GetNbPrintPage(index,printer.pageRect().height());
    75.  
    76. for(int page=0;page<nbPage;page++)
    77. {
    78.  
    79. m_mainApp->m_table->currentIndex=-1;
    80. m_mainApp->m_table->InitTablePrint(index,printer.pageRect().width());
    81. m_mainApp->m_table->FillTablePrint(index,printer.pageRect().height(),page);
    82.  
    83. painter.save();
    84. QTextDocument *editor = QTableWidget2QTextBrowser(table);
    85. painter.scale(printer.resolution()/(screenResolution*1.5f),printer.resolution()/screenResolution*.45f);
    86. editor->drawContents(&painter);
    87. painter.restore();
    88. printer.newPage();
    89.  
    90. }
    91. // Print Histogram
    92. renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground,false);
    93. renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames,true);
    94. // renderer.render(m_histogram,&painter,QRect(0,0,printer.width(),printer.height()/2.2));
    95. renderer.render(m_histogram,&painter,QRect(0,printer.height()/2,printer.width(),printer.height()/2.2));
    96. painter.end();
    97. }
    To copy to clipboard, switch view to plain text mode 

    this is the textdocument that desgins the table
    Qt Code:
    1. editor->setDocumentMargin(25);
    2.  
    3. //creates writing format
    4. QTextCharFormat NormalFormat;
    5. NormalFormat.setFont(QFont("Helvetica",24,QFont::Bold));
    6. NormalFormat.setFontWordSpacing(20);
    7. NormalFormat.setTableCellRowSpan(200);
    8.  
    9.  
    10. //create pointer to current cursor location
    11. QTextCursor cursor (editor);
    12. cursor.beginEditBlock();
    13. cursor.insertImage(QImage(":/Pictures/escort.png"));
    14. cursor.insertText("Escort Data Logger Report",NormalFormat);
    15.  
    16. // QTextBlockFormat block = cursor.blockFormat();
    17. // Qt::Alignment vertAlign = block.alignment() & Qt::AlignVertical_Mask;
    18. // Qt::Alignment horzAlign = block.alignment() & Qt::AlignHorizontal_Mask;
    19. // Qt::Alignment combAlign = horzAlign | vertAlign;
    20. // block.setAlignment(combAlign);
    21. // cursor.setBlockFormat(block);
    22.  
    23.  
    24. QTextTableFormat tableFormat;
    25. // tableFormat.setAlignment(Qt::AlignCenter);
    26.  
    27. tableFormat.setBackground(QColor("#ffffff"));
    28. tableFormat.setCellPadding(4);
    29. tableFormat.setCellSpacing(3);
    30. tableFormat.setRightMargin(9000);
    31.  
    32. QTextTable *tab=cursor.insertTable(tabW->rowCount()+1,tabW->columnCount(),tableFormat);
    33. //QTextTable *tab=cursor.insertTable(tabW->setRowCount(200),tabW->setColumnCount(10));
    34.  
    35. QTextFrame *frame=cursor.currentFrame();
    36.  
    37. QTextFrameFormat frameFormat=frame->frameFormat();
    38. frameFormat.setBorder(0);
    39. frameFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Inset);
    40. frame->setFrameFormat(frameFormat);
    41. frameFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto);
    42. cursor.movePosition(QTextCursor::NextBlock);
    43. // frameFormat.setBottomMargin(3);
    44. frameFormat.setLeftMargin(5);
    45.  
    46. QTextCharFormat format_entete_tab;
    47. format_entete_tab.setFontPointSize(15);
    48. format_entete_tab.setFontWeight(QFont::Bold);
    49.  
    50. QTextCharFormat format_cellule;
    51. format_cellule.setFontPointSize(11);
    52.  
    53. for(int i=0;i<tabW->columnCount();i++)
    54. {
    55. QTextTableCell titre = tab->cellAt(0,i);
    56. QTextCursor cellCursor=titre.firstCursorPosition();
    57. cellCursor.insertText(tabW->horizontalHeaderItem(i)->text(),format_entete_tab);
    58. }
    59.  
    60. QTextCursor cellCursor;
    61.  
    62. for(int row=1;row<tab->rows();row++)
    63. {
    64. for(int col=0;col<tab->columns();col++)
    65. {
    66. cell=tab->cellAt(row,col);
    67. cellCursor=cell.firstCursorPosition();
    68.  
    69. }
    70. }
    71.  
    72. cursor.endEditBlock();
    To copy to clipboard, switch view to plain text mode 


    and this is what populates that table. given that the info is stored in a database and then imported onto the table. my issue maxVerticalSize is too large but it's only refrenced here and i cant seem to change the number.
    Qt Code:
    1. int CTable::GetNbPrintPage(int index,int maxVerticalSizes)
    2. {
    3. int nbPage;
    4.  
    5. int currentRowHeight=18;
    6. int nbRowInPage=(maxVerticalSizes-mTab->horizontalHeader()->height())/currentRowHeight;
    7. nbRowInPage*=3;
    8. int nbRec=m_main->mLoggerList[index].recCurrentAddress;
    9. nbPage=nbRec/nbRowInPage;
    10.  
    11. if(nbRec%nbRowInPage)
    12. nbPage++;
    13. return nbPage;
    14. }
    15.  
    16. void CTable::FillTablePrint(int index,int maxVerticalSizes ,int page)
    17. {
    18. QTableWidgetItem *newItem;
    19. QString strDate,strValue,strElapsed;
    20. QDateTime startTime;
    21. QTime elapsedTime;
    22. int nbRec,startRec,col,nbRowInPage;
    23. int currentRowHeight=18;
    24. double data;
    25. int val;
    26.  
    27. if(index==-1)
    28. return;
    29. ///// newItem->setTextAlignment(30);
    30. nbRowInPage=(maxVerticalSizes-mTab->horizontalHeader()->height())/currentRowHeight;
    31. nbRec=m_main->mLoggerList[index].recCurrentAddress;
    32. startRec=nbRowInPage*page*2;
    33.  
    34. if((nbRec-startRec)<(nbRowInPage*2))
    35. nbRowInPage=(nbRec-startRec)/2;
    36. // mTab->resizeRowsToContents();
    37.  
    38. mTab->setRowCount(nbRowInPage);
    39.  
    40.  
    41. QFont font("Courrier",8,8,false);
    42. font.setBold(true);
    43. // mTab->setFont(font);
    44.  
    45. startTime=m_main->mLoggerList[index].recStartTime;
    46.  
    47.  
    48. if(page)
    49. {
    50. startTime=startTime.addSecs(m_main->mLoggerList[index].prgInterval*startRec);
    51. elapsedTime=elapsedTime.addSecs(m_main->mLoggerList[index].prgInterval*startRec);
    52. }
    53. for(int i=0;nbRowInPage && (startRec<nbRec);i++)
    54. {
    55. col=!(i&0x01)?0:6;
    To copy to clipboard, switch view to plain text mode 

    as a test i created a new project and and used setrowcount() and was able to figure that i needed 200 rows per page. i tried to test for how to create page breaks or split it but nothing seems to work. i was also joping to center that table which is also giving issues.

    any help would be great and im sorry i am entry level so im not that quick and coding is not so amazing, iunderstand best by seeing to examples are a huge help
    Last edited by asweetroxxi; 28th November 2012 at 19:58.

Similar Threads

  1. jump from one html page to another html page
    By RENOLD in forum Qt Programming
    Replies: 4
    Last Post: 10th February 2012, 04:41
  2. Replies: 2
    Last Post: 12th December 2011, 21:29
  3. Load a simple Page after the Main Page.
    By mrhevor in forum Qt Quick
    Replies: 1
    Last Post: 27th September 2011, 10:32
  4. How can I support page up/page down on QTextEdit
    By wesley in forum Qt Programming
    Replies: 7
    Last Post: 14th September 2010, 19:18
  5. QTabWidget remove a page at the page's request
    By thomaspu in forum Qt Programming
    Replies: 2
    Last Post: 29th December 2007, 20:45

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.