C# Rotativa ActionAsPDF change text-direction right to left - c#

i use Rotativa.ActionAsPdf to convert View to Pdf it works perfectly
but the problem how to change text-direction right to left?
here my code:
public ActionResult ExportPDF(ReportsModel RM)
{
string id = Session["Pat_id"].ToString();
string subPath = "~/Attachment/" + id;
string link;
bool exists = System.IO.Directory.Exists(Server.MapPath(subPath));
if (!exists)
System.IO.Directory.CreateDirectory(Server.MapPath(subPath));
return new Rotativa.ActionAsPdf("PhysicalExaminationSummaryToPDF", new { id = id })
{
FileName = "PhysicalExaminationSummary.pdf",
PageSize = Rotativa.Options.Size.Letter,
PageMargins = { Left = 0, Right = 0 }
};
}

Finnaly I solve it
should to add in view style direction:rtl
<style>
#status_quest {
direction:rtl;
}
</style>
when convert view to Pdf does not relate to CSS libraries

Related

Display dynamic header using Rotativa pdf in MVC net core

I want to display dynamic header in a cshtml. When i try to pass it using CustomSwitches i get an error like QPaintDevice: Cannot destroy paint device that is being paintedpure virtual method called terminate called without an active exception.
Calling Rotativa component(it's in a class library) from mvc Controller to print the dynamic view without header works correctly but not with the header. Is there anyway to solve this problem?
Thank you for your answers.
Edit: Example using Rotativa
string header = $"/Header.cshtml";
var customSwitches = string.Format("--header-html "{0}" " + "--header-spacing "0" ", header);
var view = new ViewAsPdf(pdfView.ToViewRoute(culture), model: viewModel)
{
PageOrientation = option.PageOrientation,
IsGrayScale = option.IsGrayScale,
MinimumFontSize = option.MinimumFontSize,
PageSize = option.PageSize,
PageMargins = option.PageMargins,
CustomSwitches = customSwitches
};
return view;
customSwitches may not find /header.cshml. You need to give the correct path.
[HttpGet]
public IActionResult Pdf()
{
string customSwitches = string.Format(" --print-media-type --page-offset 2 --footer-center [page] --allow {0} --footer-html {0} --footer-spacing -180 ",
Url.Action("header", "home", new { area = "" }, "https"));
var pageList = new List<tbpage>();
pageList.Add(new tbpage()
{
page_name = "1",
page_no = "a"
});
return new ViewAsPdf("PdfDemo", model: pageList)
{
PageOrientation = Rotativa.AspNetCore.Options.Orientation.Portrait,
IsGrayScale = true,
MinimumFontSize = 20,
PageSize = Rotativa.AspNetCore.Options.Size.A5,
PageMargins = { Left = 20, Bottom = 20, Right = 20, Top = 20 },
CustomSwitches = customSwitches
};
}
Model
public class tbpage
{
public string page_name { get; set; }
public string page_no { get; set; }
}
Pdf
In addition, if it is still incorrect, please add [AllowAnonymous] to the action Header. You can also refer to answer.
[AllowAnonymous]
public ActionResult Header()
{
return View();
}

How to run #Url.action written by string

I am trying to show image from database with #Url.Action method. The html document is also in database and I render it with #html.Raw function.
The problem is when I render the html including #Url.Action method it just show the whole function shape in the source parameter. The code I tried is below.
private string ConvertImageSource(int articleID, string content // the html string)
{
var imageCount = // counting number of image;
for (int i = 0; i < imageCount; i++)
{
content = content.Replace($"<!{i + 1}>", $"#Url.Action('ShowImage','Articles',new{{articleID={ articleID },imageID={ imageID }}})");
}
return content;
}
public ActionResult ShowImage(int? articleID, int? imageID)
{
var imageData = Encoding.ASCII.GetBytes(// get image string from database);
return new FileStreamResult(new MemoryStream(imageData), "image/jpeg");
}
I would like to know how to make it works. Any idea?
You may use that for loop on a partial view.
Looks like..
#model MyContentModel
#for (int i = 0; i < model.ImageCount; i++){{
#Url.Action("ShowImage", "Articles", new {{ articleID ={ model.ArticleID },imageID ={ model.ImageID } }})}}
Thanks for the answer. I found the solution by myself.
Instead of #Url.Action function, I put url address and it works.
private string ConvertImageSource(int articleID, string content)
{
var imageCount = content.Split(new string[] { "img " }, StringSplitOptions.None).ToList().Count - 1;
for(int i = 0; i < imageCount; i++)
{
content = content.Replace($"<!{i + 1}>", $"/Articles/ShowImage?articleID={ articleID }&imageID={i + 1}");
}
return content;
}

save generated pdf on server

I'm generating pdf from view using ROTATIVA
public ActionResult StandartPDF()
{
var makeCvSession = Session["makeCV"];
var something = new Rotativa.ViewAsPdf("StandartPDF", makeCvSession) { FileName = "cv.pdf" };
return something;
}
using that code user can download it. But at first I want to it on server. How can I do that?
I solved that using SaveOnServerPath property in Rotativa class
public ActionResult StandartPDF()
{
var makeCvSession = Session["makeCV"];
var root = Server.MapPath("~/PDF/");
var pdfname = String.Format("{0}.pdf", Guid.NewGuid().ToString());
var path = Path.Combine(root, pdfname);
path = Path.GetFullPath(path);
var something = new Rotativa.ViewAsPdf("StandartPDF", makeCvSession) { FileName = "cv.pdf", SaveOnServerPath = path };
return something;
}

asp.net mvc 4 accessing websecurity.Getuserid(user.identity.name)

I am trying to access to the user id that is currently logged on...
I have two controllers, LicencaController and ProcessoController.
In the ProcessoController there is a function that saves the user id and some other stuff,
this function was private, but in order to gain access I have change it to public..
Now in a function in the controller Licenca I instaciate an object ProcessoController and called the function on the ProcessoController...
The problem is that user.identity.name is null.
If from the ProcessoController I call the function to save the user id , user.identity.name gives me the username...
If from the LicencaController I call the function to save the user id that is declared in the ProcessoController, it gives me null...
I have tried other solutions like the one in this topic:
Authentication issue when debugging in VS2013 - iis express
but it's not working...
Is it possible to do this?
What is the problem?
Thanks in advance...
Here goes the code:
Fucntion SaveProcessoSoftware in the controller ProcessoProduto
public string SaveProcessoSoftware(int iIDProcesso, int iIDSoftware, int iIDTipoLicenciamento,
List<string> NomeVariaveis, List<string> ValorVariaveis, string sNrFactura, string sIDLicencaInicial, string sDescricaoTipoSoftware)
{
int iIDFactura = GetIDFactura(sNrFactura);
string sIDLicenca = SetLicenca(iIDSoftware, sIDLicencaInicial, sDescricaoTipoSoftware);
ProcessoProdutos objProcSoft = new ProcessoProdutos();
objProcSoft.IDProcesso = iIDProcesso;
objProcSoft.IDLicencaSoftware = sIDLicenca;
objProcSoft.IDFactura = iIDFactura;
objProcSoft.Rem = 0;
objProcSoft.IDU = WebSecurity.CurrentUserId;// .GetUserId(User.Identity.Name);
objProcSoft.TStamp = GetDateTimeFromSqlSytem();
db.ProcessoProdutos.Add(objProcSoft);
db.SaveChanges();
if (NomeVariaveis != null)
SaveVariaveis(sIDLicenca, iIDTipoLicenciamento, NomeVariaveis, ValorVariaveis);
return sIDLicenca;
}
Function SetLicenca...this is function where i save the user id...
public string SetLicenca(int iIDSoftware, string sIDLicenca, string sDescricaoTipoSoftware)
{
string LastTableIDLicenca = "";
Licenca Lic = new Licenca();
Lic.IDProduto = iIDSoftware;
Lic.Estado = 4;
Lic.Observacoes = "";
Lic.DataValidade = DateTime.MaxValue;
Lic.Validado = 2;
Lic.IDValidado = 0;
Lic.IDTitular = 0;
Lic.Rem = 0;
Lic.IDU = WebSecurity.GetUserId(User.Identity.Name);<---error
Lic.TStamp = GetDateTimeFromSqlSytem();
Lic.IDLicenca = new Licenciamento_v2.Areas.Idonic.IDLicencaGenerator().GenerateCharID(8);
db.Licencas.Add(Lic);
int t = SaveLicenca();
if (t == -1)
SetLicenca(iIDSoftware, sIDLicenca, sDescricaoTipoSoftware);
else
{
LastTableIDLicenca = Lic.IDLicenca;
//obter o id introduzido e actualizar o campo idInicial
if (sDescricaoTipoSoftware.Equals("Software") == true)
{
Lic = db.Licencas.Find(LastTableIDLicenca);
if (sIDLicenca != "")
{
Licenca LicAnt = db.Licencas.Find(sIDLicenca);
Lic.IDInicial = LicAnt.IDInicial;
}
else
{
Lic.IDInicial = LastTableIDLicenca;
}
db.SaveChanges();
}
}
return LastTableIDLicenca;
}
From LicencaController i do this:
public void SaveSoftwareToLicenca()
{
int sessionIDProcesso = (int)Session["EditIDProcesso"];
ProcessoController procCont = new ProcessoController();
procCont.ChangeProcessoProdutoStatus(sessionIDProcesso, t.rowId, 1);
procCont.ChangeLicencaEstado(t.rowId, 3);
procCont.ChangeLicencaVariaveisStatus(t.rowId, 1);
Session["IDLicenca"] = procCont.SaveProcessoSoftware(sessionIDProcesso, t.row.IDSoftware, t.row.IDNivelDeLicenciamento, t.row.NomeVariaveis, t.row.ValorVariaveis, t.row.NumeroFactura, t.row.IDLicenca, t.row.DescricaoTipoDeSoftware);
}
Thanks again for the help..

How to create OneNote 2010 section

How can you create a new section in a OneNote 2010 notebook with c#? According to the API there is no method to do so. But there is a CreateNewPage Method so I wondering if there is something similiar for sections? If not, how can this be achieved except for manipulating the XML files (which is a task i'd like to avoid since I'm not experienced in it)?
Here is code snippet from my add on:
public bool AddNewSection(string SectionTitle, out string newSectionId)
{
try
{
string CurrParentId;
string CurrParentName;
string strPath;
CurrParentId = FindCurrentlyViewedSectionGroup(out CurrParentName);
if (string.IsNullOrWhiteSpace(CurrParentId) || string.IsNullOrWhiteSpace(CurrParentName))
{
CurrParentId = FindCurrentlyViewedNotebook(out CurrParentName);
if (string.IsNullOrWhiteSpace(CurrParentId) || string.IsNullOrWhiteSpace(CurrParentName))
{
newSectionId = string.Empty;
return false;
}
strPath = FindCurrentlyViewedItemPath("Notebook");
}
else
strPath = FindCurrentlyViewedItemPath("SectionGroup");
if (string.IsNullOrWhiteSpace(strPath))
{
newSectionId = string.Empty;
return false;
}
SectionTitle = SectionTitle.Replace(':', '\\');
SectionTitle = SectionTitle.Trim('\\');
strPath += "\\" + SectionTitle + ".one";
onApp.OpenHierarchy(strPath, null, out newSectionId, Microsoft.Office.Interop.OneNote.CreateFileType.cftSection);
onApp.NavigateTo(newSectionId, "", false);
}
catch
{
newSectionId = string.Empty;
return false;
}
return true;
}
Basically what I am doing here is to get the path of currently viewing Section Group or Notebook and then adding new section name to that path and then calling OpenHierarchy method. OpenHierarchy creates a new section with title provided and returns it's id.
Following is where I create a new section and Navigate to it:
onApp.OpenHierarchy(strPath, null, out newSectionId, Microsoft.Office.Interop.OneNote.CreateFileType.cftSection);
onApp.NavigateTo(newSectionId, "", false);
So can write something like:
static void CreateNewSectionMeetingsInWorkNotebook()
{
String strID;
OneNote.Application onApplication = new OneNote.Application();
onApplication.OpenHierarchy("C:\\Documents and Settings\\user\\My Documents\\OneNote Notebooks\\Work\\Meetings.one",
System.String.Empty, out strID, OneNote.CreateFileType.cftSection);
}

Categories

Resources