Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello Everyone,

Greetings!!

im exporting a table that is present in aspx page to pdf(using itextsharp), its working fine but my problem is though it is showing the correct view in print preview but when it is exported to pdf the labels present in the table are scattered. may i know why is this happening??

thanks in advance..!!
Posted
Updated 24-Jul-13 1:37am
v2
Comments
Pheonyx 24-Jul-13 7:37am    
How are you creating the PDF, can you show your code for that aspect of the process?

--
Use the Improve Question facility and the <pre></pre> formatting tags to add the code to your question.
Sarin VT 24-Jul-13 7:44am    
You can map the table as an image.
Then there wont be any problems

Can you add your code for our review?
 
Share this answer
 
As i commented you can first convert the table into image. Then convert that image into a pdf file.

Converting aspx/html page into image

public Bitmap GenerateScreenshot(string url)
{
    // This method gets a screenshot of the webpage
    // rendered at its full size (height and width)
    return GenerateScreenshot(url, -1, -1);
}

public Bitmap GenerateScreenshot(string url, int width, int height)
{
    // Load the webpage into a WebBrowser control
    WebBrowser wb = new WebBrowser();
    wb.ScrollBarsEnabled = false;
    wb.ScriptErrorsSuppressed = true;
    wb.Navigate(url);
    while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }


    // Set the size of the WebBrowser control
    wb.Width = width;
    wb.Height = height;

    if (width == -1)
    {
        // Take Screenshot of the web pages full width
        wb.Width = wb.Document.Body.ScrollRectangle.Width;
    }

    if (height == -1)
    {
        // Take Screenshot of the web pages full height
        wb.Height = wb.Document.Body.ScrollRectangle.Height;
    }

    // Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
    Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
    wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
    wb.Dispose();

    return bitmap;
}




Then write the code that image into pdf file.

1. create a new empty PDF document
2. add a blank page
3. get the XGraphics object
4. create the XImage from the source file
5. draw the image
6. save the PDF file


The code snippet to convert image to pdf is:

PdfDocument doc = new PdfDocument();
doc.Pages.Add(new PdfPage());
XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
XImage img = XImage.FromFile(source);

xgr.DrawImage(img, 0, 0);
doc.Save(destinaton);
doc.Close();
 
Share this answer
 
Comments
Sarin VT 24-Jul-13 8:02am    
Have you got the solution??
Swetha Bisa 24-Jul-13 8:08am    
hai sarin,

thanks for the reply, but i want to generate it as a salary slip, so how can i generate a pdf document.
Swetha Bisa 24-Jul-13 10:05am    
hai sarin,

can u please let me know how the above mentioned code snippet is used??
Sarin VT 24-Jul-13 10:02am    
Then you should provide the code.
You have done the correct thing.. since you are getting pdf output. also you are using iText.
We can only proceed, if you provide enough code snippets
Swetha Bisa 24-Jul-13 10:06am    
ya its exporting to pdf but my problem is in pdf document im not getting the table which im getting in preview, im getting the labels scattered through out the page

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900