- Home
- Forum
- Xamarin.Forms
- Pdf Scale
Pdf Scale
Hi!
Can you help me please?
use PDF in this way:
public async Task SharePDFAsync(MemoryStream stream, string name, float width, float heigth)
{
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
doc.PageSettings.Width = width;
doc.PageSettings.Height = heigth;
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load the image from the stream
PdfBitmap image = new PdfBitmap(stream);
//Draw the image
graphics.DrawImage(image, 0, 0);
MemoryStream ms = new MemoryStream();
doc.Save(ms);
//Close the document.
doc.Close(true);
string filePath = await SaveAsync(ms, "pdf", name);
await Show("test", "test", filePath);
}
My question:
A jpeg file arrives as stream, with set size. I want to scale the PDF file to A4 and A3. The problem is that when I scale the PdfDocument the jpeg image saved in pdf comes out cut, does not reduce.
Is it possible to do what I want?
thankful
SIGN IN To post a reply.
4 Replies
JD
José Donizete de Oliveira Júnior
November 24, 2018 10:47 AM UTC
Hi!
I got what I wanted this way:
Syncfusion.Drawing.SizeF size = PdfPageSize.A3;
//Draw the image
graphics.DrawImage(image, 0, 0, size.Height, size.Width);
Let me know if it's the best method.
Thanks
KC
Karthikeyan Chandrasekar
Syncfusion Team
November 26, 2018 06:33 AM UTC
Hi José,
The code snippet you have provided is the preferred solution to draw the image in specific size. To maintain the aspect ratio of the image, you have to recalculate the width and height before drawing it. Let me know if you need any further assistance in this.
Regards,
Karthikeyan
JD
José Donizete de Oliveira Júnior
November 26, 2018 11:11 AM UTC
Hi!
Thanks for listening.
Only that.
KC
Karthikeyan Chandrasekar
Syncfusion Team
November 26, 2018 11:39 AM UTC
You are welcome.
SIGN IN To post a reply.
- 4 Replies
- 2 Participants
-
JD José Donizete de Oliveira Júnior
- Nov 23, 2018 04:25 PM UTC
- Nov 26, 2018 11:39 AM UTC