question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

After I have run the server then it show this error, but it still run. error1

Here is my code in the API, I scared it have problem with async/await so I used .Result

[HttpGet("booking-preview/{bookingId}")]
public IActionResult GetBookingPreview(long bookingId)
{
	if (!ModelState.IsValid)
		return Ok(ModelState);

	var doc = new HtmlToPdfDocument()
	{
		GlobalSettings = {
			PaperSize = PaperKind.A3,
			Orientation = Orientation.Landscape,
		},

		Objects = {
			new ObjectSettings()
			{
				Page = "http://google.com/",
			},
			new ObjectSettings()
			{
				Page = "https://github.com/",

			}
		}
	};
	byte[] pdf = _converter.Convert(doc);
	return new FileContentResult(pdf, "application/pdf");
}

But after have called the API and then return the pdf file, I opened it by browser withBlob or using Pdf reader but it appeared blank/ not support.

error2

image

Thanks.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
rdvojmoccommented, Aug 30, 2017

Error that you marked shouldn’t have any impact on conversion process. Can you write PDF to disk on a server to confirm that there is something wrong with the library?

[HttpGet("booking-preview/{bookingId}")]
public IActionResult GetBookingPreview(long bookingId)
{
	if (!ModelState.IsValid)
		return Ok(ModelState);

	var doc = new HtmlToPdfDocument()
	{
		GlobalSettings = {
			PaperSize = PaperKind.A3,
			Orientation = Orientation.Landscape,
		},

		Objects = {
			new ObjectSettings()
			{
				Page = "http://google.com/",
			},
			new ObjectSettings()
			{
				Page = "https://github.com/",

			}
		}
	};
	byte[] pdf = _converter.Convert(doc);
       //this writes pdf to disk
        using (FileStream stream = new FileStream(@"Files\" + DateTime.UtcNow.Ticks.ToString() + ".pdf", FileMode.Create))
        {
                stream.Write(pdf, 0, pdf.Length);
         }
	return new FileContentResult(pdf, "application/pdf");
}
1reaction
rdvojmoccommented, Aug 30, 2017

Can you paste this to your browser URL box: <insert your web server address>/booking-preview/12

This will return file stream directly from your server.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot viewing PDF files on the web
In Reader or Acrobat, right-click the document window, and choose Page Display Preferences. · From the list at left, select Internet. · Deselect ......
Read more >
Can't open PDF
Right-click the PDF, choose Open With > Choose default program (or Choose another app in Windows 10). · Choose Adobe Acrobat Reader or...
Read more >
Can't Open PDF? How To Fix PDF Files Not Opening Error
Open Adobe Reader or Acrobat. · Choose Edit from the menu bar. · Select Preferences. · Choose Internet from the left sidebar. ·...
Read more >
12 Fixes to Try When Adobe Acrobat Reader Can't Open ...
12 Fixes to Try When Adobe Acrobat Reader Can't Open PDF Files on Windows · 1. Close Background Processes and Give Adobe a...
Read more >
7 Effective Methods to Fix "PDF Not Opening" Error
Part 1: Why Does "PDF Not Opening" Error Occur? · Unsupported file type: This is the most common reason you cannot open PDF....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found