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

📄 mainunit.cpp

📁 生成PDF文档的控件
💻 CPP
字号:
//---------------------------------------------------------------------------

#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)
{
}

__fastcall TForm1::ShowFontGroup( AnsiString FontGroup, int Position )
{
    VPDF->CurrentPage->SetFont( FontGroup, TFontStyles(), 14, 0, false );               // Set font
    VPDF->CurrentPage->PrintText( Position, 50, 0, FontGroup );                  // Show font name
    VPDF->CurrentPage->SetFont( FontGroup, TFontStyles() << fsBold, 14, 0, false);      // Set font with Bold style
    VPDF->CurrentPage->PrintText( Position, 70, 0, FontGroup + "-Bold" );        // Show font name
    VPDF->CurrentPage->SetFont( FontGroup, TFontStyles() << fsItalic, 14, 0, false);    // Set font with Italic style
    VPDF->CurrentPage->PrintText( Position, 90, 0, FontGroup + "-Italic" );      // Show font name
    VPDF->CurrentPage->SetFont( FontGroup, TFontStyles() << fsBold << fsItalic, 14, 0, false);   // Set font with Bold Italic style
    VPDF->CurrentPage->PrintText( Position, 110, 0, FontGroup + "-Bold-Italic" );  // Show font name
    return 0;
}

__fastcall TForm1::ShowCharset ( TFontCharset FontCharset, int First, int Last, int Y1, int Y2 )
{
       int I;
       AnsiString CSName;
       switch ( FontCharset )
       {
         case ARABIC_CHARSET: CSName = "ARABIC_CHARSET"; break;
         case BALTIC_CHARSET: CSName = "BALTIC_CHARSET"; break;
         case EASTEUROPE_CHARSET: CSName = "EASTEUROPE_CHARSET"; break;
         case GREEK_CHARSET: CSName = "GREEK_CHARSET"; break;
         case RUSSIAN_CHARSET: CSName = "RUSSIAN_CHARSET"; break;
         case TURKISH_CHARSET: CSName = "TURKISH_CHARSET"; break;
       };
       VPDF->CurrentPage->SetFont( "Arial", TFontStyles() << fsBold << fsItalic, 12, 0, false);              // Set charset header font
       VPDF->CurrentPage->PrintText ( 50, Y1, 0, CSName + " example: ");
       VPDF->CurrentPage->SetFont( "Arial", TFontStyles(), 14, FontCharset, false );
       for (I = First; I <= Last; I++)
           VPDF->CurrentPage->PrintText( 30 + (I % 25) * 22, Y2 + int(I / 25) * 17, 0 , AnsiChar(I) ); //Show some characters
       return 0;
}

__fastcall TForm1::ShowTable ( int X, int Y )
{
    VPDF->CurrentPage->Rectangle(X, Y, 300, 50);
    VPDF->CurrentPage->Stroke();
    VPDF->CurrentPage->Rectangle(X, Y + 50, 300, 50);
    VPDF->CurrentPage->Stroke();
    VPDF->CurrentPage->MoveTo( X + 130, Y );
    VPDF->CurrentPage->LineTo( X + 130, Y + 100 );
    VPDF->CurrentPage->Stroke();
    return 0;
}


