Forum > FPvectorial
Setting of margins for docx document
(1/1)
dgm:
Hello
I am having problems setting the page margins when creating a docx file with fpvectorial. I am using the following test code and I am using Lazarus 1.0.8.0RC5 on Fedora 20.
var
Document: TvVectorialDocument;
Page: TvTextPageSequence;
Paragraph: TvParagraph;
begin
Document := TvVectorialDocument.Create;
Document.Width := 182;
Document.Height := 257;
Document.AddStandardTextDocumentStyles(vfODT);
Document.StyleTextBody.MarginLeft := 25.4;
Document.StyleTextBody.MarginRight := 25.4;
Document.StyleTextBody.MarginTop := 35;
Document.StyleTextBody.MarginBottom := 26;
Document.StyleTextBody.SetElements := Document.StyleTextBody.SetElements +
[sseMarginLeft, sseMarginRight, sseMarginTop, sseMarginBottom];
Page := Document.AddTextPageSequence();
Paragraph := Page.AddParagraph;
Paragraph.AddText('Test');
Document.WriteToFile('test.docx', vfDOCX);
Document.Free;
When I open the test.docx file in LibreOffice and click on Format/Page the page width and height is correct as set by the program but the margins is incorrect. Is seems that it is the LibreOffice default margins. What am I missing or doing wrong?
Regards
dgm
dgm:
Well since I am getting no help from the forum regarding the fpvectorial margin problem I downloaded the newest version of fpvectorial via svn. I then compiled the fpvtextwritetest2.pas example and the example's margins did not work either.
Then I created a test document in Libreoffice and unzipped the .odt file and I saw that the margins are set in page-layout. Thereafter I searched the fpvectorial code for page-layout and found a "// TODO: Add Page Margins..." comment in the odtvecterialwrite.pas code.
The margins are hard coded for example: fo:margin-top="0.7874in" which is exactly the 20 mm margins I got in Libreoffice when creating an ODT document with fpvectorial.
So clearly the margins are not implemented at this stage.
Then I modified the code after the code as follows:
FAutomaticStyles := FAutomaticStyles +
'<style:page-layout style:name="'+sPageLayoutName+'">'+ LineEnding+
' <style:page-layout-properties '+
' fo:page-width="'+FloatToODTText(dWidth)+'mm"'+
' fo:page-height="'+FloatToODTText(dHeight)+'mm"'+
' style:print-orientation="'+sOrientation+'"'+
' style:num-format="1"'+
' fo:margin-top="'+
FloatToODTText(AData.StyleTextBody.MarginTop)+'mm"'+
' fo:margin-bottom="'+
FloatToODTText(AData.StyleTextBody.MarginBottom)+'mm"'+
' fo:margin-left="'+
FloatToODTText(AData.StyleTextBody.MarginLeft)+'mm"'+
' fo:margin-right="'+
FloatToODTText(AData.StyleTextBody.MarginRight)+'mm"'+
' style:writing-mode="lr-tb" style:footnote-max-height="0in">'+ LineEnding;
It is probably not inline with the ODT specification but now at least the margins work when I set them in the code and writes an ODT document.
wp:
This is certainly better than the hard-coded version, but probably not the most general solution. I don't know whether the ODT specification allows page margins different from the style and whether this is implemented in fpvectorial - but if this were true then your code would ignore the individual page settings.
Anyway: You should post a report in bugtracker so that this issue will not be lost. Hopefully, Felipe, the maintainer of fpvectorial, sees it. Or I can have a look myself, but I don't have the time for it at the moment.
Navigation
[0] Message Index