We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Resize Image object

Thread ID:

Created:

Updated:

Platform:

Replies:

91068 Nov 3,2009 02:31 AM Jul 1,2013 04:42 AM ASP.NET Web Forms (Classic) 14
loading
Tags: PDF
Julian Bercovici
Asked On November 3, 2009 02:31 AM

Hie,

I'm converting html to pdf and i would like to know if it's possible to resize the Image to fit the pdf page or to resize the pdf page, after the conversion ?

Thanks.

Sri Subhashini M [Syncfusion]
Replied On November 4, 2009 12:47 AM

Hi Iulian,

Thank you for your interest in Essential PDF.

We can draw the image to fit the PDF page by resizing the PDF page with the help of the Size property of PageSettings class. Kindly refer the below code snippet which demonstrates resizing the PDF document,


//Create a PDF document
PdfDocument doc = new PdfDocument();
doc.PageSettings.Size = new SizeF(500, 500);


Please do find the sample from the below specified location and let me know if this helps,

http://files.syncfusion.com/samples/PDF.Windows/PDF_Win_F91068.zip

Regards,
Suba

Julian Bercovici
Replied On November 4, 2009 02:38 AM

Thanks for the reply, but i know that.
My problem is that when i convert an html to Metafile like so:

m_oHtmlConverter.FromString(HTMLString, ImageType.Metafile, 300, 300, AspectRatio.None)

the image size is 300 x 260 instead of 300 x 300.

I would like to be able to resize the image to the original size, or to resize the pdf page with the image to the original size.

Thanks.

Sri Subhashini M [Syncfusion]
Replied On November 10, 2009 12:49 AM

Hi Iulian.

we can draw resize and draw the image in PDF document by using the DrawImage method. Could you please try to use the below code snippet in your sample and let me know if this helps?


using (HtmlToPdfResult result = html.Convert("http://www.Google.com", ImageType.Metafile, (int)300, (int)300, dimension))
{
if (result.RenderedImage == null)
return;
PdfMetafile mf = new PdfMetafile(result.RenderedImage as Metafile);
mf.Quality = 100;

//Add a page
PdfPage page = doc.Pages.Add();

page.Graphics.DrawImage(mf, new RectangleF(10, 10, 300, 300));
}


Regards,
Suba

Arunkumar M
Replied On November 12, 2009 05:36 AM

How do i add images to a pdfLoadedDocument

PdfLoadedDocument pdfDocMain = new PdfLoadedDocument(loadFile);
PdfPageBase page = pdfDocMain.Pages.Add();
PdfGraphics g = page.Graphics;
PdfImage image = new PdfBitmap(jpgImage);


image.Draw(page , 20, 400);

I am not able to use the pdfPageBase.
Is there any other method to add image or can v convert pdfPageBase top pdfPage.

Thanks
Arun.M

Sri Subhashini M [Syncfusion]
Replied On November 12, 2009 06:50 AM

Hi Arum,

We can draw an image in an existing PDF document by using DrawImage() method. Could you please try the below code snippet to draw an image in an existing PDF document and let me know if this helps?


PdfLoadedDocument ldoc = new PdfLoadedDocument(@"BorderTemplate.pdf");

PdfPage page = ldoc.Pages.Add() as PdfPage;
page.Graphics.DrawImage(PdfImage.FromFile(@"PDF.gif"), new PointF(0,0));


Regards,
Suba

Arunkumar M
Replied On November 12, 2009 07:22 AM

Hi Suba,
I tried to use your code which gave me an error as
Unable to cast object of type 'Syncfusion.Pdf.PdfPage' to type 'Syncfusion.Pdf.PdfLoadedPage'.
When i tried to open the document. Not sure whether i have missed anything.

string path = Server.MapPath("pdf/Sitecheck.pdf");
string jpgImage = Server.MapPath("images/headerBG.jpg");
Response.ContentType = "application/pdf";
PdfLoadedDocument ldoc = new PdfLoadedDocument(path);
PdfPage page = ldoc.Pages.Add() as PdfPage;
page.Graphics.DrawImage(PdfImage.FromFile(jpgImage), new PointF(0, 0));
ldoc.Save("Sample.pdf", Response, HttpReadType.Open);

More over i tried loading the pdfloadedDocument to a PDfdocument and followed the sample code n achieved the o/p. but its again a roundtrip work. So could u guide me as of wat to be followed.

thanks
Arun.M

Julian Bercovici
Replied On November 19, 2009 07:10 AM

Sorry for the delay in response.
I've tested your solution and it works fine,

Thanks.

Divya G [Syncfusion]
Replied On November 23, 2009 11:09 PM

Hi Arun,

Sorry for the delay in response.
I've tested your sample code and I'm unable to reproduce the issue.it works fine.

Regards,
Divya.G

Julian Bercovici
Replied On August 2, 2010 02:49 AM

Hi,
you'r suggestion worked, thanks.

Could you tell me how to split a long image on multiple pages ?
I'm exporting a table from HTML to PDF and i don't know it's length. I would like to preserve the page hight and split the table image on multiple pages.

Thanks.

Angappan G [Syncfusion]
Replied On August 3, 2010 09:29 AM

Hi Julian,

Thank you for your interest in Essential Studio.

We can draw the image of the HTML document in multiple pages by specifying the layout property of PdfLayoutFormat as “paginate”. Please refer the sample for more details.

Sample Link:
http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=HTML_to_PDF1266391884.zip

Please try this and let us know if you have any queries.

Regards,
Angappan.

fcimage
Replied On June 16, 2013 11:27 PM

it should't be so hard for us to resizing image object c# when we are using the image programme. with the help, we can change the height and width or the pixel here. so that we can draw image in pdf.

KarthikeyanC [Syncfusion]
Replied On June 19, 2013 03:19 AM

Hi Fcimage,

Thank you for your update.

 

Thanks,

Karthikeyan.C

 


KarthikeyanC [Syncfusion]
Replied On July 1, 2013 04:42 AM

Hi Arron,

Thank you for your update.

 

Using Syncfusion we can convert Html to Pdf.

During conversion the input file is converted into Metafile and then converted to pdf.

You can control the size of the metafile by setting the value of the Pdf Page.

 

Please refer the below link for the sample.

http://asp.syncfusion.com/Windows/demos/reporting/pdf/Import%20to%20PDF/HTML%20to%20PDF/Sample.aspx

 

 

Thanks,

Karthikeyan.C

 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;