PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Nov 17, 2019 12:38 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 
Offline

Joined: Tue Aug 06, 2019 10:45 am
Posts: 20
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 1964 times ]
Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 26, 2019 12:05 pm 
Offline
PDFsharp Guru
User avatar

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

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


Top
 Profile  
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: No registered users and 5 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