Problems converting aspx to pdf and sending to browser

Hi,

I cannot seem to find any documentation which instructs how to do the above operation!

I tried the below code but it just sends the raw byte code to the browser.

Dim _url As String = "http://www.testing.com"
Dim
_pdf As Pdf = New Pdf()
Dim _wb As WebClient = New WebClient
Dim myBuffer() As Byte = _wb.DownloadData(_url)
Dim _str As MemoryStream = New MemoryStream(myBuffer)
_pdf.BindHTML(_str)
_pdf.Save("test1.pdf", SaveType.OpenInBrowser, Response)

I'd appreciate any help.

thanks,

Saleek

Hello Saleek,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for considering Aspose.

I have tested the issue using the code snippet that you have shared and in my case the Pdf is being generated. In fact the resultant Pdf is not as exact as input Aspx page, as currently this feature is in Beta version. Our development team is working hard over this issue, but I am afraid we cannot fully support this feature in short time. Sorry for your inconvenience.

For related information on how to convert Aspx file into Pdf please visit Converting Html or Aspx to PDF (Beta version)

Make sure you are using the latest version of Aspose.Pdf. I have generated the Pdf from http://www.msn.com and is in attachment, please take a look.

Ahhh, i did not realise that its not fully supported as yet.

In that case, can you provide me with some sample code showing how to create a table and insert an image into the cell?

Then output to the browser.

BTW the version I have is: 3.7.00

Many thanks.

Also, is it possible to insert an image from a url into a table cell?

thx.

Hello Saleek,

Please try the following code snippet. We would recommend you to use the latest version of Aspose.Pdf 3.8.0.0

[VB.NET]

Dim pdf As Pdf = New Pdf()

'Create a section in the Pdf instance
Dim sec1 As Aspose.Pdf.Section = pdf.Sections.Add()

'Create a Table object
Dim pdfCurrentTable As Aspose.Pdf.Table = New Aspose.Pdf.Table(sec1)

Dim row0 As Aspose.Pdf.Row
row0 = pdfCurrentTable.Rows.Add()

Dim cell0, cell1 As Aspose.Pdf.Cell
cell0 = row0.Cells.Add()

'Create an image object
Dim image1 As Aspose.Pdf.Image = New Aspose.Pdf.Image()
'Set the path of image file
image1.ImageInfo.File = "c:\Temp\warning.png"
'Set the type of image using ImageFileType enumeration
image1.ImageInfo.ImageFileType = ImageFileType.Png

row0.Cells(0).Paragraphs.Add(image1)

'Set the Default Border style
pdfCurrentTable.DefaultCellBorder = New BorderInfo(BorderSide.All, 0.1F)

cell1 = row0.Cells.Add()

Dim s2 As String = "Second Cell"
Dim t2 As Text = New Text(s2)
row0.Cells(1).Paragraphs.Add(t2)

sec1.Paragraphs.Add(pdfCurrentTable)
pdf.Save("Test.pdf", Aspose.Pdf.SaveType.OpenInBrowser, Response)

That works great!

Thank you.

Hi,

I have one more question.....

Is it possible to manipulate the size of the image container (not the image itself).

The problem i am facing is this...

I have high resolution images that I want to display in pdfs.

Currently, I resize them using GDI+ in asp.net.

This however reduces the quality substantially, which is not acceptable in my case.

So, I was wondering if i could avoid resizing the image and instead change the size of the container?? Or if there is another way to do this I would love to hear.

Please advise.

thanks,

Saleek

Deat Saleek,

We recommend you use floating box as the image container. Here is the sample code. Please try it. Thanks.

[C#]
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
//Create a floating box to contain the image
Aspose.Pdf.FloatingBox imagebox = new FloatingBox();
//Set the width/height of the floating box(container)
//The same as the image’s width and height
imagebox.BoxWidth = 200;
imagebox.BoxHeight = 300;
//Positioning the box
imagebox.BoxHorizontalPositioning = BoxHorizontalPositioningType.Page;
imagebox.Left = 100;
imagebox.BoxVerticalPositioning = BoxVerticalPositioningType.Page;
imagebox.Top = 250;
//Add the image into the box
Aspose.Pdf.Image img = new Image();
img.ImageInfo.File = “C:/images/1.jpg”;
img.ImageInfo.ImageFileType = ImageFileType.Jpeg;
imagebox.Paragraphs.Add(img);
Aspose.Pdf.Section sec = pdf.Sections.Add();
sec.Paragraphs.Add(imagebox);
pdf.Save(@“E:/temp/test.pdf”);

Best regards.

HI,

Thanks for your response, but I'm afraid this did not work, the BoxHeight value had no affect on the image height even though the BoxWidth did.

Even If I change the BoxHeight to 10 it does not take effect.

thanks.

Hello Saleek,

I have tested the issue and I’m able to reproduce the same problem. I have logged it in our issue tracking system as PDFNET-6134. We will investigate this issue in detail and will keep you updated on the status of a correction. We apologize for your inconvenience.