C # – how can you generate pdf with image with blazor and asp.net core 3.1?

Hello Community I have created a test PDF with blazor and asp.net core 3.1 and it already works correctly, but I encountered a problem where I wanted to add an image and I wanted to use it IWebHostEnvironment and use your property webRootPath But as you know, this is inserted into a controller as a dependency. The detail is that I don't use a controller to create my PDF and I have to use it
webRootPath to extract the image from a folder in wwwroot How can I extract the image and place it in the PDF?

I would like to put the picture here: _env it should come from IWebHostEnvironment

 private PdfPTable AddLogo()
        {
            int maxColumn = 1;
            PdfPTable pdfPTable = new PdfPTable(maxColumn);
            string path = _env.WebRootPath + "/LogoPDF";
            string imgCombine = Path.Combine(path, "logo.jpg");
            Image img = Image.GetInstance(imgCombine);

            _pdfCell = new PdfPCell(img);
            _pdfCell.Colspan = maxColumn;
            _pdfCell.HorizontalAlignment = Element.ALIGN_LEFT;
            _pdfCell.Border = 0;
            _pdfCell.ExtraParagraphSpace = 0;
            pdfPTable.AddCell(_pdfCell);

            pdfPTable.CompleteRow();
            return pdfPTable;
        }

I have pasted this code into a Javascript document:

function saveAsFile(filename, bytesBase64) {
    var link = document.createElement('a');
    link.download=filename;
    link.href = "data:application/octet-stream;base64," + bytesBase64;
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
}

Then I created a class for a student model and added the generatepdf method:

public class Student
    {
        public int StudentId { get; set; } = 0;
        public string Name { get; set; } = "";
        public string Roll { get; set; } = "";

        public void GeneratePDF(IJSRuntime js)
        {
            List oStudents = new List();
            for (int i = 1; i <= 9; i++)
            {
                oStudents.Add(new Student()
                {
                    StudentId = i,
                    Name = "Stu" + i,
                    Roll = "100" + i
                });
            }

            Rptstudent oRpstStudent = new Rptstudent();
            js.InvokeAsync("saveAsFile", "Reporte.pdf", Convert.ToBase64String(oRpstStudent.Report(oStudents)));
        }
    }

here i have built my pdf into a class called rptsutedent:

