asp.net-web-api


ASP.NET Web Api pdf with embedded images download


I'm using the below code to get the byte array that also contains images from a business class.
byte[] fileBytes = accountBusiness.DownloadInvoice(user.Id, invoiceId).ToArray();
Also, Please find below code that is used to generate pdf with embedded images
public HttpResponseMessage DownloadInvoice(string invoiceId)
{
try
{
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);
ApplicationUser user = HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(HttpContext.Current.User.Identity.GetUserId());
MyAccountBusiness accountBusiness = new MyAccountBusiness();
byte[] fileBytes = accountBusiness.Download(user.Id, invId).ToArray();
Stream stream = new MemoryStream(fileBytes);
response.Content = new StreamContent(stream, fileBytes.Length);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = accountBusiness.FileName + ".pdf";
return response;
}
catch (Exception ex)
{
logger.Error("Exception: " + ex.Message + "\n Inner Exception:" + ex.InnerException?.Message);
return null;
}
}
The underlying business class embeds an image like this:
sb.Append("<tr><td width='50%' align='left'><img src=" + Imgpath + ">
However, I'm getting the images are not being displayed in the pdf and also pdf is not being generated correctly. Please help

Related Links

How to return file from ASP.net 5 web api
Is WebAPI hosted outside of application pool process?
How to configure a named resource stream using OData in ASP.NET Web API
How to return xml or json with ASP.NET web mvc 6 depending on Accept Header
Kendo UI GRID with web api paging
Web Api with Sitecore 8.1
Autofac PerLifetimeScope vs PerRequest in web applications
Value cannot be null. Parameter name: value, while calling httppost via ajax post
Getting 417 error for Web API POST method
EF 6 Rollback and Update Best Approach
CORS header not being set
How to post a string to web API controller?
Service Fabric hosted Web API
Cannot change parameter in C# WebApi async method
Swagger issue with Autofac
How to configure SSL on a self hosted Web API in Azure Service Fabric

Categories

HOME
service-worker
mjml
yahoo-finance
replace
mips
retrofit2
discrete-mathematics
minecraft-forge
commonjs
text-mining
activecollab
stellar.js
docx
symbol
bitnami
symfony-2.8
wolframalpha
swagger-2.0
has-and-belongs-to-many
outliers
ms-access-2003
paperjs
playstation-portable
hard-drive
raft
sim-toolkit
openproject
google-knowledge-graph
git-rewrite-history
ods
loading
magento-1.9.3
dbnull
lpsolve
x++
fwrite
serde
globalize
user-defined-fields
datamaps
arq
wpas
arules
bbpress
janus
universal-analytics
change-tracking
latin
iotivity
tinkerpop3
drawstring
wso2developerstudio
shopping
embedding
nservicebus5
libav
blitline
highland.js
visual-sourcesafe-2005
mod-proxy
lasso
dulwich
snoop
mmwormhole
pseudo-class
deform
iso-prolog
formview
dsym
qscrollarea
bin
notorm
jquery-1.9
actiondispatch
insert-id
swfobject
joomla3.1
jquery-blockui
zope.interface
rmiregistry
correlated-subquery
window-decoration
fitbounds
infobright
stress
urlrewriter
flex-mobile
automationelement
drawtobitmap
mbeans
xui
dataform
nhprof
cac
updatesourcetrigger
vs-android
qtabbar
feasibility
mathematical-notation
dojo-dnd
sifr3
technical-debt
lemmatization

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App