Sign In  Sign Up Live-Chat

Images not rendering in PDF when using memory stream

Last post 06-25-2008, 9:36 PM by zachm875. 8 replies.
Sort Posts: Previous Next
  •  06-09-2008, 12:45 PM 130592

    Images not rendering in PDF when using memory stream

    I am reading in HTML using a memory stream...the pdf is rendering fnie with the exception of images. All images reference in the HTML are not displaying in the PDF. MY code is below

    //Set Aspose License

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

    license.SetLicense(AppDomain.CurrentDomain.BaseDirectory + "bin/Aspose.Pdf.lic");

    //Get pdf instance

    Pdf pdf = new Pdf();

    //Set margin widths

    pdf.HtmlInfo.Margin.Top = 20;

    pdf.HtmlInfo.Margin.Bottom = 20;

    pdf.HtmlInfo.Margin.Left = 20;

    pdf.HtmlInfo.Margin.Right = 20;

    //Set Font Map for better performance

    pdf.IsTruetypeFontMapCached = true;

    pdf.TruetypeFontMapPath = System.IO.Path.GetTempPath();

    byte[] by = System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "Templates/ClaimSummaryFaxPage1.htm"));

    MemoryStream ms = new MemoryStream(by);

    pdf.BindHTML(ms);

    string fileName = "ClaimSummaryFax_" + requestId.ToString();

    pdf.Save(fileName, SaveType.OpenInBrowser, Response);

     
  •  06-09-2008, 9:39 PM 130671 in reply to 130592

    Re: Images not rendering in PDF when using memory stream

    Hi,

    Thank you for considering Aspose.

    We have logged this issue as PDFNET-5301. We will try to resolve this problem soon.


    Tommy Wang
    Lead Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
  •  06-18-2008, 1:37 PM 131966 in reply to 130671

    Re: Images not rendering in PDF when using memory stream

    Any update or workaround for this issue?

     

    Thanks

     

     
  •  06-18-2008, 6:51 PM 131994 in reply to 131966

    Re: Images not rendering in PDF when using memory stream

    We are working on this issue. I hope we can resolve this problem late this week or early next week.
    Tommy Wang
    Lead Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
  •  06-23-2008, 3:41 PM 132641 in reply to 131994

    Re: Images not rendering in PDF when using memory stream

    Attachment: Present (inaccessible)
    Hi,

    The problem has been resolved. Please try the attachment before our new hotfix.

    Best regards.

    Hans Zhang
    Product Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
  •  06-24-2008, 1:53 PM 132843 in reply to 132641

    Re: Images not rendering in PDF when using memory stream

    Hello..thanks for the response

    I did try the attached .dll but images are still not being rendered when binding from a memory stream with the underlying html source.

    The code I am trying with is the same as in my original post. The HTML i am testing with is very simple..below is the HTML fragment from the file I am reading from

    <html >

    <body>

    <img src="test.gif">

    </body>

    </html>

    I did find a workaround for this issue..I'm not using MemoryStream but instead creating a temporary file and then binding to that. That works and all images render properly in the PDF. I would rather use the memory stream and forgo  having to create temp files.

     

     
  •  06-24-2008, 4:12 PM 132863 in reply to 132843

    Re: Images not rendering in PDF when using memory stream

    Hello Zach,

    I have tested your code using Aspose.Pdf v3.6.2.10 and with a very simple HTML file as specified in your post. I am unable to reproduce the error in this simple case. Where as I have also tested it using an HTML document with lots of information i.e. Text,Images,Table etc in that case its causing problem. I will discuss this issue with the development team and we will let you udpate with the status. Sorry for the inconvenience.


    Nayyer Shahbaz
    Support Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
  •  06-24-2008, 11:50 PM 132922 in reply to 132843

    Re: Images not rendering in PDF when using memory stream

    Hi Zach,

        Thank you very much for considering Aspose.Pdf. To the problem you mentioned above, we can provide another workaround which definitely supports memory stream. We provide a parameter HtmlInfo.ImgUrl to set the basic directory for relative path of img. All you have to do is to set the parameter before you bind the html. The code should be like the below:

       Pdf pdf1 = new Pdf();
       pdf1.HtmlInfo.ImgUrl="c:/pdftest/Aspose_files";
       byte[] by = System.Text.Encoding.UTF8.GetBytes(File.ReadAllText("C:/Memory.html"));
       MemoryStream ms = new MemoryStream(by);

       pdf1.BindHTML(ms);

           I am sure it works well in this way. The ultimate path of image in html is equal to pdf1.HtmlInfo.ImgUrl concatenated with the src of <img> in html source. That is to say pdf1.HtmlInfo.ImgUrl provides the basic path of image and the property 'src' of <img> provides the relative path of image.

           Sorry we have not provide a clear specification on this image path issue and we apologize for the inconvenience. If you have other problems with Aspose.Pdf, we are available anytime.


    Cynthia Hu
    Product Developer
    Aspose Changsha Team
    About Us
    Contact Us
     
  •  06-25-2008, 9:36 PM 133140 in reply to 132922

    Re: Images not rendering in PDF when using memory stream

    Thank you! Using the HtmlInfo.ImgUrl works.
     
View as RSS news feed in XML