public class Rptstudent
    {
        #region Declararion
        int _maxColum = 3;
        Document _document;
        PdfPTable _pdfTable = new PdfPTable(3);
        PdfPCell _pdfCell;
        Font _fontstyle;
        MemoryStream _memoryStream = new MemoryStream();
        List _oStudents = new List();
        #endregion

        public byte()Report(List oStudents)
        {
            _oStudents = oStudents;

            _document = new Document(PageSize.A4, 10f, 10f, 20f, 30f);
            _pdfTable.WidthPercentage = 100;
            _pdfTable.HorizontalAlignment = Element.ALIGN_LEFT;
            _fontstyle = FontFactory.GetFont("Tahoma", 8f, 1);
            PdfWriter.GetInstance(_document, _memoryStream);
            _document.Open();

            float() sizes = new float(_maxColum);
            for(var i = 0; i < _maxColum; i++)
            {
                if (i == 0) sizes(i) = 50;
                else sizes(i) = 100;
            }
            _pdfTable.SetWidths(sizes);

            this.ReportHeader();
            this.ReportBody();

            _pdfTable.HeaderRows = 2;
            _document.Add(_pdfTable);
            _document.Close();
            return _memoryStream.ToArray();
        }

        private void ReportHeader()
        {
           // _pdfCell = new PdfPCell(this.AddLogo());//agregar logo
            _fontstyle = FontFactory.GetFont("Tahoma", 18f, 1);
            _pdfCell = new PdfPCell(new Phrase("Reporte", _fontstyle));
            _pdfCell.Colspan = _maxColum;
            _pdfCell.HorizontalAlignment = Element.ALIGN_CENTER;
            _pdfCell.Border = 0;
            _pdfCell.ExtraParagraphSpace = 0;
            _pdfTable.AddCell(_pdfCell);
            _pdfTable.CompleteRow();

            _pdfCell = new PdfPCell(new Phrase("Información del estudiante", _fontstyle));
            _pdfCell.Colspan = _maxColum;
            _pdfCell.HorizontalAlignment = Element.ALIGN_CENTER;
            _pdfCell.Border = 0;
            _pdfCell.ExtraParagraphSpace = 0;
            _pdfTable.AddCell(_pdfCell);
            _pdfTable.CompleteRow();
        }

        private PdfPTable AddLogo()
        {
            int maxColumn = 1;
            PdfPTable pdfPTable = new PdfPTable(maxColumn);
            string path = _env.WebRootPath + "/LogoPDF";
            string imgCombine = Path.Combine(path, "logo.jpg");
            Image img = Image.GetInstance(imgCombine);

            _pdfCell = new PdfPCell(img);
            _pdfCell.Colspan = maxColumn;
            _pdfCell.HorizontalAlignment = Element.ALIGN_LEFT;
            _pdfCell.Border = 0;
            _pdfCell.ExtraParagraphSpace = 0;
            pdfPTable.AddCell(_pdfCell);

            pdfPTable.CompleteRow();
            return pdfPTable;
        }

        private void ReportBody()
        {
            _fontstyle = FontFactory.GetFont("Tahoma", 9f, 1);
            var fontStyle = FontFactory.GetFont("Tahoma", 9f, 0);

            #region Table Header
            _pdfCell = new PdfPCell(new Phrase("ID", _fontstyle));
            _pdfCell.HorizontalAlignment = Element.ALIGN_CENTER;
            _pdfCell.VerticalAlignment = Element.ALIGN_MIDDLE;
            _pdfCell.BackgroundColor = BaseColor.Gray;
            _pdfTable.AddCell(_pdfCell);

            _pdfCell = new PdfPCell(new Phrase("Nombre del estudiante", _fontstyle));
            _pdfCell.HorizontalAlignment = Element.ALIGN_CENTER;
            _pdfCell.VerticalAlignment = Element.ALIGN_MIDDLE;
            _pdfCell.BackgroundColor = BaseColor.Gray;
            _pdfTable.AddCell(_pdfCell);

            _pdfCell = new PdfPCell(new Phrase("Rol del estudiante", _fontstyle));
            _pdfCell.HorizontalAlignment = Element.ALIGN_CENTER;
            _pdfCell.VerticalAlignment = Element.ALIGN_MIDDLE;
            _pdfCell.BackgroundColor = BaseColor.Gray;
            _pdfTable.AddCell(_pdfCell);

            _pdfTable.CompleteRow();
            #endregion

            #region Table Body
            int nSL = 1;
            foreach(var oStudent in _oStudents)
            {

                _pdfCell = new PdfPCell(new Phrase(nSL++.ToString(), fontStyle));
                _pdfCell.HorizontalAlignment = Element.ALIGN_CENTER;
                _pdfCell.VerticalAlignment = Element.ALIGN_MIDDLE;
                _pdfCell.BackgroundColor = BaseColor.White;
                _pdfTable.AddCell(_pdfCell);

                _pdfCell = new PdfPCell(new Phrase(oStudent.Name, fontStyle));
                _pdfCell.HorizontalAlignment = Element.ALIGN_CENTER;
                _pdfCell.VerticalAlignment = Element.ALIGN_MIDDLE;
                _pdfCell.BackgroundColor = BaseColor.White;
                _pdfTable.AddCell(_pdfCell);

                _pdfCell = new PdfPCell(new Phrase(oStudent.Roll, fontStyle));
                _pdfCell.HorizontalAlignment = Element.ALIGN_CENTER;
                _pdfCell.VerticalAlignment = Element.ALIGN_MIDDLE;
                _pdfCell.BackgroundColor = BaseColor.White;
                _pdfTable.AddCell(_pdfCell);

                _pdfTable.CompleteRow();
            }
            #endregion
        }
    }

and finally I added the following to the shaving side:

@page "/generar-pdf"
@using BlazorApp.Client.Data
@inject IJSRuntime js

Generar PDF

@code { private void GeneratePDFFile() { Student student = new Student(); student.GeneratePDF(js); } }

Probability – Conditional PDF and CDF problem

I have a problem below:

The probability density function (PDF) of the random variable X is

$$
f_X (x) = begin {cases}
1- | x | & text {| x | <1} \
0 & text {else} end {cases}
$$

a. Find and outline X's cumulative distribution function (CDF).

b. Calculate the probability that | x | > = 1/2.

c. Calculate the conditional probability density function
$$
f_ {X || X | ≥ 1/2} (x || X | ≥ 1/2)
$$

d. Calculate and outline the conditional cumulative distribution function (CDF).
$$
F_ {X || X | ≥ 1/2} (x│ | X | ≥ 1/2) = P (X <x || X | ≥ 1/2)
$$

I can solve one. and B. P (| x |> = 1/2) = 1/4. But for c. and d., I got confused about the condition term (| X |> = 1/2) and don't know how to solve it.

PDF JavaScript Validation – Dynamic form filling

I am working on a form to dynamically fill in multiple objects in the form. I am currently using the validation JavaScript to do this. I was able to create dropdowns dynamically, but when I added a text box that I wanted to fill in, it stopped working. I think I'm using the wrong method. Help?

That worked:

