Recent

Author Topic: fpVectorial Page Orientation  (Read 886 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 539
fpVectorial Page Orientation
« on: August 19, 2024, 02:00:43 pm »
Hello, is it possible to set the page oriantation to horizontal instead of vertical ?
i tried to figure it out but couldn't.

The wiki does say following "Each Page Sequence can have it's own Header and Footer, and it's own Page Setup (size, orientation)"
https://wiki.lazarus.freepascal.org/fpvectorial_-_Text_Document_Support#General


paweld

  • Hero Member
  • *****
  • Posts: 1217
Re: fpVectorial Page Orientation
« Reply #1 on: August 19, 2024, 02:28:54 pm »
if width is greater than heigth then is landscape. modified sample from wiki:
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. Uses
  6.   Classes, SysUtils, fpvectorialpkg, fpvectorial, LCLIntf;
  7.  
  8. Var
  9.   Document: TvVectorialDocument;
  10.   Page: TvTextPageSequence;
  11.   Paragraph: TvParagraph;
  12.   BoldTextStyle: TvStyle;
  13.  
  14.  
  15. Begin
  16.   Document := TvVectorialDocument.Create;
  17.   Try
  18.     //  Adds the defaut Paragraph Styles
  19.     //    StyleTextBody, StyleHeading1,
  20.     //    StyleHeading2 & StyleHeading3
  21.     Document.AddStandardTextDocumentStyles(vfUnknown);
  22.  
  23.     // Add our own Style
  24.     BoldTextStyle := Document.AddStyle();
  25.  
  26.     BoldTextStyle.Kind := vskTextSpan;
  27.     BoldTextStyle.Name := 'Bold';
  28.     BoldTextStyle.Font.Bold := True;
  29.     BoldTextStyle.SetElements := BoldTextStyle.SetElements + [spbfFontBold];
  30.  
  31.     // Create the page A4 portait
  32.     Page := Document.AddTextPageSequence;
  33.     Page.SetPageFormat(vpA4);   //set page to A4 portait - only A4 size is supported
  34.     Page.AddParagraph.AddText('A4 portait');
  35.     Paragraph := Page.AddParagraph;
  36.     Paragraph.Style := Document.StyleTextBody;
  37.  
  38.     // Add Hello World as two text spans within the same paragraph,
  39.     // and make 'World' bold
  40.     Paragraph.AddText('Hello ');
  41.     Paragraph.AddText('World!').Style := BoldTextStyle;
  42.  
  43.     // Create the page A3 landscpe
  44.     Page := Document.AddTextPageSequence;
  45.     Page.Width := 420;   //set page to A3 landscape
  46.     Page.Height := 297;  //if width is greater than heigth then is landscape
  47.     Page.AddParagraph.AddText('A3 Landscape');
  48.     Paragraph := Page.AddParagraph;
  49.     Paragraph.Style := Document.StyleTextBody;
  50.  
  51.     // Add Hello World as two text spans within the same paragraph,
  52.     // and make 'World' bold
  53.     Paragraph.AddText('Witaj ');
  54.     Paragraph.AddText('Świecie!').Style := BoldTextStyle;
  55.  
  56.     Document.WriteToFile('Hello_World.docx', vfDOCX);
  57.     Document.WriteToFile('Hello_World.odt', vfODT);
  58.     OpenDocument('Hello_World.docx');
  59.   Finally
  60.     Document.Free;
  61.   End;
  62. End.
  63.  
  64.  
« Last Edit: August 19, 2024, 02:39:19 pm by paweld »
Best regards / Pozdrawiam
paweld

Weitentaaal

  • Hero Member
  • *****
  • Posts: 539
Re: fpVectorial Page Orientation
« Reply #2 on: August 19, 2024, 03:22:10 pm »
if width is greater than heigth then is landscape. modified sample from wiki:
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. Uses
  6.   Classes, SysUtils, fpvectorialpkg, fpvectorial, LCLIntf;
  7.  
  8. Var
  9.   Document: TvVectorialDocument;
  10.   Page: TvTextPageSequence;
  11.   Paragraph: TvParagraph;
  12.   BoldTextStyle: TvStyle;
  13.  
  14.  
  15. Begin
  16.   Document := TvVectorialDocument.Create;
  17.   Try
  18.     //  Adds the defaut Paragraph Styles
  19.     //    StyleTextBody, StyleHeading1,
  20.     //    StyleHeading2 & StyleHeading3
  21.     Document.AddStandardTextDocumentStyles(vfUnknown);
  22.  
  23.     // Add our own Style
  24.     BoldTextStyle := Document.AddStyle();
  25.  
  26.     BoldTextStyle.Kind := vskTextSpan;
  27.     BoldTextStyle.Name := 'Bold';
  28.     BoldTextStyle.Font.Bold := True;
  29.     BoldTextStyle.SetElements := BoldTextStyle.SetElements + [spbfFontBold];
  30.  
  31.     // Create the page A4 portait
  32.     Page := Document.AddTextPageSequence;
  33.     Page.SetPageFormat(vpA4);   //set page to A4 portait - only A4 size is supported
  34.     Page.AddParagraph.AddText('A4 portait');
  35.     Paragraph := Page.AddParagraph;
  36.     Paragraph.Style := Document.StyleTextBody;
  37.  
  38.     // Add Hello World as two text spans within the same paragraph,
  39.     // and make 'World' bold
  40.     Paragraph.AddText('Hello ');
  41.     Paragraph.AddText('World!').Style := BoldTextStyle;
  42.  
  43.     // Create the page A3 landscpe
  44.     Page := Document.AddTextPageSequence;
  45.     Page.Width := 420;   //set page to A3 landscape
  46.     Page.Height := 297;  //if width is greater than heigth then is landscape
  47.     Page.AddParagraph.AddText('A3 Landscape');
  48.     Paragraph := Page.AddParagraph;
  49.     Paragraph.Style := Document.StyleTextBody;
  50.  
  51.     // Add Hello World as two text spans within the same paragraph,
  52.     // and make 'World' bold
  53.     Paragraph.AddText('Witaj ');
  54.     Paragraph.AddText('Świecie!').Style := BoldTextStyle;
  55.  
  56.     Document.WriteToFile('Hello_World.docx', vfDOCX);
  57.     Document.WriteToFile('Hello_World.odt', vfODT);
  58.     OpenDocument('Hello_World.docx');
  59.   Finally
  60.     Document.Free;
  61.   End;
  62. End.
  63.  
  64.  

thank you !

Weitentaaal

  • Hero Member
  • *****
  • Posts: 539
Re: fpVectorial Page Orientation
« Reply #3 on: August 20, 2024, 09:03:54 am »
Hey,

it works fine with odt Files but i can't get it to work with PDF Files. is it possible to create a Landscape pdf ?

paweld

  • Hero Member
  • *****
  • Posts: 1217
Re: fpVectorial Page Orientation
« Reply #4 on: August 20, 2024, 10:08:03 am »
And why are you creating a PDF using fpVectorial as there is a dedicated fpPDF module for that.
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   Classes, SysUtils, Graphics, fppdf, fpttf, LCLIntf;
  7.  
  8. const
  9.   colarr: Array [1..5] of TColor = (clYellow, clAqua, clLime, clRed, clSkyBlue);
  10. var
  11.   d: TPDFDocument;
  12.   s: TPDFSection;
  13.   p: TPDFPage;
  14.   g: TFPFontCacheList;
  15.   f: TFPFontCacheItem;
  16.   i, j, pw, ph: Integer;
  17.   fname: String;
  18. begin
  19.   fname := 'fclpdf-test.pdf';
  20.   g := TFPFontCacheList.Create;
  21.   g.SearchPath.Add('C:\Windows\Fonts\');
  22.   g.BuildFontCache;
  23.   //doc properties
  24.   d := TPDFDocument.Create(nil);
  25.   d.Options := [poCompressText, poCompressImages, poUseRawJPEG, poNoEmbeddedFonts, poPageOriginAtTop];
  26.   d.Infos.Title := 'sample pdf';
  27.   d.Infos.Author := 'me';
  28.   d.Infos.Producer := 'lazarus';
  29.   d.Infos.ApplicationName := 'test';
  30.   d.Infos.CreationDate := Now;
  31.   d.StartDocument;
  32.   s := d.Sections.AddSection;
  33.   f := g.Find('Courier', False, False);
  34.   if f <> nil then
  35.     d.AddFont(f.FileName, f.FamilyName);
  36.   f := g.Find('Arial', False, False);
  37.   if f <> nil then
  38.     d.AddFont(f.FileName, f.FamilyName);
  39.   f := g.Find('Times New Roman', False, False);
  40.   if f <> nil then
  41.     d.AddFont(f.FileName, f.FamilyName);
  42.   //
  43.   for j := 1 to 5 do
  44.   begin
  45.     p := d.Pages.AddPage;
  46.     case j of
  47.       2: p.PaperType := ptA5;
  48.       3: p.PaperType := ptLetter;
  49.       5: p.PaperType := ptComm10;
  50.       else
  51.         p.PaperType := ptA4;
  52.     end;
  53.     if j mod 2 = 0 then
  54.       p.Orientation := ppoLandscape
  55.     else
  56.       p.Orientation := ppoPortrait;
  57.     p.UnitOfMeasure := uomMillimeters;
  58.     s.AddPage(p);
  59.     pw := trunc(p.Paper.W * 25.4 / 72);
  60.     ph := trunc(p.Paper.H * 25.4 / 72);
  61.     for i := 10 to ph - 10 do
  62.     begin
  63.       if (i mod 10 = 0) or (i = ph - 10) then
  64.       p.DrawLine(10, i, pw - 10, i, 0.1);
  65.     end;
  66.     for i := 10 to pw - 10 do
  67.     begin
  68.       if (i mod 10 = 0) or (i = pw - 10) then
  69.       p.DrawLine(i, 10, i, ph - 10, 0.1);
  70.     end;
  71.     p.SetFont(0, 40);
  72.     p.SetColor(clBlack, false);
  73.     p.WriteText(20, 20, 'Page ' + IntToStr(j));
  74.     p.SetColor(colarr[j], False);
  75.     p.DrawRect(100, 100, 50, 50, 1, True, False);
  76.     if j = 1 then
  77.     begin
  78.       p.SetColor(clMaroon, False);
  79.       p.SetFont(1, 24);
  80.       p.WriteText(10, 50, 'table of contents:');
  81.       for i := 2 to 5 do
  82.       begin
  83.         p.WriteText(10, 50 + (i * 10) - 10, 'Page ' + IntToStr(i));
  84.         {$IF FPC_FULLVERSION>30202}p.AddInternalLink(10, 50 + (i * 10) - 10, 30, 8, i - 1){$ENDIF}; //link to page
  85.       end;
  86.     end
  87.     else
  88.     begin
  89.       p.SetColor(clMaroon, False);
  90.       p.SetFont(1, 24);
  91.       p.WriteText(10, 50, 'goto page 1');
  92.       p.AddInternalLink(10, 50, 30, 8, 0);
  93.     end;
  94.   end;
  95.   d.SaveToFile(fname);
  96.   d.Free;
  97.   OpenDocument(fname);
  98. end.
  99.  
  100.  
Best regards / Pozdrawiam
paweld

 

TinyPortal © 2005-2018