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.

Wed Jul 17, 2019 6:57 pm

Code: Select all
//====================================================================================================
// use Spire.PDF to dump to user                                                               
PdfDocument pdfdoc = new PdfDocument();
PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();

//htmlLayoutFormat.FitToPage = Clip.Width; // doesn't work
htmlLayoutFormat.TrimPage = Clip.Width; // doesn't work
htmlLayoutFormat.FitToHtml = Clip.Width; // doesn't work
htmlLayoutFormat.IsWaiting = false;
PdfPageSettings settings = new PdfPageSettings();
settings.Size = PdfPageSize.Letter;
string htmlCode = Session.Contents["reportcontents"].ToString();
Thread thread = new Thread(() => { pdfdoc.LoadFromHTML(htmlCode, false, settings, htmlLayoutFormat); });
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();

MemoryStream msDoc = new MemoryStream();
pdfdoc.SaveToStream(msDoc, FileFormat.PDF);
pdfdoc.SaveToHttpResponse("report.pdf", this.Response, HttpReadType.Save);
// end output to PDF for the user
//====================================================================================================


C# in ASP.Net, developer licensed.
this does create the report and allows me to capture it with the save dialogue.
When I open the PDF, it is improperly scaled, no matter what I do, I can't get it to scale correctly.
The div it is in is set to a static width of 1400px, the table within the div is set to a static width of 1400px, the final image output is more like 700px, if that, more like 640px.
so it clips over 50% of the actual resulting information off and I am stuck with half of what I need.
Any suggestions?

JonathanWood
 
Posts: 26
Joined: Fri Feb 26, 2016 2:19 am

Thu Jul 18, 2019 8:11 am

Hi,

Thank you for contacting us.
I did notice that the settings of htmlLayoutFormat didn't take effect, the content was not scaled correctly in PDF file. The issue will be logged into our bug tracking system. If it is fixed or there is any update for you, I will let you know. In addition, could you please provide your testing HTML code, so that we can better investigate and fix the issue according to your HTML. You could send it to us via email (support@e-iceblue.com). Thanks in advance.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Thu Jul 18, 2019 12:39 pm

Code: Select all
//====================================================================================================
// use Spire.PDF to dump to user                                                               
PdfDocument pdfdoc = new PdfDocument();
PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat(); //useless
PdfPageSettings pdfSettings = new PdfPageSettings();
pdfSettings.Width = 1205; // had to use to get the results to show in pdf
pdfSettings.Height = 800;
pdfSettings.Orientation = PdfPageOrientation.Landscape;
//pdfSettings.Size= PdfPageSize.Letter;  // no way, too much shrinkage

//htmlLayoutFormat.FitToPage = Clip.Width;  // does not work
//htmlLayoutFormat.TrimPage = Clip.Width; // does not work
htmlLayoutFormat.Layout = Spire.Pdf.Graphics.PdfLayoutType.Paginate; // does not work
htmlLayoutFormat.FitToHtml = Clip.Both; // does not work

htmlLayoutFormat.IsWaiting = false;

string htmlCode = Session.Contents["reportcontents"].ToString();
Thread thread = new Thread(() => { pdfdoc.LoadFromHTML(htmlCode,false,pdfSettings,htmlLayoutFormat); });
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();

MemoryStream msDoc = new MemoryStream();
pdfdoc.SaveToStream(msDoc, FileFormat.PDF);
string reportid = Guid.NewGuid().ToString();
pdfdoc.SaveToHttpResponse(reportid+".pdf", this.Response, HttpReadType.Save);
// end output to PDF for the user
//====================================================================================================


I tried your custom plugin converter, threw it away, I can use other methods if I want to do a "File, Print, choose random PDF printer driver", what I am trying to do is in code, I need to take HTML code that exists only in memory in my program, save it to a PDF in memory, and send to the web response, note the final few lines of my code, SaveToStream, then SaveToHttpResponse, this is not a physical file to store on a hard drive location, this is in memory and I do not want to start an external viewer process, instead I want to send the resulting PDF to the web response, on a web page, the plugin has zero way of accomplishing either task, it is for windows forms where you can have a button on a windows program where a person clicks it and goes to a web page, downloads it, and saves the resulting to a PDF file, so the plugin is pointless for the web, plus, if a person is doing that, there is a simple way to do it anyway without the plugin, they just use the built in visual studio tools to accomplish that task with zero overhead.

I need the FitToPage, TrimPage, FitToHtml all working plus I need the Layout Paginate working so it allows me to break per page so all the features that Spire.PDF is supposed to have working, working, on the HTML to PDF tools, I have given code many times here and you can copy / paste and try.

JonathanWood
 
Posts: 26
Joined: Fri Feb 26, 2016 2:19 am

Fri Jul 19, 2019 2:52 am

Dear Jonathan,

Thanks for your feedback.
In our plugin method, there is no direct SaveToHttpResponse method, but it supports saving HTML to PDF stream. And you can then save the stream to client through Response. See the following code. If there is still any question, please provide your testing HTML code for a better investigation.
BTW, I have posted the issue that the htmlLayoutFormat setting (FitToPage, TrimPage, FitToHtml) didn't work to our Dev team for investigating and fixing. If there is any update, I will inform you.
Code: Select all
 MemoryStream stream = new MemoryStream();
//convert HTML to PDF stream
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(htmlCode, stream,

     //enable javascript
     true,

     //load timeout
     100 * 1000,

     //page size
     PdfPageSize.A4,

     //page margins
     new PdfMargins(0, 0),
     LoadHtmlType.SourceCode);
//save the stream to client through Response
string fileName = "nina.pdf";
byte[] bytes = new byte[(int)stream.Length];
stream.Position = 0;
stream.Read(bytes, 0, bytes.Length);
stream.Close();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;  filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Fri Jul 19, 2019 3:29 pm

Current version of the plugin does not support this code you posted
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert
does not support stream and html code, it only supports URL and path

JonathanWood
 
Posts: 26
Joined: Fri Feb 26, 2016 2:19 am

Mon Jul 22, 2019 3:16 am

Hello,

Thanks for your feedback and sorry for late reply as weekend.
There might be something wrong on your side. I can save the HTML code to Pdf stream well. Here I uploaded my testing application. Please check it on your side. If there is any question, please provide your HTML code to help us have a better investigation. Thanks in advance.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Tue Jul 23, 2019 2:08 pm

I took your project, unzipped it, put it on the IIS server, made it a web app, ran it, and it blew up with an error on the same Convert method, I have posted that error information in the other thread about the problem with the converter. You must have something registered on your computer for a different library than what is in the project folder or a different version of the same library, but your project, zero changes, doesn't work.

JonathanWood
 
Posts: 26
Joined: Fri Feb 26, 2016 2:19 am

Wed Jul 24, 2019 3:08 am

Hi,

Thanks for your feedback.
When deploying the application on IIS, please set "Enable 32-Bit Applications" to be True in your IIS Application Pools Settings. After setting, I can deploy my application on IIS successfully. Please have a test on your side. If the issue still happens, please provide the following information to help us further investigate your issue.
1. If you don't deploy the application on IIS, just run it on local, will the issue happen?
2. Please provide your testing environment, such as Server 2012 R2.
3. Please share some screenshots showing your IIS settings.
I'm looking forward to your reply.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.PDF