void __fastcall TForm1::Button1Click(TObject *Sender)
{
    VPDF->AutoLaunch =true;              // PDF file will be shown automatically

    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

    //---------------------------  Standard fonts   --------------------------//
    TFontStyles CurrentFontStyle =  TFontStyles()<< fsBold << fsUnderline;
    VPDF->CurrentPage->SetFont("Arial Unicode MS", CurrentFontStyle, 20, 0, false);  // Show page header
    VPDF->CurrentPage->PrintText( 220, 10, 0, "Standard fonts" );
    OutlineRoot->AddChild( "Standard fonts", 220, 10 );             // Add Outline block linked to 220, 10 in current page

    ShowFontGroup( "Times New Roman", 20 );
    ShowFontGroup( "Arial", 230 );
    ShowFontGroup( "Courier New", 380 );

    //---------------------------  Charsets   --------------------------//
    VPDF->CurrentPage->SetFont("Arial", CurrentFontStyle, 20, 0, false);  // Show next header
    VPDF->CurrentPage->PrintText( 250, 170, 0, "Charsets" );
    TVPDFDocOutlineObject * CurrnetOutline = OutlineRoot->AddChild( "Charsets", 250, 170 );   // Add Outline block linked to 250, 170 in current page
    CurrnetOutline->Opened =true;                                    // The outline will be opened

    CurrnetOutline->AddChild( "ARABIC_CHARSET", 210, 105 );        //  Add Outline linked to 210, 105 in current page
    ShowCharset ( ARABIC_CHARSET, 161, 252, 210, 105 );

    CurrnetOutline->AddChild( "BALTIC_CHARSET", 300, 195 );       //  Add Outline linked to 300, 195 in current page
    ShowCharset ( BALTIC_CHARSET, 166, 255, 300, 195 );

    CurrnetOutline->AddChild( "EASTEUROPE_CHARSET", 390, 285 );   //  Add Outline linked to 390, 285 in current page
    ShowCharset ( EASTEUROPE_CHARSET, 161, 255, 390, 285 );

    CurrnetOutline->AddChild( "GREEK_CHARSET", 390, 285 );       //  Add Outline linked to 480, 285 in current page
    ShowCharset ( GREEK_CHARSET, 161, 254, 480, 375 );

    CurrnetOutline->AddChild( "RUSSIAN_CHARSET", 390, 285 );     //  Add Outline linked to 570, 465 in current page
    ShowCharset ( RUSSIAN_CHARSET, 161, 255, 570, 465 );

    CurrnetOutline->AddChild( "TURKISH_CHARSET", 660, 555 );      //  Add Outline linked to 660, 555 in current page
    ShowCharset ( TURKISH_CHARSET, 161, 255, 660, 555 );

    VPDF->AddPage();
    //---------------------------  Text Scaling   --------------------------//
    VPDF->CurrentPage->SetFont("Arial", CurrentFontStyle, 20, 0, false);  // Show next header
    OutlineRoot->AddChild( "Text Scaling", 200, 20 );
    VPDF->CurrentPage->PrintText( 200, 20, 0, "Horizontal text scaling" );
    ShowTable(170, 60);

    TFontStyles EmptyFontStyle = TFontStyles();
    VPDF->CurrentPage->SetFont("Times New Roman", EmptyFontStyle, 12, 0, false);            // Draw table
    VPDF->CurrentPage->PrintText( 200, 80, 0, " = 100 (default)" );
    VPDF->CurrentPage->PrintText( 230, 125, 0, " = 50" );
    VPDF->CurrentPage->SetFont("Times New Roman", EmptyFontStyle, 24, 0, false);
    VPDF->CurrentPage->PrintText( 350, 80, 0, "Word" );
    VPDF->CurrentPage->SetHorizontalScaling( 50 );                   // Set horizontal scaling
    VPDF->CurrentPage->PrintText( 350, 120, 0, "WordWord" );
    VPDF->CurrentPage->SetHorizontalScaling( 100 );                  // Set horizontal scaling

    //---------------------------  Character Spacing   --------------------------//
    VPDF->CurrentPage->SetFont("Arial", CurrentFontStyle, 20, 0, false);  // Show next header
    OutlineRoot->AddChild( "Character Spacing", 200, 180 );
    VPDF->CurrentPage->PrintText( 220, 180, 0, "Character Spacing" );
    ShowTable(170, 220);
    VPDF->CurrentPage->SetFont("Times New Roman", EmptyFontStyle, 12, 0, false);
    VPDF->CurrentPage->PrintText( 200, 240, 0, "=0 (default)" );
    VPDF->CurrentPage->PrintText( 230, 290, 0, "=5" );
    VPDF->CurrentPage->SetFont("Times New Roman", EmptyFontStyle, 24, 0, false);
    VPDF->CurrentPage->PrintText( 320, 230, 0, "Character" );
    VPDF->CurrentPage->SetCharacterSpacing( 5 );                     // Set character spacing
    VPDF->CurrentPage->PrintText( 320, 280, 0, "Character" );
    VPDF->CurrentPage->SetCharacterSpacing( 0 );                     // Set character spacing

    //---------------------------  Word Spacing   --------------------------//
    VPDF->CurrentPage->SetFont("Arial", CurrentFontStyle, 20, 0, false);  // Show next header
    OutlineRoot->AddChild( "Word Spacing", 200, 340 );
    VPDF->CurrentPage->PrintText( 250, 340, 0, "Word Spacing" );
    ShowTable(170, 380);
    VPDF->CurrentPage->SetFont("Times New Roman", EmptyFontStyle, 12, 0, false);
    VPDF->CurrentPage->PrintText( 200, 400, 0, "=0 (default)" );
    VPDF->CurrentPage->PrintText( 230, 450, 0, "=5" );
    VPDF->CurrentPage->SetFont("Times New Roman", EmptyFontStyle, 24, 0, false);
    VPDF->CurrentPage->PrintText( 320, 390, 0, "Word Space" );
    VPDF->CurrentPage->SetWordSpacing( 5 );                          //Set word spacing
    VPDF->CurrentPage->PrintText( 320, 440, 0, "Word Space" );
    VPDF->CurrentPage->SetWordSpacing( 0 );                          //Set word spacing

    //---------------------------  Rendering modes   --------------------------//
    VPDF->CurrentPage->SetFont("Arial", CurrentFontStyle, 20, 0, false);  // Show next header
    OutlineRoot->AddChild( "Rendering modes", 200, 540 );
    VPDF->CurrentPage->PrintText( 240, 540, 0, "Rendering modes" );
    VPDF->CurrentPage->Rectangle( 50, 580, 500, 150 );
    VPDF->CurrentPage->Stroke();
    VPDF->CurrentPage->MoveTo( 175, 580 );
    VPDF->CurrentPage->LineTo( 175, 730 );
    VPDF->CurrentPage->Stroke();
    VPDF->CurrentPage->MoveTo( 300, 580 );
    VPDF->CurrentPage->LineTo( 300, 730 );
    VPDF->CurrentPage->Stroke();
    VPDF->CurrentPage->MoveTo( 425, 580 );
    VPDF->CurrentPage->LineTo( 425, 730 );
    VPDF->CurrentPage->Stroke();
    VPDF->CurrentPage->MoveTo( 50, 655 );
    VPDF->CurrentPage->LineTo( 550, 655 );
    VPDF->CurrentPage->Stroke();

    VPDF->CurrentPage->SetFont("Arial", EmptyFontStyle, 12, 0, false);                       // Show table header
    VPDF->CurrentPage->PrintText( 100, 610, 0, "Fill");
    VPDF->CurrentPage->PrintText( 215, 610, 0, "Stroke");
    VPDF->CurrentPage->PrintText( 320, 610, 0, "Fill then Stroke");
    VPDF->CurrentPage->PrintText( 465, 610, 0, "Invisible");

    CurrentFontStyle =  TFontStyles()<< fsBold;
    VPDF->CurrentPage->SetFont("Arial", CurrentFontStyle, 72, 0, false);
    VPDF->CurrentPage->SetRGBStrokeColor ( clRed );                   // Set stroke color
    VPDF->CurrentPage->SetRGBFillColor ( clYellow );                  // Set fill color

    VPDF->CurrentPage->SetTextRenderingMode( trFill );                // Set only fill rendering mode
    VPDF->CurrentPage->PrintText( 80, 650, 0, "W");
    VPDF->CurrentPage->SetTextRenderingMode( trStroke );              // Set only stroke rendering mode
    VPDF->CurrentPage->PrintText( 205, 650, 0, "W");
    VPDF->CurrentPage->SetTextRenderingMode( trFillThenStroke );      // Set fill and stroke rendering mode
    VPDF->CurrentPage->PrintText( 330, 650, 0, "W");
    VPDF->CurrentPage->SetTextRenderingMode( trInvisible );           // Set invisible rendering mode
    VPDF->CurrentPage->PrintText( 465, 650, 0, "W");
    VPDF->CurrentPage->SetTextRenderingMode( trFillThenStroke );      // Set default rendering mode

    VPDF->EndDoc();
}

⌨️ 快捷键说明

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