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. Image for the cookie policy date

Resize Image object

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.

14 Replies

SS Sri Subhashini M Syncfusion Team November 4, 2009 05:47 AM UTC

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


JB Julian Bercovici November 4, 2009 07:38 AM UTC

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.


SS Sri Subhashini M Syncfusion Team November 10, 2009 05:49 AM UTC

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


AM Arunkumar M November 12, 2009 10:36 AM UTC

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


SS Sri Subhashini M Syncfusion Team November 12, 2009 11:50 AM UTC

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


AM Arunkumar M November 12, 2009 12:22 PM UTC

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


JB Julian Bercovici November 19, 2009 12:10 PM UTC

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

Thanks.


DG Divya G Syncfusion Team November 24, 2009 04:09 AM UTC

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


JB Julian Bercovici August 2, 2010 06:49 AM UTC

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.


AG Angappan G Syncfusion Team August 3, 2010 01:29 PM UTC

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.


FC fcimage June 17, 2013 03:27 AM UTC

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.


KC Karthikeyan Chandrasekar Syncfusion Team June 19, 2013 07:19 AM UTC

Hi Fcimage,

Thank you for your update.

 

Thanks,

Karthikeyan.C

 



AR arronlee June 26, 2013 08:17 AM UTC

After converting html to pdf, you should treat your pdf files as images.
If you want to resize the image to fit the pdf page or to resize the pdf page, you should work with a PDF processing SDK. AFAIK, you'd better try some professional SDKs whose way of processing is simple and fast, and then resize the height and width of it with its help.
BTW, which kind of pdf converter do you prefer? Do you have any suggestions?
Thanks in advance.



Best regards,
Arron



KC Karthikeyan Chandrasekar Syncfusion Team July 1, 2013 08:42 AM UTC

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

 


Loader.
Live Chat Icon For mobile
Up arrow icon