PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

Can't position TextFrame Where I want
http://forum.pdfsharp.de/viewtopic.php?f=2&t=4021
Page 1 of 1

Author:  IRlyDunno [ Thu Sep 26, 2019 10:46 am ]
Post subject:  Can't position TextFrame Where I want

Hello, I'm trying to get my text frame to a specific spot on the pdf but I can't seem to get ir there...

The textFrame has a QRCode Image, and with the code I've written it only appears of the top|right on the Pdf, not at all where I want it to!

I attached a File to show what I want to achieve.

and the code I use is here:

Code:
    public static void UpdateQRSource(Document doc, string address, float x, float y, float width, float height, float prtsize)
    {
        ZXing.QrCode.QrCodeEncodingOptions options = new ZXing.QrCode.QrCodeEncodingOptions
        {
            DisableECI = true,
            CharacterSet = "UTF-8",
            Width  = Convert.ToInt32(width),
            Height = Convert.ToInt32(height),
        };
           
        var qr = new ZXing.BarcodeWriter();
        qr.Format  = ZXing.BarcodeFormat.QR_CODE;
        qr.Options = options;
           
        Bitmap result = new Bitmap(qr.Write(address));
       
        byte[] image = null;
        using (var ms = new MemoryStream())
        {
            result.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            image = ms.ToArray();
        }
        //img.Save(rndFile, ImageFormat.Png);
     
        var pdfFrame = doc.LastSection.AddTextFrame();
        pdfFrame.Width = width;
        pdfFrame.Height = height;
        //pdfFrame.Left = MigraDoc.DocumentObjectModel.Shapes.ShapePosition.Right;
        //pdfFrame.Top = MigraDoc.DocumentObjectModel.Shapes.ShapePosition.Bottom;
        pdfFrame.RelativeVertical   = MigraRelativeVertical.Page;
        pdfFrame.RelativeHorizontal = MigraRelativeHorizontal.Margin;
        pdfFrame.MarginLeft   = x;
        pdfFrame.MarginBottom = y;
       
        var QRImage = pdfFrame.AddImage("base64:" + Convert.ToBase64String(image));
    }


How can I change the code to achieve what I want?

Attachments:
QRCodePosition.png
QRCodePosition.png [ 33.03 KiB | Viewed 4032 times ]

Author:  Thomas Hoevel [ Thu Sep 26, 2019 12:05 pm ]
Post subject:  Re: Can't position TextFrame Where I want

Hi!
You have to set ".WrapFormat.Style = WrapStyle.Through;" for the TextFrame.
Textframe has many layout settings and I always have to play a bit until it works as wanted.

No need for a TextFrame here as Image has the same positioning options.

See also:
viewtopic.php?p=11162#p11162

Author:  IRlyDunno [ Fri Sep 27, 2019 10:56 am ]
Post subject:  Re: Can't position TextFrame Where I want

thanks for the reply, I managed to make it work after fidgeting with the textframe for a bit.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/