Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Jul 16, 2012 2:07 pm

Hi,
I'm trying to convert HTML file in PDF in SharePoint 2007 context, using this snippet of code:

......................................

System.Threading.ThreadStart threadStart = HTMLToPDF;
System.Threading.Thread thread = new System.Threading.Thread(threadStart);
thread.SetApartmentState(System.Threading.ApartmentState.STA);
thread.Start();

.......................................

private static void HTMLToPDF()
{
Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument();
doc.LoadFromHTML("http://www.google.it", false, true, true);

........................................

}


During LoadFromHTML execution I obtain an error like "It is timeout to load html". I attach the resulting converted PDF file, it seems navigation error. How I can solve this problem?

Thanks for support

simorav
 
Posts: 9
Joined: Mon Jul 16, 2012 1:46 pm

Tue Jul 17, 2012 4:11 am

Hi simorav,

Thanks for evaluating Spire.Pdf.

We've created a research on this problem, but it works fine on my side. The issue happened for you might caused by the network connection
of your PC/server, please check that.
Besides you can try to use the following code:
....................................................................................

WebClient wc = new WebClient();
byte[] data = wc.DownloadData("http://www.google.it");

....................................................................................
If you still have any problems, please contact us!
Have a great day!

Amy
e-iceblue support
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Jul 17, 2012 8:25 am

Hi,
thanks for your support.
I try your suggestion and I have no problem to download data from web, my array is filled correctly.
If I use this instuction to create a PdfDocument:

Code: Select all
WebClient wc = new WebClient();
byte[] data = wc.DownloadData("http://www.google.it");

Spire.Pdf.PdfDocument doc= new Spire.Pdf.PdfDocument();
doc.LoadFromBytes(data);


I obtain this exception message :
Invalid/Unknown/Unsupported format
at Spire.Pdf.IO.PdfReader.ReadBack(Int32 length)
at Spire.Pdf.IO.PdfReader.SearchBack(String token)
at Spire.Pdf.IO.CrossTable..ctor(Stream docStream, PdfCrossTable crossTable)
at Spire.Pdf.IO.PdfCrossTable..ctor(Stream docStream)
at Spire.Pdf.Widget.PdfDocumentWidget.a(Stream A_0)
at Spire.Pdf.Widget.PdfDocumentWidget..ctor(Stream file)
at Spire.Pdf.Widget.PdfDocumentWidget..ctor(Byte[] file)
at Spire.Pdf.PdfDocument.LoadFromBytes(Byte[] bytes)

Any suggestion?

simorav
 
Posts: 9
Joined: Mon Jul 16, 2012 1:46 pm

Wed Jul 18, 2012 3:43 am

Hi simorav,

As the issue you reported, we have created a research on it, but we need some more time to fix it.However, you will be surely informed once we fix it.

Thanks for your understanding and cooperation.

Have a great day!

Amy
e-iceblue support
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Thu Jul 19, 2012 9:16 am

Hi,
You colud set the timeout argument, please try this:
Code: Select all
using System;

using Spire.Pdf;
using Spire.Pdf.Graphics;
using Spire.Pdf.HtmlConverter;

namespace SPIREPDF_52
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            using (PdfDocument doc = new PdfDocument())
            {
                PdfSection section = doc.Sections.Add();
                PdfHtmlLayoutFormat format = new PdfHtmlLayoutFormat
                {
                    Layout = PdfLayoutType.Paginate,
                    FitToPage = Clip.Width,
                    //load html timeout
                    LoadHtmlTimeout = 60 * 1000
                };
                section.LoadFromHTML("http://www.google.it", true, true, format);

                doc.SaveToFile("test.pdf");
            }
            System.Diagnostics.Process.Start("test.pdf");
        }
    }
}
Harry
Technical Support / Developer,
e-iceblue Support Team
User avatar

harry.support
 
Posts: 180
Joined: Mon Nov 08, 2010 3:11 pm

Mon Jul 23, 2012 11:56 am

Hi,
using your code I solved the timeout problem, but I still observe navigation error in my PDF file (please see the file attached in my first post).

In my opinion the user who create the PDF file inside the specific thread is not able to navigate through my proxy server. If I try to run my code on another server (using other user) I can convert a local html file in PDF format, but I can't convert google page. So, who is the user who throw the thread? Can I set and modify this user?

Thanks for your help, regards

simorav
 
Posts: 9
Joined: Mon Jul 16, 2012 1:46 pm

Tue Jul 24, 2012 2:26 am

Hi simorav,

You must make sure the user is able to navigate through your google page. I am sorry for we can not modify this user and that need modify your code by yourself.

Have a great day!

Amy
e-iceblue support
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Thu Sep 20, 2012 2:41 pm

Hi,
I'm not able to load html from url (authentication problem), so now I'm trying to create PDF file starting from MemoryStream:

Code: Select all
Stream stream = file.OpenBinaryStream(SPOpenBinaryOptions.SkipVirusScan);
Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument();         
doc.LoadFromStream(stream);


but I obtain the error "Invalid/Unknown/Unsupported format".
Then I tried to use Spire.Doc dll int the same way, obtaining the error "Can't open storage on LockBytes".

Any ideas? bye

simorav
 
Posts: 9
Joined: Mon Jul 16, 2012 1:46 pm

Fri Sep 21, 2012 1:55 am

Dear simorav,

Thanks for your inquiry.
You can load html from url, we provide you a solution, please have a try. If you still have the problem, please tell us.
Code: Select all
            PdfDocument doc = new PdfDocument();
            Thread thread = new Thread(() =>
            { doc.LoadFromHTML("http://www.google.it", true, true, true); });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            doc.SaveToFile("sample.pdf");
            System.Diagnostics.Process.Start("sample.pdf");


Thanks and best regards,
Amy
e-iceblue support
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF

cron