DocX icon indicating copy to clipboard operation
DocX copied to clipboard

Align Picture in paragraph to the right.

Open pagnax opened this issue 8 years ago • 4 comments

I cannot align picture to the right. The below is the code that take from example project in this DocX project. ` // Get the upper right Paragraph in the layout_table. //Paragraph upper_right_paragraph = layout_table.Rows[0].Cells[1].Paragraph; Paragraph upper_right_paragraph = layout_table.Rows[0].Cells[1].InsertParagraph();

        // Add a template logo image to this document.
        Novacode.Image logo = document.AddImage(assembly.GetManifestResourceStream("Novacode.Resources.logo_template.png"));

        // Insert this template logo into the upper right Paragraph.
        //Picture picture_logo = upper_right_paragraph.InsertPicture(logo.Id, "", "");
        Picture picture_logo = logo.CreatePicture();            
        upper_right_paragraph.InsertPicture(picture_logo);
        upper_right_paragraph.Alignment = Alignment.right;

`

pagnax avatar May 28 '17 16:05 pagnax

Hi, @pagnax ,

Did you found the solution for this?

Thank you, Andrei

dobrinsky avatar Aug 10 '18 13:08 dobrinsky

Hi,

Just to make sure, you want to insert an image in a cell of a table and align it to the right of that cell ? Will there be any text in the paragraph containing the image ?

Thank you.

XceedBoucherS avatar Nov 05 '18 21:11 XceedBoucherS

Bump???

This is still broken.

      var h = document.Headers.Odd.InsertParagraph();

      h.Alignment = Alignment.right;
      h.InsertPicture(img.CreatePicture(30, 30));

Above code does not produce header paragraph with picture aligned to right!

martinrotter avatar Jan 29 '24 15:01 martinrotter

Hi,

this issue is now fixed. The fix will be in the next release. In the meantime, if you have access to code, you can go in file : Xceed.Document.NET/Src/Paragraph.cs, In method : InsertPicture( Picture p, int index = 0 ) and replace

Xml.AddFirst( p.Xml );

// Extract the picture back out of the DOM. p_xml = ( XElement )Xml.FirstNode;

with:

var pPr = this.Xml.Element( XName.Get( "pPr", Document.w.NamespaceName ) ); if( pPr != null ) { pPr.AddAfterSelf( p.Xml ); p_xml = (XElement)pPr.NextNode; } else { this.Xml.AddFirst( p.Xml ); p_xml = (XElement)this.Xml.FirstNode; }

Thank you

XceedBoucherS avatar Jan 30 '24 13:01 XceedBoucherS