diff --git a/components/powerpdf/LazarusExamples/ConsoleProgramDemo/BatchPdf.lpi b/components/powerpdf/LazarusExamples/ConsoleProgramDemo/BatchPdf.lpi new file mode 100644 index 000000000..7937198f8 --- /dev/null +++ b/components/powerpdf/LazarusExamples/ConsoleProgramDemo/BatchPdf.lpi @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + <UseAppBundle Value="False"/> + <ResourceType Value="res"/> + </General> + <BuildModes Count="1"> + <Item1 Name="Default" Default="True"/> + </BuildModes> + <PublishOptions> + <Version Value="2"/> + </PublishOptions> + <RunParams> + <local> + <FormatVersion Value="1"/> + <CommandLineParams Value="salida.pdf"/> + </local> + </RunParams> + <RequiredPackages Count="1"> + <Item1> + <PackageName Value="pack_powerpdf"/> + </Item1> + </RequiredPackages> + <Units Count="1"> + <Unit0> + <Filename Value="BatchPdf.lpr"/> + <IsPartOfProject Value="True"/> + </Unit0> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="11"/> + <PathDelim Value="\"/> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + </SearchPaths> + <Parsing> + <SyntaxOptions> + <SyntaxMode Value="Delphi"/> + </SyntaxOptions> + </Parsing> + </CompilerOptions> + <Debugging> + <Exceptions Count="3"> + <Item1> + <Name Value="EAbort"/> + </Item1> + <Item2> + <Name Value="ECodetoolError"/> + </Item2> + <Item3> + <Name Value="EFOpenError"/> + </Item3> + </Exceptions> + </Debugging> +</CONFIG> diff --git a/components/powerpdf/LazarusExamples/ConsoleProgramDemo/BatchPdf.lpr b/components/powerpdf/LazarusExamples/ConsoleProgramDemo/BatchPdf.lpr new file mode 100644 index 000000000..2c0f20e83 --- /dev/null +++ b/components/powerpdf/LazarusExamples/ConsoleProgramDemo/BatchPdf.lpr @@ -0,0 +1,280 @@ +{* + * + * BatchPdf.dpr + * + * To run this program, open command-prompt window and run this program with + * filename parameter + * + * ex) BatchPdf.exe batchpdf.pdf + *} + +program BatchPdf; + +{$MODE ObjFPC}{$H+} +{$modeswitch nestedprocvars} + +{$APPTYPE CONSOLE} +uses + SysUtils, + Classes, + PdfDoc, + PdfTypes, + PdfFonts, + DB, + LCSVUtils, + BufDataset; + +const + CSVFILE = 'customer.csv'; + +var + FDoc: TPdfDoc; + FFileName: string; + FOutFile: TFileStream; + FPage: integer; + FQuery: TBufDataset; + + procedure SetupDataset; + var + Stream: TFileStream; + procedure Newrecord(L: TStringList); + begin + fQuery.AppendRecord([StrToIntDef(L[0], 0), L[1], L[2], L[3], L[4], L[5]]); + end; + begin + FQuery := TBufDataset.Create(nil); + FQuery.FieldDefs.Add('CustNo', ftInteger); + FQuery.FieldDefs.Add('Company', ftString, 70); + FQuery.FieldDefs.Add('State', ftString, 30); + FQuery.FieldDefs.Add('City', ftString, 30); + FQuery.FieldDefs.Add('Addr1', ftString, 70); + FQuery.FieldDefs.Add('Phone', ftString, 15); + FQuery.CreateDataset; + + // csv data generated from http://www.generatedata.com + Stream := TFileStream.Create(CSVFILE, fmOpenRead); + try + LCSVUtils.LoadFromCSVStream(Stream, @Newrecord); + FQuery.First; + finally + Stream.Free; + end; + end; + + procedure TextOut(X, Y: Single; S: string); + begin + with FDoc.Canvas do + begin + BeginText; + MoveTextPoint(X, Y); + ShowText(S); + EndText; + end; + end; + + procedure DrawLine(X1, Y1, X2, Y2, Width: Single); + begin + with FDoc.Canvas do + begin + MoveTo(X1, Y1); + LineTo(X2, Y2); + Stroke; + end; + end; + + procedure WriteHeader; + var + s: string; + w: integer; + begin + // writing the headline of the pages + with FDoc.Canvas do + begin + // setting font + SetFont('Arial-BoldItalic', 16); + + // printing text. + TextOut(90, 770, CSVFILE); + + SetFont('Arial-BoldItalic', 9); + S := FormatDateTime('YYYY/MM/DD', Date); + w := Round(TextWidth(S)); + + // writing header text. + TextOut(530 - w, 770, S); + + SetRGBStrokeColor($00008800); + DrawLine(90, 765, 530, 765, 1.5); + end; + end; + + procedure WriteFooter; + var + w: Single; + s: string; + begin + with FDoc.Canvas do + begin + // Setting font and print text with center align + SetFont('Times-Roman', 8); + + DrawLine(90, 70, 530, 70, 1.5); + + s := 'Page ' + IntToStr(FPage); + w := TextWidth(s); + + TextOut((PageWidth - w) / 2, 55, S); + end; + end; + + procedure WriteRow(YPos: Single); + var + i: integer; + s: string; + begin + // printing the detail lines + with FDoc.Canvas do + begin + if not FQuery.Eof then + begin + TextOut(95, YPos - 15, FQuery.FieldByName('CustNo').AsString); + + s := FQuery.FieldByName('Company').AsString; + + // calculate the number of the charactor which can be contained in the + // width of the frame. + i := MeasureText(s, 130); + TextOut(135, YPos - 15, Copy(s, 1, i)); + + s := FQuery.FieldByName('State').AsString + + FQuery.FieldByName('City').AsString + + FQuery.FieldByName('Addr1').AsString; + + i := MeasureText(s, 175); + TextOut(275, YPos - 15, Copy(s, 1, i)); + + TextOut(455, YPos - 15, FQuery.FieldByName('Phone').AsString); + + FQuery.Next; + end; + end; + end; + + procedure WritePage; + var + i: integer; + XPos, YPos: Single; + begin + with FDoc.Canvas do + begin + // writing the outline + SetLineWidth(1.5); + Rectangle(90, 80, 440, 680); + Stroke; + + // writing the horizontal lines. + YPos := 760; + SetLineWidth(0.75); + for i := 0 to 32 do + begin + YPos := YPos - 20; + MoveTo(90, YPos); + LineTo(530, YPos); + Stroke; + end; + + // writing the header of the text. + SetLineWidth(1); + SetFont('Times-Roman', 10.5); + + XPos := 90; + TextOut(XPos + 5, 745, 'NO.'); + + XPos := 130; + DrawLine(XPos, 760, XPos, 80, 1); + TextOut(XPos + 5, 745, 'Company'); + + XPos := 270; + DrawLine(XPos, 760, XPos, 80, 1); + TextOut(XPos + 5, 745, 'Address'); + + XPos := 450; + DrawLine(XPos, 760, XPos, 80, 1); + TextOut(XPos + 5, 745, 'Phone'); + + XPos := 530; + DrawLine(XPos, 760, XPos, 80, 1); + + // setting the font for the detail lines. + SetFont('Arial', 10.5); + end; + + // printing the detail lines with 20 dot height. + YPos := 740; + for i := 0 to 32 do + begin + WriteRow(YPos); + YPos := YPos - 20; + end; + end; + +begin + if ParamCount > 0 then + FFileName := ParamStr(1) + else + begin + Writeln('Usage: bachpdf <pdf-filename>'); + Halt(2); + end; + + if not FileExists(CSVFILE) then + begin + WriteLn('file ',CSVFILE,' not found in program directory'); + Halt(3); + end; + + // create output-filestream. + FOutFile := TFileStream.Create(FFileName, fmCreate); + + FPage := 1; + + // create TQuery object and set properties. + Writeln('BatchPdf opening database..'); + SetupDataset; + + with FQuery do + try + + // create TPdfDoc object. + Writeln('BatchPdf creating document..'); + FDoc := TPdfDoc.Create; + with FDoc do + try + // create a new document. + NewDoc; + + // printind page from the result of the query. + while not FQuery.Eof do + begin + AddPage; + WriteHeader; + WritePage; + WriteFooter; + inc(FPage); + end; + + // save the pdf-document to the file-stream. + Writeln('BatchPdf saving document..'); + FDoc.SaveToStream(FOutFile); + finally + FDoc.Free; + end; + + Close; + Writeln('BatchPdf end..'); + finally + Free; + FOutFile.Free; + end; + +end. diff --git a/components/powerpdf/LazarusExamples/ConsoleProgramDemo/customer.csv b/components/powerpdf/LazarusExamples/ConsoleProgramDemo/customer.csv new file mode 100644 index 000000000..f2f76e576 --- /dev/null +++ b/components/powerpdf/LazarusExamples/ConsoleProgramDemo/customer.csv @@ -0,0 +1,100 @@ +1,Pede Et Risus Consulting,Wie,Vienna,Ap #508-3195 At Avenue,(932) 612-6518 +2,Pede Malesuada Consulting,Drenthe,Meppel,"P.O. Box 616, 9409 Suspendisse St.",(105) 303-2051 +3,Auctor Incorporated,ON,Hearst,944-3936 Praesent Road,(326) 282-6747 +4,Auctor Odio LLC,QC,Chicoutimi,"P.O. Box 124, 3952 Sit Rd.",(623) 728-1497 +5,Phasellus Dapibus Quam Institute,Berlin,Berlin,"599-5509 Id, Road",(302) 275-3108 +6,Eget Lacus Associates,Queensland,Hervey Bay,Ap #966-4267 Elit Avenue,(657) 147-3061 +7,Eu Neque Pellentesque Ltd,BE,Berlin,9285 Tortor Av.,(553) 851-6429 +8,Magnis LLC,SP,Jundiaí,766-9005 Dictum. Road,(432) 411-6225 +9,Vulputate Posuere Vulputate Associates,AR,Zaragoza,4433 Mauris Rd.,(562) 522-8957 +10,Dis Parturient Industries,Tyrol,Wörgl,Ap #878-7915 Sit St.,(153) 510-0468 +11,Adipiscing Non Associates,SL,Katowice,"1654 Augue, St.",(175) 176-8256 +12,Pede Nonummy Ut Company,ON,Toronto,7516 Condimentum. Rd.,(809) 296-0946 +13,Scelerisque Associates,Metropolitana de Santiago,Providencia,Ap #752-7401 Aliquam Ave,(223) 351-4520 +14,Malesuada Id Erat Inc.,Champagne-Ardenne,Troyes,"P.O. Box 727, 7109 Quis, St.",(859) 728-6562 +15,Elit Sed Associates,LAZ,Labico,Ap #627-356 Nulla. Avenue,(242) 771-1721 +16,Donec Nibh Enim LLC,Antalya,Alanya,802 Placerat Rd.,(130) 562-4215 +17,Sed Company,UP,Gorakhpur,Ap #911-7201 Ullamcorper. Road,(877) 882-4792 +18,Purus Company,NO,Lens,"Ap #379-9596 Magna, St.",(178) 292-4753 +19,Ipsum Dolor Sit Company,San José,Mata de Plátano,"3052 Nunc, Road",(721) 314-8328 +20,Cubilia Associates,Ontario,Essex,"P.O. Box 189, 7017 Enim St.",(530) 997-4789 +21,Orci Sem Limited,E,Norrköping,"P.O. Box 904, 8871 Nec, Road",(927) 856-0234 +22,Semper Cursus Integer LLP,CAM,Sant'Arsenio,"P.O. Box 806, 737 Velit Av.",(148) 598-4515 +23,Eros Limited,Worcestershire,Halesowen,Ap #466-1326 Nulla Avenue,(125) 664-6887 +24,Orci Adipiscing PC,Ankara,Beypazarı,Ap #503-2121 Et Rd.,(922) 118-3062 +25,Pulvinar Arcu Et Company,Zuid Holland,Delft,1918 Cubilia Rd.,(151) 846-0164 +26,Consequat Auctor Institute,L,Dublin,"P.O. Box 355, 6352 Eu Avenue",(666) 646-6854 +27,Ornare Fusce Incorporated,Noord Holland,Hilversum,1211 Lacus. Road,(497) 414-4833 +28,Rhoncus Id Foundation,Saarland,Schwalbach,Ap #572-9437 In Street,(185) 830-7168 +29,Aliquam Erat Volutpat Ltd,NSW,Tamworth,630-159 Dis St.,(508) 666-6097 +30,Tincidunt Dui Augue Corp.,RJ,Bikaner,6646 Pellentesque Avenue,(541) 222-1296 +31,Egestas Industries,QC,Pointe-aux-Trembles,Ap #834-7483 Sagittis. Ave,(929) 966-1678 +32,Cras PC,Northern Territory,Darwin,"P.O. Box 797, 6957 Adipiscing Rd.",(784) 755-0169 +33,Velit Quisque Varius Institute,WA,Gosnells,Ap #262-3475 Metus. Avenue,(107) 893-1395 +34,Rutrum Corporation,Wie,Vienna,"P.O. Box 487, 2759 Venenatis Avenue",(541) 252-3979 +35,Non Nisi Aenean Corp.,Wie,Vienna,4689 Sit Ave,(574) 571-8873 +36,Sapien Cursus In Industries,Ontario,Whitby,Ap #113-7134 Ut Avenue,(564) 826-1266 +37,Cras Eget Nisi Corp.,AN,Arendonk,"521-2463 Purus, Av.",(921) 456-3540 +38,Ut LLC,IA,Cedar Rapids,"P.O. Box 899, 7840 Justo. St.",(374) 905-3251 +39,Aliquam Industries,Leinster,Dublin,Ap #434-4457 Ligula. Street,(378) 388-2768 +40,Ante Bibendum Inc.,NI,Porirua,3389 Ac Rd.,(292) 375-4468 +41,Nunc In At Limited,N.,Laren,602-1426 Arcu. Avenue,(547) 919-2398 +42,Convallis In Foundation,Midi-Pyrénées,Toulouse,"P.O. Box 343, 9555 Nisi Ave",(234) 125-0471 +43,Lacinia Sed Congue LLP,Ist,Istanbul,"P.O. Box 601, 3686 Donec St.",(769) 602-2550 +44,Euismod Industries,NL,Glovertown,919-4124 Egestas. Rd.,(157) 942-9742 +45,Nullam Ut Associates,Oost-Vlaanderen,Steendorp,8648 Sed Rd.,(775) 999-5190 +46,Enim Mi Ltd,Maharastra,Ahmadnagar,663-9903 Erat Rd.,(135) 712-9458 +47,Urna Ut Company,Noord Brabant,Helmond,204-5245 Ut Street,(823) 199-2338 +48,Nunc Id Enim Associates,NI,Cambridge,"P.O. Box 899, 5251 Sed St.",(203) 782-1779 +49,Lobortis Risus In Ltd,Cartago,Carmen,596-3119 Egestas Road,(464) 788-8637 +50,Mauris Molestie Pharetra Ltd,Aydın,Kuşadası,7728 Eu Rd.,(986) 622-0685 +51,Aenean Egestas PC,PV,Bilbo,4999 Fusce Road,(830) 849-9027 +52,Nunc Mauris Incorporated,NI,Tokoroa,"Ap #665-8244 Ante, St.",(518) 603-7206 +53,Pharetra Nam Ac Institute,FVG,Forgaria nel Friuli,"P.O. Box 543, 4271 Tempus Ave",(276) 176-2775 +54,Nunc Sed Libero PC,New South Wales,Wagga Wagga,4089 Aliquam Street,(129) 929-4820 +55,Aliquam Company,BU,Oudergem,Ap #440-8271 Vitae St.,(591) 889-2609 +56,Et PC,Bedfordshire,Leighton Buzzard,Ap #539-5445 Quam Av.,(554) 153-7471 +57,Est Incorporated,Anglesey,Beaumaris,347-2618 Arcu St.,(399) 720-0760 +58,Arcu LLP,Luxemburg,Ethe,Ap #602-4508 Interdum Rd.,(515) 158-5849 +59,Enim Etiam Corp.,MH,Mumbai,Ap #347-3668 Est St.,(744) 327-6738 +60,Tempus Lorem Fringilla Associates,North Island,Wellington,Ap #161-9602 Nec Street,(467) 358-8336 +61,Ac Turpis Egestas Ltd,Connacht,Galway,Ap #776-8305 Molestie. Rd.,(903) 615-2716 +62,Arcu Ac Orci LLC,C,Galway,614-5547 Nunc Ave,(424) 371-4963 +63,Non Cursus Non Corporation,Ohio,Columbus,"Ap #887-5007 Pede, St.",(404) 120-4837 +64,Porttitor Vulputate Corporation,Ontario,Hearst,954-412 Id Rd.,(198) 570-9682 +65,Montes Nascetur Foundation,PIE,Rueglio,898-5723 Consectetuer Rd.,(877) 534-8280 +66,Sit LLC,MO,Jefferson City,494-8078 Netus St.,(769) 439-0548 +67,Sed Pede LLC,Andalucía,Córdoba,Ap #381-3155 Faucibus Ave,(192) 410-1335 +68,Enim Limited,SJ,Desamparados,"P.O. Box 417, 9500 Proin Avenue",(849) 276-3299 +69,In Condimentum Ltd,NSW,Parramatta,"Ap #825-9140 Id, St.",(742) 379-3433 +70,Parturient Montes Limited,FC,Montbéliard,8297 Integer Road,(740) 969-7061 +71,Mauris Blandit Mattis Foundation,PB,Bayeux,406-4021 Egestas Rd.,(351) 448-5059 +72,Molestie Tellus Foundation,KN,Kano,7935 Integer Avenue,(815) 266-2036 +73,Et Corp.,WV,Kortrijk,6939 Ultricies St.,(824) 474-8372 +74,Ligula Aenean Gravida Limited,Jönköpings län,Nässjö,"P.O. Box 262, 8677 Interdum St.",(773) 340-9163 +75,Odio A Purus PC,VI,Nancagua,899-8377 Cursus Rd.,(609) 134-4305 +76,At Lacus Ltd,U,Belfast,"P.O. Box 876, 2528 Leo, Street",(526) 149-2700 +77,Ac Metus PC,SI,Greymouth,"P.O. Box 710, 2374 Integer Road",(660) 403-1841 +78,Quam Elementum Consulting,New South Wales,Grafton,Ap #938-7507 Non Road,(860) 572-1507 +79,Eget Metus Corp.,WV,Zevekote,2047 Cursus Av.,(447) 128-6448 +80,Nonummy Ipsum Non Consulting,O,Borås,3558 Odio. Avenue,(942) 436-4721 +81,Nulla Incorporated,AB,Upplands Väsby,707-268 Quis Street,(127) 664-4298 +82,Donec LLC,NI,Waitakere,"Ap #363-4011 Est, Road",(672) 266-4129 +83,Mi Duis Risus Industries,Vienna,Vienna,"P.O. Box 304, 8203 Tincidunt, Avenue",(830) 556-0931 +84,Curabitur Industries,Catalunya,Sabadell,2645 Tincidunt Ave,(953) 756-7476 +85,Orci Consectetuer Euismod Ltd,Noord Holland,Purmerend,Ap #262-6406 Neque Av.,(254) 764-9122 +86,Amet Massa LLC,AZ,Mesa,2104 Mauris Rd.,(932) 329-4671 +87,Nisi Aenean Eget Inc.,Ontario,Whitchurch-Stouffville,929 Nisi Rd.,(467) 631-2832 +88,Enim Mi Associates,Île-de-France,Champigny-sur-Marne,843-8432 Et Rd.,(203) 341-3904 +89,Nunc Ltd,Iowa,Sioux City,"P.O. Box 172, 3375 Turpis Street",(572) 985-2313 +90,Tempus Eu Consulting,Uttar Pradesh,Rae Bareli,"P.O. Box 599, 8831 Enim Road",(993) 502-6391 +91,Augue LLC,NA,Nairn,"P.O. Box 403, 5362 Enim. Road",(886) 827-7924 +92,Imperdiet Nec Leo Institute,Andalucía,Córdoba,"1294 Id, Street",(809) 679-7858 +93,Nec LLP,Ontario,Bath,Ap #920-1434 Diam. Avenue,(273) 597-7476 +94,Convallis In Cursus Corporation,MP,Kraków,"P.O. Box 786, 6677 Nunc Rd.",(196) 845-2459 +95,Orci Lacus Industries,Provence-Alpes-Côte d'Azur,Antibes,"P.O. Box 149, 4231 Dictum. Avenue",(662) 604-3010 +96,Pede Ac Urna Corp.,Andalucía,Cádiz,305-3663 Integer Av.,(618) 154-5898 +97,Lorem Lorem Luctus Incorporated,HE,Erpion,"P.O. Box 442, 1484 Lobortis St.",(233) 687-2562 +98,Molestie Orci Tincidunt Ltd,CL,Palencia,Ap #413-2822 Nulla Street,(304) 402-2069 +99,Etiam Laoreet Libero Limited,British Columbia,Fraser-Fort George,"858-6829 Consequat, Rd.",(798) 805-1814 +100,Accumsan LLC,Dr,Assen,Ap #358-8213 Velit. Rd.,(357) 206-6714 \ No newline at end of file