⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainunit.cpp

📁 生成PDF文档的控件
💻 CPP
字号:
//*******************************************************//
//                                                       //
//       This unit is part of the VISPDF VCL library.    //
//       Written by R.Husske - ALL RIGHTS RESERVED.      //
//                                                       //
//       Copyright (C) 2000-2008, www.vispdf.com         //
//                                                       //
//       e-mail: support@vispdf.com                      //
//       http://www.vispdf.com                           //
//                                                       //
//*******************************************************//
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "MainUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "VPDFDoc"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    VPDF->AutoLaunch  =  true;              // PDF file will be shown automatically
    VPDF->NotEmbeddedFonts->Add("Arial");
    VPDF->StandardFontEmulation  =  true;
    VPDF->Compression  =  cmNone;              // Set flate compression
    VPDF->PageLayout  =  plOneColumn;          // One column viewer mode
    VPDF->BeginDoc( true );                    // Create PDF file
    TVPDFDocOutlineObject * OutlineRoot  =  VPDF->OutlineRoot;                          // Get Outlines Root
    TVPDFDocOutlineObject * CurrnetOutline  =  OutlineRoot->AddChild( "Lines", 0, 0 );  // Add Outline block linked to 0, 0 in current page
    CurrnetOutline->Opened  =  true;                                                    // Current outline is opened;
    VPDF->CurrentPage->SetFont("Arial", TFontStyles() << fsBold << fsUnderline, 16, 0, false); // Show page header
    VPDF->CurrentPage->PrintText( 150, 25, 0, "Examples of line dash patterns" );
    VPDF->CurrentPage->SetFont("Arial", TFontStyles(), 12, 0, false);  // Show next header
    VPDF->CurrentPage->SetLineWidth( 3 );
    VPDF->CurrentPage->SetRGBStrokeColor( clBlue );             // Set blue line color
    VPDF->CurrentPage->PrintText( 70, 70, 0, "[ ] 0                                                                          No dash; solid, unbroken lines" );
    DrawLine( 77 );
    char * DashArray = (char *) calloc( 1, 1 );
    //-------------------------  Examples of line dash patterns  -----------------------------------------------//
    CurrnetOutline->AddChild( "Dash patterns", 150, 25 );          // Add Outline block linked to 150, 25 in current page
    DashArray[0]  =  7;
    VPDF->CurrentPage->SetDash( DashArray, 0, 0 );  // Set dash array [7] 0
    VPDF->CurrentPage->PrintText( 70, 90, 0, "[7] 0                                                                         7 units on, 7 units off " );
    DrawLine( 97 );
    DashArray[0]  =  7;
    VPDF->CurrentPage->SetDash( DashArray, 0 , 7);  // Set dash array [7] 7
    VPDF->CurrentPage->PrintText( 70, 110, 0, "[7] 7                                                                         7 off, 7 on, 7 off, 7 on " );
    DrawLine( 117 );
    free(DashArray);

    DashArray = (char *) calloc( 2, 1 );
    DashArray[0]  =  9;
    DashArray[1]  =  7;
    VPDF->CurrentPage->SetDash( DashArray, 1 , 0 );  // Set dash array [9 7] 0
    VPDF->CurrentPage->PrintText( 70, 130, 0, "[9 7] 0                                                                      9 on, 7 off, 9 on, 7 off" );
    DrawLine( 137 );

    DashArray[0]  =  3;
    DashArray[1]  =  5;
    VPDF->CurrentPage->SetDash( DashArray, 1 , 6);  // Set dash array [3 5] 6
    VPDF->CurrentPage->PrintText( 70, 150, 0, "[3 5] 6                                                                      2 off, 3 on, 5 off, 3 on, 5 off" );
    DrawLine( 157 );
    free(DashArray);

    DashArray = (char *) calloc( 6, 1 );
    DashArray[0]  =  10;
    DashArray[1]  =  3;
    DashArray[2]  =  2;
    DashArray[3]  =  3;
    DashArray[4]  =  2;
    DashArray[5]  =  3;
    VPDF->CurrentPage->SetDash( DashArray, 5 , 0);  // Set dash array [10 3 2 3 2 3] 0
    free(DashArray);

    VPDF->CurrentPage->PrintText( 70, 170, 0, "[10 3 2 3 2 3] 0                                                       10 on, 3 off, 2 on, 3 off, 2 on, 3 off" );
    DrawLine( 177 );
    VPDF->CurrentPage->NoDash();  // Set default dash style
    //------------------------------------  Examples of line width -----------------------------------------//
    CurrnetOutline->AddChild( "Width examples", 190, 225 );           // Add Outline block linked to 190, 225 in current page
    VPDF->CurrentPage->SetRGBStrokeColor( clGreen );                   // Set green line color
    VPDF->CurrentPage->SetFont("Arial", TFontStyles() << fsBold << fsUnderline, 16, 0, false);    // Show page header
    VPDF->CurrentPage->PrintText( 190, 225, 0, "Examples of line width" );
    VPDF->CurrentPage->SetFont("Arial", TFontStyles(), 10 , 0, false);
    for (int I = 1; I <= 9; I++)
    {
        VPDF->CurrentPage->PrintText( 250, 239 + I * 25, 0, "Width = " + FloatToStr(I * 0.25));      // Print line width
        VPDF->CurrentPage->SetLineWidth( I * 0.25 );                                               // Set line width
        VPDF->CurrentPage->MoveTo( 60, 250 + I * 25 );
        VPDF->CurrentPage->LineTo( 510, 250 + I * 25 );                                            // Draw line
        VPDF->CurrentPage->Stroke();                                                                 // Stroke line
    }
    //------------------------------------  Examples of curves -----------------------------------------//
    CurrnetOutline->AddChild( "Curves", 210, 500 );                 // Add Outline block linked to 210, 500 in current page
    VPDF->CurrentPage->SetRGBStrokeColor( clRed );                    // Set red line color
    VPDF->CurrentPage->SetFont("Arial", TFontStyles() << fsBold << fsUnderline, 16, 0, false);  // Show page header
    VPDF->CurrentPage->PrintText( 210, 500, 0, "Examples of curves" );
    VPDF->CurrentPage->MoveTo( 80, 800 );
    VPDF->CurrentPage->CurveToC( 50, 620, 150, 570, 270, 700 );      // Draw curve type C
    VPDF->CurrentPage->Stroke();
    VPDF->CurrentPage->MoveTo( 320, 800 );
    VPDF->CurrentPage->CurveToY( 350, 620, 550, 670 );               // Draw curve type Y
    VPDF->CurrentPage->Stroke();
    VPDF->CurrentPage->SetRGBStrokeColor( clBlack );                 // Set black line color

    DashArray = (char *) calloc( 1, 1 );                             // Set braked line type
    DashArray [ 0 ]  =  8;
    VPDF->CurrentPage->SetDash( DashArray, 0 , 0);
    VPDF->CurrentPage->SetLineWidth( 0.5 );
    VPDF->CurrentPage->MoveTo( 350, 620 );
    VPDF->CurrentPage->LineTo( 320, 800 );                            // Draw dotted line
    VPDF->CurrentPage->Stroke();
    VPDF->CurrentPage->MoveTo( 80, 800 );
    VPDF->CurrentPage->LineTo( 50, 620 );                            // Draw dotted line
    VPDF->CurrentPage->Stroke();
    VPDF->CurrentPage->MoveTo( 150, 570 );
    VPDF->CurrentPage->LineTo( 270, 700 );                            // Draw dotted line
    VPDF->CurrentPage->Stroke();
    VPDF->CurrentPage->SetFont("Times New Roman", TFontStyles(), 10, 0, false);                // Set label font
    VPDF->CurrentPage->PrintText( 85, 790,0, "Current point ( 80, 800 )" );
    VPDF->CurrentPage->PrintText( 50, 610,0, "X1 ( 50, 620 )" );
    VPDF->CurrentPage->PrintText( 150, 560,0, "X2 ( 150, 570 )" );
    VPDF->CurrentPage->PrintText( 200, 700,0, "X3 ( 270, 700 )" );
    VPDF->CurrentPage->PrintText( 325, 790,0, "Current point ( 320, 800 )" );
    VPDF->CurrentPage->PrintText( 350, 610,0, "X1 ( 350, 620 )" );
    VPDF->CurrentPage->PrintText( 490, 685,0, "X3 ( 550, 670 )" );
    VPDF->CurrentPage->NoDash();                                       // Set default dash type
    VPDF->AddPage();
    CurrnetOutline  =  OutlineRoot->AddChild( "Rectangles", 0, 0 );        // Add Outline block linked to 0, 0 in current page
    CurrnetOutline->Opened  =  true;                                 // Current outline is opened;
    //------------------------------------  Draw  rectangles -----------------------------------------//
    VPDF->CurrentPage->SetFont("Arial", TFontStyles() << fsBold << fsUnderline, 16, 0, false);  // Set header font
    CurrnetOutline->AddChild( "Rectangles", 230, 25 );              // Add Outline block linked to 230, 25 in current page
    VPDF->CurrentPage->PrintText( 230, 25, 0, "Draw rectangles" );
    for (int I = 0; I<=4; I++)
    {
        VPDF->CurrentPage->SetRGBFillColor(TColor(random(0xFFFFFF)));         // Set rectangle color
        VPDF->CurrentPage->Rectangle( I * 100+50, 60, 95, 130);      // Draw round rectangle
        VPDF->CurrentPage->ClosePathFillAndStroke();                   // Close, fill and stroke rectangle
        VPDF->CurrentPage->SetRGBFillColor(TColor(random(0xFFFFFF)));         // Set rectangle color
        VPDF->CurrentPage->Rectangle( I * 100 + 80, 80, 95, 130);    // Draw round rectangle
        VPDF->CurrentPage->ClosePathFillAndStroke();                   // Close, fill and stroke rectangle
    }
    VPDF->CurrentPage->SetRGBFillColor( clBlack );                   //   Set default fill color
    //------------------------------------  Draw rotated rectangles -----------------------------------------//
    CurrnetOutline->AddChild( "Rotated rectangles", 190, 225 );              // Add Outline block linked to 190, 225 in current page
    VPDF->CurrentPage->PrintText( 190, 225, 0, "Draw rotated rectangles" );
    VPDF->CurrentPage->PrintText( 230, 25, 0, "Draw rectangles" );
    for (int I = 1; I <= 9; I++ )
    {
        VPDF->CurrentPage->SetRGBFillColor(TColor(random(0xFFFFFF)));                     // Set rectangle color
        VPDF->CurrentPage->RectangleRotate( I * 50 + 35, 420, 95, 130, I * 40);  // Draw rectangle
        VPDF->CurrentPage->ClosePathFillAndStroke();                               // Close, fill and stroke rectangle
    }
    VPDF->CurrentPage->SetRGBFillColor( clBlack );                   //   Set default fill color
    //------------------------------------  Draw round rectangles -----------------------------------------//
    CurrnetOutline->AddChild( "Round rectangles", 210, 600 );              // Add Outline block linked to 210, 600 in current page
    VPDF->CurrentPage->PrintText( 210, 600, 0, "Draw round rectangles" );
    for (int I = 0; I <= 4; I++)
    {
        VPDF->CurrentPage->SetRGBFillColor(TColor(random(0xFFFFFF)));                         // Set rectangle color
        VPDF->CurrentPage->RoundRect( I * 100+50, 630, I * 100+145, 770, 20, 20);    // Draw round rectangle
        VPDF->CurrentPage->ClosePathFillAndStroke();                                   // Close, fill and stroke round rectangle
        VPDF->CurrentPage->SetRGBFillColor(TColor(random(0xFFFFFF)));                         // Set rectangle color
        VPDF->CurrentPage->RoundRect( I * 100 + 80, 660, I * 100+175, 800, 20, 20);  // Draw round rectangle
        VPDF->CurrentPage->ClosePathFillAndStroke();                                   // Close, fill and stroke round rectangle
    }
    VPDF->CurrentPage->SetRGBFillColor( clBlack );                      //   Set default rectangle color
    VPDF->AddPage();
    CurrnetOutline  =  OutlineRoot->AddChild( "Circles and ellipses" , 0, 0); // Add Outline block linked to 0, 0 in current page
    CurrnetOutline->Opened  =  true;                                    // Current outline is opened;
    VPDF->CurrentPage->SetFont("Arial", TFontStyles() << fsBold << fsUnderline, 16, 0, false);     // Set font
    //------------------------------------  Draw  circles -----------------------------------------//
    CurrnetOutline->AddChild( "Circles", 270, 20 );              // Add Outline block linked to 270, 600 in current page
    VPDF->CurrentPage->PrintText( 270, 20, 0, "Circles" );
    for (int I = 1; I <= 8; I++)
    {
        VPDF->CurrentPage->SetRGBFillColor(TColor(random(0xFFFFFF)));         // Set circle fill color
        VPDF->CurrentPage->Circle( I * 60 + 25, 150, 80 / I );       // Draw circle
        VPDF->CurrentPage->ClosePathFillAndStroke();                   // Close, fill and stroke circle
        VPDF->CurrentPage->SetRGBFillColor(TColor(random(0xFFFFFF)));         // Set circle fill color
        VPDF->CurrentPage->Circle( I * 60 + 25, 280, I * 10 );       // Draw circle
        VPDF->CurrentPage->ClosePathFillAndStroke();                   // Close, fill and stroke circle
    }
    VPDF->CurrentPage->SetRGBFillColor( clBlack );                   //   Set default rectangle color
    //------------------------------------  Draw  elipses -----------------------------------------//
    CurrnetOutline->AddChild( "Ellipses", 270, 450 );              // Add Outline block linked to 270, 450 in current page
    VPDF->CurrentPage->PrintText( 270, 450, 0, "Ellipses" );
    for (int I = 1; I <= 8; I++ )
    {
        VPDF->CurrentPage->SetRGBFillColor(TColor(random(0xFFFFFF)));                           // Set ellipse fill color
        VPDF->CurrentPage->Ellipse( I * 35, 500 + I * 3, 600 - I * 70, 270 - I * 6 );  // Draw ellipse
        VPDF->CurrentPage->ClosePathFillAndStroke();                                     // Close, fill and stroke ellipse
    }
    VPDF->EndDoc();
}

void __fastcall TForm1::DrawLine(int Y)
{
    VPDF->CurrentPage->MoveTo( 160, Y);
    VPDF->CurrentPage->LineTo( 310, Y);
    VPDF->CurrentPage->Stroke();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -