Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 months ago.
Improve this question
I've got an API where I accept a stream representing an image (usually about ~3mb) and I write this stream into a file. When I test this locally with postman, writing the stream into the file takes about ~20ms. However, when deploying this to production this process takes around 1000ms.
Guid guid = Guid.NewGuid();
string input = InputPathWithExtension(guid);
string output = OutputPathWithExtension(guid);
using FileStream file = File.OpenWrite(input);
await stream.CopyToAsync(file);
await stream.DisposeAsync();
await file.DisposeAsync();
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Is there a way to convert a PDF page to bitmap in c#? I tried with Ghostscript but I think it is file based. Thanks in advance.
LibPdf
This library converts converts PDF file to an image. Supported image formats are PNG and BMP, but you can easily add more.
using (FileStream file = File.OpenRead(#"..\path\to\pdf\file.pdf")) // in file
{
var bytes = new byte[file.Length];
file.Read(bytes, 0, bytes.Length);
using (var pdf = new LibPdf(bytes))
{
byte[] pngBytes = pdf.GetImage(0,ImageType.BMP); // image type
using (var outFile = File.Create(#"..\path\to\pdf\file.bmp")) // out file
{
outFile.Write(pngBytes, 0, pngBytes.Length);
}
}
}
Read this article: PDF to bmp Images (12 pages = 12 images)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'd like to download the daily photo from this site but i can't use the JPEG's URL because it changes everyday.
Is there any way to download object from site using the page URL and XPath? I tried to find some method in WebClient but with no luck.
An example of my comment with HTML Agility Pack :
WebClient client = new WebClient();
string resource = client.DownloadString("http://photography.nationalgeographic.com/photography/photo-of-the-day/");
HtmlAgilityPack.HtmlDocument html = new HtmlAgilityPack.HtmlDocument();
html.LoadHtml(resource);
var imgDiv = html.DocumentNode.SelectSingleNode("//*[contains(#class,'primary_photo')]");
var imgSrc = imgDiv.SelectSingleNode("//img/#src");
string relativePath = imgSrc.GetAttributeValue("src", "");
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am trying to Convert a MVC 4 View to a PDF. I have no idea where to start, after searching google i found ItextSharp and have been playing around with it.
My View is fairly Simple it has a Map and a Table. i would like to just call an action in the controller and have it print my web page.
Any Advice would be greatly Appreciated
You can use Rotativa
public ActionResult TestViewWithModel(string id)
{
var model = new TestViewModel {DocTitle = id, DocContent = "This is a test"};
return new ViewAsPdf(model);
}
public ActionResult PrintIndex()
{
return new ActionAsPdf("Index", new { name = "Giorgio" }) { FileName = "Test.pdf" };
}
It uses wkhtmltopdf under the hood.
wkhtmltopdf and wkhtmltoimage are open source (LGPLv3) command line
tools to render HTML into PDF and various image formats using the QT
Webkit rendering engine. These run entirely "headless" and do not
require a display or display service.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to get 2 parametrs from windows phone 8 to php index file , with get or post method
any solutions?
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += (s, e) =>
{
};
webClient.DownloadStringAsync(new Uri(String.Format("http://example.com?par1={0}&par2={1}", "param1", "param2"), UriKind.RelativeOrAbsolute));
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have the following situation:
A document view where user can upload multiple files. A one(Document) to many(files) relationship. All these files are "inside" the document by its IDDocument property.
The user will make loads of .xml files upload, each file upload fires that Action in my controller:
[HttpPost]
public ActionResult ProcessSubmitUpload(HttpPostedFileBase attachments, Guid? idDocument)
{
//Validations
var xmlDocument = XDocument.Load(attachments.InputStream);
if (xmlDocument.Root.Name.LocalName == "cteProc")
{
if (DocumentCommonHelper.SendXmlViaWebService(xmlDocument))
{
_documentRepository.UpdateDocumentStatus(StatusOption.DocumentApproved);
}
else
{
_documentRepository.UpdateDocumentStatus(StatusOption.DocumentPending);
}
}
}
The logic is: If all files go correctly in the DocumentCommonHelper.SendXmlViaWebService(xmlDocument) , the document status must be Approved. But if one single file fails, the document status must be Pending.
The problem is that approach in this code is wrong. Because its changing the status of the document each time that the Action is executed, forgeting the others HttpPostedFileBase that are passed before.
What is the best way to do that?
Try to store the HttpPostedFileBase in the Session and retrieve them back when you need it
Session["HttpPostedFileBase"] = attachments;