switch (event.value) {

case "-----":
    this.getField("Test_Label_two")
        .setItems(("-----"));
        break;

case "First":
    this.getField("Test_Label_two")
        .setItems(("One.one", "One.two", "One.three"));
        break;

This did not:

switch (event.value) {

case "-----":
    this.getField("Test_Label_two")
        .setItems(("-----"));
        break;

case "First":
    this.getField("SomeTxtBx") //This is a text box
        .setValue("TestOne"); // Also tried .setText
    this.getField("Test_Label_Two") // This is a dropdown menu
        .setItems(("1", "2"));
        break;

Sell ​​- KCR Converter Convert Kindle Cloud Reader to DRM-free PDF, EPUB, Mobi, AZW3, TXT with 1 click. | Proxies-free

Hi Guys! I'm selling
Epubor KCR Converter 1.0.1.192

A clear and simple tool that allows you to extract Kindle books from the Kindle Cloud Reader and then convert the Kindle Cloud Reader to the popular ePub / Mobi / AZW3.

Features and characteristics:

  • Requirements: Use Chrome to access Kindle Cloud Reader, ensure offline reading, downloading, and pinning books.
  • Remove DRM directly from Kindle Cloud Reader. You don't need to install the Kindle desktop app or use the Kindle e-ink device.
  • The easiest way to remove Kindle DRM and convert Kindle eBooks.
  • License details:1 year license with free updates and support
  • System requirements:
    Windows Vista / 7/8/10

Price: $ 5

PayPal – (Email protected)

After receipt of payment write the postal address in PM, I will send you the program.

Convert Kindle Cloud Reader to PDF / EPUB / Mobi / AZW3 / TXT with just one click
No installation of Kindle for PC / Mac No need for a Kindle eReader

KCR Converter is a lightweight tool that allows you to export Kindle books from Kindle Cloud Reader, remove the copy protection from Digital Rights Management, and convert your Kindle books to PDF, EPUB, MOBI, TXT, or AZW3 format can. Simply open KCR Converter, select the output format and click the “Convert” button. The books you downloaded from Kindle Cloud Reader are converted to DRM-free files in the format you choose.

With this clear and simple tool, you can read Kindle books on any e-book reader and have complete control over your Kindle books by backing them up to your computer permanently.

How do I download Kindle books from Kindle Cloud Reader?

Step 1. Install the Google Chrome browser if you don't already have it.

Step 2. Add the Kindle Cloud Reader Chrome extension to your Chrome browser.

Step 3. Sign in to your Amazon Kindle Cloud Reader in the Chrome browser.

Step 4. Right click on the Kindle book and select "Download & Pin Book".

Step 5. The Kindle book is then displayed on the Downloaded tab with the green icon under the book cover.

.

How do I convert Kindle Cloud Reader to PDF / EPUB / Mobi / AZW3?
Step 1. Start the KCR converter. All Kindle books that you have downloaded and pinned will automatically appear in the KCR Converter main window.

Step 2. Check the box on the left side of the books you want to compile
Invert the output format and click the "Convert to …" button to start the conversion.

Read more here – epubor.com/kcr-converter.html

.

Web forms – Twig if statement does not work as expected in the PDF attachment

if statements generate an error saving the Twig template in an attachment PDF file, complaining that the elements (YAML) are invalid and the line cannot be parsed with the if statement.

Update: I later found that {% for%} worked, but {% set%} didn't. Maybe there is something about entity print support for Twig or Webform … hard to say.

Test work

The following statement works in a Twig template that is used for the text of an email handler.

{% if data.checkbox%}
game
{% else%}
no agreement
{% endif%}

Test fails

The same code in an attachment PDF file generates an error.

.htaccess – [WordPress][htaccess] Prevent unregistered users from accessing PDF, Doc, DocX and Odt files

I have the following code on my htaccess, it works for all users, but I only want to deny access for non-logged in WordPress users. Can someone help me? Thanks a lot!

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^http://(www.)?localhost (NC) 
RewriteCond %{HTTP_REFERER} !^http://(www.)?localhost.*$ (NC) 
RewriteRule .(pdf|doc|docx|odt)$ - (F)

Convert LZW code to convert it to PDF in JAVA

I have this case: with soap, I use a service that answers me in the end with a PDF document. In the SOAP UI system, access is easy in the "Appendix" section. However, when I implement it in a JAVA class, the attached picture answers me. This is LZW code. How can I analyze it to convert it to a PDF document? At the moment I only have the call where everything is stored in the variable "res".

SoapHttpClientString soapHttpCliente = new SoapHttpClientString (SERVICE_URL, SOAP_ACTION, CONTENT_TYPE, soapEnvelope, soapHeader, soapBody, soapEnvelopeEnd);
String res = soapHttpCliente.execute ();