Monzon Soft provides a PDF SDK that will make your application capable of saving PDF files in 15 minutes
|
MzPDF Toolkit Delphi Tutorial:
Introduction: This tutorial will show you how to integrate Mozon MzPDF toolkit in your own application in less than 15 minutes. After that you will have your application PDF-enabled.
This Delphi tutorial will explain how to generate a PDF file with 5X5 cm rectangle using “Map Mode” technique.
Steps:
1. Open Delphi 7.
2. Create new project.
3. Add in USES section MzDllUnit and ShellApi.
4. Add a button on the form and double-click it. This will take you to the TForm1.Button1Click() function.
5. Add the following variables to the VAR section for this function
pdfFilename :string; hPdfDocument : MZDOCHANDLE; PageInfo : MZPAGEINFO; rcPage : TRect; nRet : integer; rectText : string; TextFont : TFont; nSaveDC : integer;
6. After Begin statement add the following
// Choose the file name pdfFilename :='c:\generatedPDFFile.pdf';
// Now create the font you want to use TextFont := TFont.Create(); TextFont.Size := Round(0.5*100 ); //0.5 font height TextFont.Style := [fsBold,fsItalic]; TextFont.Name := 'Times New Roman';
// Start the document if ( MZ_ERR_SUCCESS <> mzCreateDocument(@hPdfDocument) ) then begin MessageBox(Handle,'Error','Could not create the document',MB_OK); exit; end;
// Now start the page PageInfo.uStructSize := sizeof(PageInfo);
if (MZ_ERR_SUCCESS = mzStartPage(hPdfDocument,MZ_LAST_PAGE,8.5,11,@PageInfo,0)) then begin
// Now select font nSaveDC := SaveDC(PageInfo.hPageDC); SelectObject(PageInfo.hPageDC,TextFont.Handle);
// Now Set the Map Mode each logical unit equal 1 CM
// Set map mode to be 0.01 CM SetMapMode(PageInfo.hPageDC,MM_ANISOTROPIC);
// Map 0.01, for example if you need map 0.1 then change 100 to 10 SetWindowExtEx(PageInfo.hPageDC,100,100,nil); SetViewportExtEx(PageInfo.hPageDC,Round(PageInfo.xDPI / 2.5),Round(PageInfo.yDPI / 2.5),nil);
// Draw 1 CM rectangle, start on 5 CM rcPage.Left := 1 * 100; // Since map 0.01, start 1 CM from left rcPage.Top := 1 * 100; // Start after 1 CM from top rcPage.Right := rcPage.left + 5 * 100; // 5 CM width rcPage.Bottom := rcPage.top + 5 * 100; // 5 CM height
Rectangle( PageInfo.hPageDC, rcPage.left, rcPage.top, rcPage.right, rcPage.bottom );
// Now draw text inside rectangle. rectText := Char(13) + 'This demo displays 5 Centimeters rectangle' + Char(13) + 'By Mozon Soft'; DrawText(PageInfo.hPageDC, PChar(rectText), Length(rectText), rcPage, DT_BOTTOM or DT_CENTER or DT_WORDBREAK or DT_EXPANDTABS );
// Now Restore the PDF DC and close the page RestoreDC( PageInfo.hPageDC, nSaveDC );
// Close current page mzEndCurrentPage( hPdfDocument ); end;
// Now close the document mzCloseDocument ( hPdfDocument );
// finally generate the PDF file. nRet := mzGeneratePDF( hPdfDocument, PChar(pdfFileName),nil,nil,nil);
if (nRet <> MZ_ERR_SUCCESS ) then begin if(nRet <> MZ_ERR_USER_ABORT) then MessageBox(Handle,'Error Generate PDF file','Report Demo',MB_OK); end;
// delete document handle to free memory mzDeleteDocument( hPdfDocument );
// Now if you want, you can load the file ShellExecute( Handle, 'open', PChar(pdfFileName), nil, nil, SW_SHOW );
7. Before you run you need to go to project|options then to directories\conditionals tab and fill the following
Output directory = ..\..\..\bin\api\win32 where mzpdflib.dll and mzpdfKrn.dll are exist.
Search path = ..\..\..\include\delphi where MzDllUnit.pas is exist
8. Run the project and click on the button and then you will get the result. Download MzPDF Toolkit:The MzPDF toolkit (Evaluation version) can be downloaded from the downloads page. Order MzPDF Toolkit: To order MzPDF toolkit, go to the order page. Contact Us:If you have any notes or questions please drop us a line and we will be glad to help. |
|||||||||||||||||||||||||||||||||
PDF SDK to generate PDF files quickly and easily |
Home . PDF SDK . Contact Us . About Us Copyright © 2011 - Mozon Software |