PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Oct 19, 2020 11:21 pm

All times are UTC

Forum rules

Please read this before posting on this forum: Forum Rules

Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Sep 26, 2019 10:46 am 

Joined: Tue Aug 06, 2019 10:45 am
Posts: 41
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:

    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?

QRCodePosition.png [ 33.03 KiB | Viewed 4103 times ]
Reply with quote  
PostPosted: Thu Sep 26, 2019 12:05 pm 
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3047
Location: Cologne, Germany
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:

Thomas Hoevel
PDFsharp Team

Reply with quote  
PostPosted: Fri Sep 27, 2019 10:56 am 

Joined: Tue Aug 06, 2019 10:45 am
Posts: 41
thanks for the reply, I managed to make it work after fidgeting with the textframe for a bit.

Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC

Who is online

Users browsing this forum: Baidu [Spider] and 20 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group