Client Logo and CSS is not applied

Last post 02-15-2012, 10:47 AM by tahir.manzoor. 14 replies.
Sort Posts: Previous Next
  •  02-07-2012, 4:48 AM 359728

    Client Logo and CSS is not applied

    Attachment: Present (inaccessible)

    Hi AsposeTeam,

    The requirement of my project is to convert a html file to images and insert these images into a pdf document.

    THe code I am using is as follows:
    ----------------------------------
       Aspose.Words.License license = new Aspose.Words.License();
            license.SetLicense(@"C:\Jetstream\500\Resources\net3.5_ClientProfile\Aspose.Words.lic");

            Aspose.Pdf.License license2 = new Aspose.Pdf.License();
            license2.SetLicense(@"C:\Jetstream\500\Resources\Aspose.Pdf.Kit.lic");

            //load the html file into Aspose.Words
            Aspose.Words.LoadOptions lo = new Aspose.Words.LoadOptions();
            lo.LoadFormat = Aspose.Words.LoadFormat.Html;
      

            //Aspose.Words.Document doc = new Aspose.Words.Document(@"D:\Aspose\RDP\NEWFiles\Depp_backup.htm", lo);
            Aspose.Words.Document doc = new Aspose.Words.Document(@"D:\Aspose\RDP\NEWFiles\ImagePDF2.html", lo);

            //Make the text display in  individual rows

            NodeCollection tables = doc.GetChildNodes(NodeType.Table, true);
            foreach (Aspose.Words.Tables.Table tbl in tables)
            {
                tbl.AllowAutoFit = true;
                tbl.AutoFit(AutoFitBehavior.AutoFitToWindow);
                // tbl.AutoFit(AutoFitBehavior.AutoFitToContents);
                //tbl.AutoFit(AutoFitBehavior.FixedColumnWidths);
                //tbl.Alignment = TableAlignment.Left;
                tbl.Alignment = TableAlignment.Left;

                foreach (Aspose.Words.Tables.Row r in tbl.Rows)
                {
                    r.RowFormat.AllowBreakAcrossPages = false;
                    //  r.RowFormat.AllowAutoFit = true;

                    //NodeCollection cells = r.Cells;
                    foreach (Aspose.Words.Tables.Cell c in r.Cells)
                    {

                        c.CellFormat.WrapText = false;
                        //CellFormat.PreferredWidth = PreferredWidth.FromPercent(100);
                        //c.CellFormat.PreferredWidth = PreferredWidth.FromPoints(1000);               
                    }
                }
            }
            ////Generate the images
            doc.Save(@"D:\Aspose\RDP\NEWFiles\Depp_DOc.doc");
            for (int pageCounter = 0, stop = doc.PageCount; pageCounter < stop; pageCounter++)
            {
                Aspose.Words.Saving.ImageSaveOptions options2 = new Aspose.Words.Saving.ImageSaveOptions(SaveFormat.Png);
                options2.PageIndex = pageCounter;
                options2.PrettyFormat = true;
                // images are of the format <path>\<file><0-padded-page-index>.png, e.g. (somepath\myfile02.png)
                doc.Save(string.Format("{0}{1}{2}{3:d2}.png", "D:\\Aspose\\RDP\\NEWFiles\\Images\\", "", "MyImage", pageCounter + 1), options2);
            }

            //Aspose.Words.License license = new Aspose.Words.License();
            //license.SetLicense(@"D:\jetstream\500\Resources\Aspose.Words.lic");


            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
            string[] fileEntries = Directory.GetFiles(@"D:\Aspose\RDP\NEWFiles\Images\", "*.png");

            int length = fileEntries.GetLength(0);
            int counter;

            for (counter = 0; counter < length; counter++)
            {
                // Create a section object
                Aspose.Pdf.Generator.Section section1 = pdf.Sections.Add();
                // creat an image object
                section1.PageInfo.PageWidth = Aspose.Pdf.Generator.PageSize.A4Width;
                section1.PageInfo.PageHeight = Aspose.Pdf.Generator.PageSize.A4Height;

                section1.PageInfo.Margin.Top = 0;
                section1.PageInfo.Margin.Left = 0;
                section1.PageInfo.Margin.Bottom = 0;
                section1.PageInfo.Margin.Right = 0;

                Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(section1);
                image1.ImageInfo.File = fileEntries[counter];
                image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Png;
                image1.ImageInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Center;

                image1.ImageInfo.FixHeight = section1.PageInfo.PageHeight - section1.PageInfo.Margin.Top - section1.PageInfo.Margin.Bottom;
                // specify the image Width information eqaul to Section Width minus Left and Right margin of page
                image1.ImageInfo.FixWidth = section1.PageInfo.PageWidth - section1.PageInfo.Margin.Left - section1.PageInfo.Margin.Right;

     

                // Create a BitMap object in order to get the information of image file
                //Bitmap myimage = new Bitmap(fileEntries[counter]);

                //// check if the width of the image file is greater than Page width or not
                //if (myimage.Width > section1.PageInfo.PageWidth)
                ////    // if the Image width is greater than page width, then set the page orientation to Landscape
                //    section1.IsLandscape = true;
                //else
                ////    // if the Image width is less than page width, then set the page orientation to Portrait
                section1.IsLandscape = false;
                //// add the image to paragraphs collection of the PDF document
                //section1.IsLandscape = false;
                section1.Paragraphs.Add(image1);
            }
            pdf.Save(@"D:\Aspose\RDP\NEWFiles\Images_to_PDF_Conversion2.pdf");

    The above code is working fine for ImagePdf2.htm..I am able to obtaing the CSS but not the client logo.(PLease see the attached folder by name "working")
    The above code is not working for "Depp_backup.htm".I am not able to get the CSS applied as well as the client logo.(Please see the attached folder by "No Working").

    If you observer the "Depp_backup.htm" the columns are placed side by side in the browser.i.e in multiple columns.
    THe CSS used for this purpose is: https://staging.brassring.com/WelcomePages.UserInterface/CSS/LayoutForms.css.


    Can you please look into the code and suggest me the changes need to  be implemented to have the client logo as well as the fields to be displayed in multiple columns.


    Thanks,
    siddi.

     
  •  02-07-2012, 10:43 AM 359818 in reply to 359728

    Re: Client Logo and CSS is not applied

    Attachment: Present (inaccessible)
    Hi Siddi,

    Thanks for your query. Your code seems correct to me. The only issue is you are using html from local  D drive and html file contain CSS and logo from live URLs. You can achieve your requirement by following two methods.
    1. Save the html file, CSS and logos at local hard drive and use the same code to achieve correct output. Please see the attachment.
    2. Use the method OpenDocumentFromUrl to load document from URL.
    Hope this helps you. Let me know, If you have any more queries.

    Best Regards,
    Tahir Manzoor
    Support Developer, Aspose Sialkot Team
    http://www.aspose.com
    Your File Format Experts
    Keep in touch! We're on Twitter and Facebook
     
  •  02-08-2012, 12:03 PM 360156 in reply to 359818

    Re: Client Logo and CSS is not applied

    Attachment: Present (inaccessible)

    Hi Tahir,

    Thanks for looking into this.

    I have tried both the above mentioned approaches.But with no success.

    I am still not able to get the CSS applied.Below are the details of my implementation.

    Please look into this and suggest me any changes.

    Approach 1:
    -----------
    1.Save the html file, CSS and logos at local hard drive and use the same code to achieve correct output. Please see the attachment.

    With this approach I am able to get the Client logo but not the CSS.

    shows labels and form options in one column left-justified, instead of two columns.

    Expected: The output PDF should look like the input html, including column display, font type, font style, etc.
     
    Please see the attached pdf file "NoCSSApplied.pdf".

    Approach 2:Use the method OpenDocumentFromUrl to load document from URL.

    ------------------------------------------------------------------------

    I have used the following code:

    private Document OpenDocumentFromUrl(string url)
    {
        //Prepare the web page we will be asking for
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "GET";
        request.ContentType = "text/html";
        request.UserAgent = "Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0";

        //Execute the request
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        //We will read data via the response stream
        Stream resStream = response.GetResponseStream();

        //Write content into the MemoryStream
        BinaryReader resReader = new BinaryReader(resStream);
        MemoryStream docStream = new MemoryStream(resReader.ReadBytes((int)response.ContentLength));
        // Open document from stream.

        string filename = @"D:\Aspose\test.htm";
     //save the file to the local disk inoreder to replace the relative paths to absolute paths
        SaveMemoryStream(docStream, @"D:\test.htm");
        Document doc = new Document(docStream);

        return doc;
    }

    private void SaveMemoryStream(MemoryStream ms, string FileName)
    {
        FileStream outStream = File.OpenWrite(FileName);
        ms.WriteTo(outStream);
        outStream.Flush();
        outStream.Close();
    }

    Aspose.Words.LoadOptions lo = new Aspose.Words.LoadOptions();
        lo.LoadFormat = Aspose.Words.LoadFormat.Html;

        string readText = File.ReadAllText(@" D:\test.htm");

        string dataToRemove = "href=\"/jetstream";
        string dataToRemove2 = "src=\"/jetstream";
        string dataToRemove3 = "../../../../../../..";

     //replace the relative paths with absolute paths.
        readText = Regex.Replace(readText, dataToRemove, "href=\"https://" + "VIZSPOTHUGADT01" + "/jetstream", RegexOptions.IgnoreCase);
        readText = Regex.Replace(readText, dataToRemove2, "src=\"https://" + "VIZSPOTHUGADT01" + "/jetstream", RegexOptions.IgnoreCase);
        readText = Regex.Replace(readText, dataToRemove2, "src=\"https://" + "VIZSPOTHUGADT01" + "/jetstream", RegexOptions.IgnoreCase);
        readText = Regex.Replace(readText,dataToRemove3,"https://VIZSPOTHUGADT01");

        File.WriteAllText(@" D:\test2.htm", readText);


        Aspose.Words.Document doc2 = new Aspose.Words.Document(@" D:\test2.htm", lo);
      

    //conver the html to image files.

        for (int pageCounter = 0, stop = doc2.PageCount; pageCounter < stop; pageCounter++)
        {
            Aspose.Words.Saving.ImageSaveOptions options2 = new Aspose.Words.Saving.ImageSaveOptions(SaveFormat.Png);
            options2.PageIndex = pageCounter;
            options2.PrettyFormat = true;
            // images are of the format <path>\<file><0-padded-page-index>.png, e.g. (somepath\myfile02.png)
            doc2.Save(string.Format("{0}{1}{2}{3:d2}.png", "D:\\Aspose\\RDP\\NEWFiles\\Images\\", "", "MyImagetest", pageCounter + 1), options2);
        }


    With this approach also I am not able to get the CSS applied.

    Can you please look into this and help me to convert the html file to image file with all the CSS applied.

    Thanks,
    Siddi.

     
  •  02-09-2012, 2:36 AM 360295 in reply to 360156

    Re: Client Logo and CSS is not applied

    Attachment: Present (inaccessible)
    Hi Siddi,

    I have download the CSS and logo file to local disk and have successfully converted to .doc and images files. Please see in attachment. Your html, CSS and logo file should be located at local disk or at remote server.

    Best Regards,
    Tahir Manzoor
    Support Developer, Aspose Sialkot Team
    http://www.aspose.com
    Your File Format Experts
    Keep in touch! We're on Twitter and Facebook
     
  •  02-09-2012, 2:57 AM 360305 in reply to 360295

    Re: Client Logo and CSS is not applied

    Attachment: Present (inaccessible)
    Hi Siddi,

    Please find the doc and images files generated from http://www.aspose.com/ web page in attachment.


    Document doc = OpenDocumentFromUrl("http://www.aspose.com/");

    //Make the text display in  individual rows

     

    NodeCollection tables = doc.GetChildNodes(NodeType.Table, true);

    foreach (Aspose.Words.Tables.Table tbl in tables)

    {

        tbl.AllowAutoFit = true;

        tbl.AutoFit(AutoFitBehavior.AutoFitToWindow);

        // tbl.AutoFit(AutoFitBehavior.AutoFitToContents);

        //tbl.AutoFit(AutoFitBehavior.FixedColumnWidths);

        //tbl.Alignment = TableAlignment.Left;

        tbl.Alignment = TableAlignment.Left;

     

        foreach (Aspose.Words.Tables.Row r in tbl.Rows)

        {

            r.RowFormat.AllowBreakAcrossPages = false;

            //  r.RowFormat.AllowAutoFit = true;

     

            //NodeCollection cells = r.Cells;

            foreach (Aspose.Words.Tables.Cell c in r.Cells)

            {

     

                c.CellFormat.WrapText = false;

                //CellFormat.PreferredWidth = PreferredWidth.FromPercent(100);

                //c.CellFormat.PreferredWidth = PreferredWidth.FromPoints(1000);              

            }

        }

    }

    ////Generate the images

    doc.Save(MyDir + "Depp_DOc.doc");

     

    for (int pageCounter = 0, stop = doc.PageCount; pageCounter < stop; pageCounter++)

    {

        Aspose.Words.Saving.ImageSaveOptions options2 = new Aspose.Words.Saving.ImageSaveOptions(SaveFormat.Png);

        options2.PageIndex = pageCounter;

        options2.PrettyFormat = true;

        doc.Save(string.Format("{0}{1}{2}{3:d2}.png", MyDir, "", "MyImage", pageCounter + 1), options2);

    }



    Best Regards,
    Tahir Manzoor
    Support Developer, Aspose Sialkot Team
    http://www.aspose.com
    Your File Format Experts
    Keep in touch! We're on Twitter and Facebook
     
  •  02-10-2012, 7:28 AM 360728 in reply to 360305

    Re: Client Logo and CSS is not applied

    Attachment: Present (inaccessible)

    Hi Tahir,

    Thanks for looking into this issue.

    I am able to obtain the images with CSS applied by giving the url: "http://www.aspose.com/".

    The requirement of my project is to get the ouptut images which look exacttly as the html page.

    But when I try with the below test urls, I am unable to get the output images which look exactly the input html.

    Please find the attached files which include the images generated, which donot contain any CSS or images applied.

    The test URLS are:
    ------------------
    1)https://staging.brassring.com/JetStream/500/Presentation/Template/ASP/Candidate/Forms/ViewForm.asp?isgq=@7jmvKabnpHc=&apprvl=@Qa8WrdFDvAg=&localeid=@IsSbRwlc1jxKpUy0SbstnA==&mode=@1yjS1Hi6/q/uNq32m6X08Q==&where=@TPEBTmFaU8Z5hrgmRqSygA==&encryptedvalues=@B3v1zQ6oVqFsDY9pMN69NQ==*@lAP/WXdUWjbvI28lBLZ0NzBOSP9eR2R7*@WVhbetm62SftzZwTNAdDiQ==*@vd5QY$kP9OncO1wvAFpXoQ==*@C3jlsYN$x6ZuYErOxxZHQA==*@woZRg$sPs2Y=*@7jmvKabnpHc=*@gsu53u3NYJAumwDx57RTDQ==*@G6OALy2D/Sw=*@amtcAhHDhl8=*@oELV7RtSM3LfQjXvPMhUzSVCQJTXr1BhDAAR5gOoetnpWj13kdr2wuon/UIgaFPbrUE8CZNi$RTC$Yr9bXP46MFnD95zC7uVcS023F232FPHTl1FLh74vftdOzP2ro7NA/j$CsraD26f7$7zlk7zbhNfy9dM9AmWdZBYVfYt7nv2p51ZKV5O$ILtRT7bkp0bH2Nj1uytfRQ=*@s/8UkTuFFVU=*@7jmvKabnpHc=
    2)https://staging.brassring.com/JetStream/500/Presentation/Template/ASP/Candidate/Forms/ViewForm.asp?isgq=@7jmvKabnpHc=&apprvl=@Qa8WrdFDvAg=&localeid=@IsSbRwlc1jxKpUy0SbstnA==&mode=@1yjS1Hi6/q/uNq32m6X08Q==&where=@TPEBTmFaU8Z5hrgmRqSygA==&encryptedvalues=@B3v1zQ6oVqFsDY9pMN69NQ==*@s$qqQfL/LZEvTJxmryQE/AotErv5vup4*@WVhbetm62SftzZwTNAdDiQ==*@vd5QY$kP9OncO1wvAFpXoQ==*@C3jlsYN$x6ZuYErOxxZHQA==*@woZRg$sPs2Y=*@7jmvKabnpHc=*@gsu53u3NYJAumwDx57RTDQ==*@G6OALy2D/Sw=*@amtcAhHDhl8=*@oELV7RtSM3LfQjXvPMhUzSVCQJTXr1BhDAAR5gOoetnpWj13kdr2wuon/UIgaFPbrUE8CZNi$RTC$Yr9bXP46MFnD95zC7uVcS023F232FPHTl1FLh74vftdOzP2ro7NA/j$CsraD26f7$7zlk7zbhNfy9dM9AmWdZBYVfYt7nv2p51ZKV5O$ILtRT7bkp0bH2Nj1uytfRQ=*@s/8UkTuFFVU=*@7jmvKabnpHc=

    Can you please try with the above urls and help me to get the images which look exactly the html.
    Please let me know if you need any more information.

    Thanks,
    Siddi.


     

     
  •  02-10-2012, 11:17 AM 360800 in reply to 360728

    Re: Client Logo and CSS is not applied

    Attachment: Present (inaccessible)
    Hi Siddi,

    I have tested the shared URL and found that the logo and web page URL (Domain) is not same. Its mean, the web page and logo are at different domains. Please see the attachment.  In this case, you need to download complete web page with HttpWebRequest and pass stream object to Document constructor.

    Best Regards,
    Tahir Manzoor
    Support Developer, Aspose Sialkot Team
    http://www.aspose.com
    Your File Format Experts
    Keep in touch! We're on Twitter and Facebook
     
  •  02-10-2012, 11:54 AM 360810 in reply to 360800

    Re: Client Logo and CSS is not applied

    Hi Tahir,

     

    I have used the following code but still I did not get the CSS as well as images.

     

    //string url = "http://localhost/test_setLicense/in.doc";

    //string url = "https://staging.brassring.com/JetStream/500/Presentation/Template/ASP/Candidate/Forms/ViewForm.asp?isgq=@7jmvKabnpHc=&apprvl=@Qa8WrdFDvAg=&localeid=@IsSbRwlc1jxKpUy0SbstnA==&mode=@1yjS1Hi6/q/uNq32m6X08Q==&where=@TPEBTmFaU8Z5hrgmRqSygA==&encryptedvalues=@B3v1zQ6oVqFsDY9pMN69NQ==*@s$qqQfL/LZEvTJxmryQE/AotErv5vup4*@WVhbetm62SftzZwTNAdDiQ==*@vd5QY$kP9OncO1wvAFpXoQ==*@C3jlsYN$x6ZuYErOxxZHQA==*@woZRg$sPs2Y=*@7jmvKabnpHc=*@gsu53u3NYJAumwDx57RTDQ==*@G6OALy2D/Sw=*@amtcAhHDhl8=*@oELV7RtSM3LfQjXvPMhUzSVCQJTXr1BhDAAR5gOoetnpWj13kdr2wuon/UIgaFPbrUE8CZNi$RTC$Yr9bXP46MFnD95zC7uVcS023F232FPHTl1FLh74vftdOzP2ro7NA/j$CsraD26f7$7zlk7zbhNfy9dM9AmWdZBYVfYt7nv2p51ZKV5O$ILtRT7bkp0bH2Nj1uytfRQ=*@s/8UkTuFFVU=*@7jmvKabnpHc=";

    string url = "http://www.aspose.com/";

    //Prepare the web page we will be asking for

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

    request.Method = "GET";

    request.ContentType = "application/msword";

    request.UserAgent = "Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0";

    //Execute the request

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

    //We will read data via the response stream

    Stream resStream = response.GetResponseStream();

    //Write content into the MemoryStream

    BinaryReader resReader = new BinaryReader(resStream);

    MemoryStream docStream = new MemoryStream(resReader.ReadBytes((int)response.ContentLength));

    //Create document

    Aspose.Words.License license = new Aspose.Words.License();

    license.SetLicense(@"C:\Jetstream\500\Resources\net3.5_ClientProfile\Aspose.Words.lic");

    Document doc = new Document(docStream);

    //Do something

    //........

    //Save document

    doc.Save(@"C:\out.doc");

     

    Could you please review this and let me know if you need more information.

    And my requirement is to get the output which looks exactly as the input html..including the CSS.

    THanks,

    Siddi.

     
  •  02-12-2012, 8:03 AM 360884 in reply to 360810

    Re: Client Logo and CSS is not applied

    Hi Tahir,

    Sorry for the trouble.May I know any update on this?

    Thanks,
    Siddi.
     
  •  02-13-2012, 3:57 AM 361042 in reply to 360884

    Re: Client Logo and CSS is not applied

    Hi Siddi,

    I regret to share with you that the requested feature is not available in Aspose.Words at the moment. However, We had
    already logged this feature request in our issue tracking system. You will be notified via this forum thread once this feature is available.

    Best Regards,
    Tahir Manzoor
    Support Developer, Aspose Sialkot Team
    http://www.aspose.com
    Your File Format Experts
    Keep in touch! We're on Twitter and Facebook
     
  •  02-13-2012, 4:38 AM 361060 in reply to 361042

    Re: Client Logo and CSS is not applied

    Hi Tahir,

    Thanks for your reply..If possible can you please tell me the timeframe when I can expect this feature ..and also I request the AsposeTeam to  update me once this feature is fully supported..

    Thanks,

    Siddi.

     
  •  02-13-2012, 8:25 AM 361122 in reply to 361060

    Re: Client Logo and CSS is not applied

    Hi Siddi,

    Thanks for your inquiry. Unfortunately, your issues are pending for analysis. Once our developers analyze these issues, we will be able to provide you an estimate. You will be notify as soon as it is fixed. Sorry for inconvenience.


    Best Regards,
    Imran Rafique
    Support Developer
    Aspose Sialkot Team
    http://www.aspose.com/
    Aspose - Your File Format Experts
    Keep in touch! We're on Twitter and Facebook
     
  •  02-15-2012, 3:06 AM 361747 in reply to 361122

    Re: Client Logo and CSS is not applied

    Hi Siddi,

     

    Thanks for your request. I reinvestigated your issue and here is what I found:

     

    1. The problem with logo:

    a) The logo image disappears because in your HTML ‘img’ is direct child of ‘table’. Aspose.Words simply ignores the image in such case. I suppose you would agree that image should not be a direct child of ‘table’. Here is snippet of your HTML:

     

    <table class="guardAgainstInvalidMarkup">

        <tbody class="guardAgainstInvalidMarkup">

            <tr class="guardAgainstInvalidMarkup">

                <td class="guardAgainstInvalidMarkup">

                    <font class="FONTMedium">

                        <table style="background-color: #ffffff;" class="backg">

                            <img src="https://sstagingjobs.brassring.com/img/images_25411_5501/images/DGlogo.jpg"

                                style="align: left; position: absolute; left: 1px; top: 1px;">

                            <br>

                            <br>

                            <br>

                            <br>

                        </table>

                        <span class="helpLink"><span class="questionHelpText"></span></span></font>

                </td>

            </tr>

        </tbody>

    </table>

     

    Highlighted tags are redundant. If you remove them the logo image will be displayed.

     

    b) Logo image in your HTML is absolutely positioned. Unfortunately, Aspose.Words does not support importing floating content form HTML yet. That is why position of such image might be incorrect.

     

    I logged both of these issue into our defect database. We will let you know once they are resolved.

     

    2) Problem with css. Aspose.Words does not support inheriting formatting from parent elements. Currently, Aspose.Words expects that font formatting is set in <span>, <i>, <b> or <u> element, formatting of paragraph – in <p> or <h1>…<h6> elements etc…

    In your case all elements are deeply nested into divs and tables that is why formatting that must be inherited from the parent elements is lost.

     

    Best regards. 


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  02-15-2012, 9:43 AM 361848 in reply to 361747

    Re: Client Logo and CSS is not applied

    Hi ,

    I have found a way to downlad the webpage to image using the following code:

     

    using System;

    using System.Collections.Generic;

    using System.Text;

    using System.Drawing;

    using System.Drawing.Drawing2D;

    using System.Drawing.Imaging;

    using System.Windows.Forms;

    using System.Diagnostics;

    using System.Threading;

    namespace MyLib

    {

    public class GetImage

    {

    private int S_Height;

    private int S_Width;

    private int F_Height;

    private int F_Width;

    private string MyURL;

    public int ScreenHeight

    {

    get { return S_Height; }

    set { S_Height = value; }

    }

    public int ScreenWidth

    {

    get { return S_Width; }

    set { S_Width = value; }

    }

    public int ImageHeight

    {

    get { return F_Height; }

    set { F_Height = value; }

    }

    public int ImageWidth

    {

    get { return F_Width; }

    set { F_Width = value; }

    }

    public string WebSite

    {

    get { return MyURL; }

    set { MyURL = value; }

    }

    public GetImage(string WebSite, int ScreenWidth, int ScreenHeight, int ImageWidth, int ImageHeight)

    {

    this.WebSite = WebSite;

    this.ScreenWidth = ScreenWidth;

    this.ScreenHeight = ScreenHeight;

    this.ImageHeight = ImageHeight;

    this.ImageWidth = ImageWidth;

    }

    public void GetBitmap()

    {

    WebPageBitmap Shot = new WebPageBitmap(this.WebSite, this.ScreenWidth, this.ScreenHeight);

    Shot.GetIt();

    Bitmap Pic = Shot.DrawBitmap(this.ImageHeight, this.ImageWidth);

    Pic.Save(@"C:\Second.jpg");

    //return Pic;

    }

    }

    class WebPageBitmap

    {

    WebBrowser MyBrowser;

    string URL;

    int Height;

    int Width;

    public WebPageBitmap(string url, int width, int height)

    {

    this.Height = height;

    this.Width = width;

    this.URL = url;

    MyBrowser = new WebBrowser();

    MyBrowser.ScrollBarsEnabled = false;

    MyBrowser.WebBrowserShortcutsEnabled = false;

    MyBrowser.ObjectForScripting = false;

    MyBrowser.Size = new Size(this.Width, this.Height);

    }

    public void GetIt()

    {

    MyBrowser.Navigate(this.URL);

    while (MyBrowser.ReadyState != WebBrowserReadyState.Complete)

    {

    Application.DoEvents();

    }

    }

    public Bitmap DrawBitmap(int theight, int twidth)

    {

    //HtmlElementCollection children = MyBrowser.Document.All;

    //int maxOffset = 0;

    //foreach (HtmlElement child in children)

    //{

    // int bottom = 0; bottom = child.OffsetRectangle.Bottom;

    // if (bottom > maxOffset)

    // {

    // maxOffset = bottom;

    // theight = maxOffset;

    // }

    //}

    Height=theight = MyBrowser.Document.Body.ScrollRectangle.Height;

    Bitmap myBitmap = new Bitmap(Width, Height);

    Rectangle DrawRect = new Rectangle(0, 0, Width, Height);

    MyBrowser.DrawToBitmap(myBitmap, DrawRect);

    System.Drawing.Image imgOutput = myBitmap;

    System.Drawing.Image oThumbNail = new Bitmap(twidth, theight, imgOutput.PixelFormat);

    Graphics g = Graphics.FromImage(oThumbNail);

    g.CompositingQuality = CompositingQuality.HighSpeed;

    g.SmoothingMode = SmoothingMode.HighSpeed;

    g.InterpolationMode = InterpolationMode.HighQualityBilinear;

    Rectangle oRectangle = new Rectangle(0, 0, twidth, theight);

    g.DrawImage(imgOutput, oRectangle);

    try

    {

    return (Bitmap)oThumbNail;

    }

    catch (Exception ex)

    {

    Console.WriteLine(ex.Message);

    return null;

    }

    finally

    {

    imgOutput.Dispose();

    imgOutput = null;

    MyBrowser.Dispose();

    MyBrowser = null;

    }

    }

    }

    public class OLayer

    {

    public void CaptureImage(string url)

    {

    System.Drawing.Bitmap x = null;

    try

    {

    // string url = "http://" + Request.Url.Host + ":" + Request.Url.Port.ToString();

    //url = url + UrlPath;

    GetImage thumb = new GetImage(url, 1024, 3800, 1024, 3200);

    Thread thread = new Thread(new ThreadStart(thumb.GetBitmap));

    thread.SetApartmentState(ApartmentState.STA);

    thread.Start();

    thread.Join();

    //return _bmp.GetThumbnailImage(_thumbWidth, _thumbHeight,

    // null, IntPtr.Zero) as Bitmap;

    // x = thumb.GetBitmap();

    // x.Save(System.Environment.CurrentDirectory + "\\cap\\" + FileName + ".jpg");

    // x.Save(@"C:\first.jpg");

    //CaptureState = true;

    }

    catch (Exception ex)

    {

    Console.WriteLine(ex.ToString());

    //CaptureState = false;

    }

    finally

    {

    if (x != null) x.Dispose();

    }

    }

    }

    public class Run

    {

    [STAThread]

    public static void Main()

    {

    OLayer ow = new OLayer();

    //ow.CaptureImage("http://www.5do8.com/");

    //ow.CaptureImage("http://www.google.co.in/");

    //ow.CaptureImage("https://staging.brassring.com/JetStream/500/Presentation/Template/ASP/Candidate/Forms/ViewForm.asp?isgq=@7jmvKabnpHc=&apprvl=@Qa8WrdFDvAg=&localeid=@IsSbRwlc1jxKpUy0SbstnA==&mode=@1yjS1Hi6/q/uNq32m6X08Q==&where=@TPEBTmFaU8Z5hrgmRqSygA==&encryptedvalues=@B3v1zQ6oVqFsDY9pMN69NQ==*@m11AkCrr/WdfHQn3dsvDdUuR$QYfhoGz*@WVhbetm62SftzZwTNAdDiQ==*@vd5QY$kP9OncO1wvAFpXoQ==*@3tBza19gLN9AOfIx08Q2pg==*@woZRg$sPs2Y=*@7jmvKabnpHc=*@Sd6PLl1ntnDqsPugmZoV/A==*@G6OALy2D/Sw=*@amtcAhHDhl8=*@oELV7RtSM3LfQjXvPMhUzSVCQJTXr1BhDAAR5gOoetnpWj13kdr2wuon/UIgaFPbODmFpOT5BhJg8cn7fGqWRI0EYHDJIER4KKCeDRc1jEz5FfyHMM57wBymCDK78/ZObSQcpLEgW6busGbFRQFeMw==*@s/8UkTuFFVU=*@7jmvKabnpHc");

    ow.CaptureImage(https://qaweb1.brassring.com/JetStream/500/Presentation/Template/ASP/Candidate/Forms/ViewForm.asp?isgq=@7jmvKabnpHc=&apprvl=@Qa8WrdFDvAg=&localeid=@IsSbRwlc1jxKpUy0SbstnA==&mode=@1yjS1Hi6/q/uNq32m6X08Q==&where=@TPEBTmFaU8Z5hrgmRqSygA==&encryptedvalues=@5OjSQ96Fv4Lic5wJIRyUTQ==*@zpiLnXx8ONE6E0UKhZdO1hlzLQQ6oVgr*@Xupg87uqgbqUEmdUypYGZQ==*@TuyYPtXnSeKduDZls580CQ==*@zE6YUyYzyt7tHAI3fqMqag==*@9BmpnW1LtuY=*@7jmvKabnpHc=*@E5uA4fPTviC1uPC6FYO0Ww==*@G6OALy2D/Sw=*@amtcAhHDhl8=*@TMNx58pLCiVdCjReyWnhvnPkg7ElzD75tdw/KPVAZZGl4BlMSZsf5hHLs6nFRmae0jyytCjEw5HcrTcNdHAdG$WaVvvVQLcDCXi76Rk0o52ysbEyUt7pLeFI6D9mNdRTalo3nMFYurCmpy1XnJDOhxtQAyCqPV1r*@s/8UkTuFFVU=*@7jmvKabnpHc=);

    }

    }

    }

     

    Create a button in the Sample Webproject and Call the above code like this:

    protected void Button1_Click(object sender, EventArgs e)

    {

    OLayer ow = new OLayer();

    //ow.CaptureImage("http://www.5do8.com/");

    //ow.CaptureImage("http://www.google.co.in/");

    //ow.CaptureImage("https://staging.brassring.com/JetStream/500/Presentation/Template/ASP/Candidate/Forms/ViewForm.asp?isgq=@7jmvKabnpHc=&apprvl=@Qa8WrdFDvAg=&localeid=@IsSbRwlc1jxKpUy0SbstnA==&mode=@1yjS1Hi6/q/uNq32m6X08Q==&where=@TPEBTmFaU8Z5hrgmRqSygA==&encryptedvalues=@B3v1zQ6oVqFsDY9pMN69NQ==*@m11AkCrr/WdfHQn3dsvDdUuR$QYfhoGz*@WVhbetm62SftzZwTNAdDiQ==*@vd5QY$kP9OncO1wvAFpXoQ==*@3tBza19gLN9AOfIx08Q2pg==*@woZRg$sPs2Y=*@7jmvKabnpHc=*@Sd6PLl1ntnDqsPugmZoV/A==*@G6OALy2D/Sw=*@amtcAhHDhl8=*@oELV7RtSM3LfQjXvPMhUzSVCQJTXr1BhDAAR5gOoetnpWj13kdr2wuon/UIgaFPbODmFpOT5BhJg8cn7fGqWRI0EYHDJIER4KKCeDRc1jEz5FfyHMM57wBymCDK78/ZObSQcpLEgW6busGbFRQFeMw==*@s/8UkTuFFVU=*@7jmvKabnpHc");

    //ow.CaptureImage("https://qaweb1.brassring.com/JetStream/500/Presentation/Template/ASP/Candidate/Forms/ViewForm.asp?isgq=@7jmvKabnpHc=&apprvl=@Qa8WrdFDvAg=&localeid=@IsSbRwlc1jxKpUy0SbstnA==&mode=@1yjS1Hi6/q/uNq32m6X08Q==&where=@TPEBTmFaU8Z5hrgmRqSygA==&encryptedvalues=@5OjSQ96Fv4Lic5wJIRyUTQ==*@zpiLnXx8ONE6E0UKhZdO1hlzLQQ6oVgr*@Xupg87uqgbqUEmdUypYGZQ==*@TuyYPtXnSeKduDZls580CQ==*@zE6YUyYzyt7tHAI3fqMqag==*@9BmpnW1LtuY=*@7jmvKabnpHc=*@E5uA4fPTviC1uPC6FYO0Ww==*@G6OALy2D/Sw=*@amtcAhHDhl8=*@TMNx58pLCiVdCjReyWnhvnPkg7ElzD75tdw/KPVAZZGl4BlMSZsf5hHLs6nFRmae0jyytCjEw5HcrTcNdHAdG$WaVvvVQLcDCXi76Rk0o52ysbEyUt7pLeFI6D9mNdRTalo3nMFYurCmpy1XnJDOhxtQAyCqPV1r*@s/8UkTuFFVU=*@7jmvKabnpHc=");

    ow.CaptureImage(https://qaweb1.brassring.com/JetStream/500/Presentation/Template/ASP/Candidate/Forms/AddForm.asp?localeid=@IsSbRwlc1jxKpUy0SbstnA==&mode=@a5fPHOySW6Q=&where=@VwH0SImlsFALHYRM909LDQ==&dsn=@9BmpnW1LtuY=&ftid=@/gDPNh/gaR0=&encryptedvalues=@5OjSQ96Fv4Lic5wJIRyUTQ==$@KxXsVxPq3RUL720JsGH/2Azo45r6ndTO$@Xupg87uqgbqUEmdUypYGZQ==$@/gDPNh/gaR0=$@zE6YUyYzyt7tHAI3fqMqag==$@9BmpnW1LtuY=$@7jmvKabnpHc=$-1$@nEErLCr*rvLBz6Ie1KFzlg==$$@s/8UkTuFFVU=);

    }

    I found the above Code From the URL:

    1)      http://snippets.dzone.com/posts/show/4732

     

    I hope this will help us to download the Webpage as image..

    Please let me know if you need any more information. for your investigation.

    Thanks,

    Siddi.

     

     

     
  •  02-15-2012, 10:47 AM 361862 in reply to 361848

    Re: Client Logo and CSS is not applied

    Hi Siddi,

    Thanks for sharing helpful information. Our development team will look into these issues and you will be updated via this forum thread once these issues are resolved.

    Best Regards,
    Tahir Manzoor
    Support Developer, Aspose Sialkot Team
    http://www.aspose.com
    Your File Format Experts
    Keep in touch! We're on Twitter and Facebook
     
View as RSS news feed in XML