Как получить два действия за один шаг - PullRequest
0 голосов
/ 29 января 2019

Прямо сейчас у меня есть index.cshtml с html.actionLink для предварительного просмотра html-таблицы, которая извлекает данные из формы, чтобы подготовиться к ее печати.Затем, когда я нажимаю на ссылку, она переходит к предварительному просмотру файла PDFOnePage.cshtml с HTML.Тогда есть кнопка, чтобы получить это к методу abcpdf, чтобы напечатать это.Я хотел бы получить оба действия за один шаг из index.cshtml.

Это часть моего index.cshtml со ссылкой:

   <td>
            @Html.ActionLink("Edit", "Edit", new { id = item.ID }) |

            @Html.ActionLink("PDF", "PDFOnePage", new { id = item.ID }) 
   </td>

Затем, когда я нажимаю ссылку PDF, он показывает HTML перед печатью.

PDFOnePage.cshtml выглядит так:

   <table frame="box" style="width:100%; border-collapse:separate">
        <tr>
            <td colspan="3"> <b>BlahBlahBlahLotsOfStuff</b></td>
        </tr>
   </table>


<button>
    <a href="@Url.Action("HmtltoPDF2","Applicant")">Export PDF</a>
   </button>

Так что, когда мы нажимаем эту кнопку, он показывает PDF, и когда я нажимаю Ctrl-p, он вызывает графический интерфейс печати. ​​

Эта кнопка обращается к моему методу ApplicantController.cs:

public FileStreamResult HmtltoPDF2()
        {
            //getting the url to convert to pdf
            String PreviousPage = System.Web.HttpContext.Current.Request.UrlReferrer.AbsoluteUri;


            //abcpdf was annoying for not accepting the Url directly 
            //so just make a string variable to assign the value of the url
            // DO NOT delete this and use PreviousPage directly
            //it will break the PDF Convertion.
            String HtmlToPDFConvertion = PreviousPage;
            MemoryStream m = new MemoryStream();
            Doc theDoc = new Doc();
            theDoc.MediaBox.String = "A4";
            theDoc.FontSize = 8;
            //theDoc.Rect.Inset(114, 162);
            theDoc.Rect.Inset(15, 1);

            theDoc.HtmlOptions.Engine = EngineType.Chrome;
            theDoc.HtmlOptions.UseScript = true; // enable JavaScript
            theDoc.HtmlOptions.Media = MediaType.Print; // Or Screen for a more screen oriented output
            theDoc.HtmlOptions.InitialWidth = 800; // In case we have a responsive site which is non-specific on good widths
                                                   //theDoc.HtmlOptions.RepaintDelay = 500; // Only required if you have AJAX or animated content such as graphs
                                                   //theDoc.HtmlOptions.IgnoreCertificateErrors = false; // Disabled for ease of debugging
                                                   //theDoc.HtmlOptions.FireShield.Policy = XHtmlFireShield.Enforcement.Deny; // Disabled for ease of debugging


            theDoc.Page = theDoc.AddPage();
            int theID;

            theID = theDoc.AddImageUrl(HtmlToPDFConvertion);

            while (true)
            {
                theDoc.FrameRect(); // add a black border
                if (!theDoc.Chainable(theID))
                    break;
                theDoc.Page = theDoc.AddPage();
                theID = theDoc.AddImageToChain(theID);
            }

            for (int i = 1; i <= theDoc.PageCount; i++)
            {
                theDoc.PageNumber = i;
                theDoc.Flatten();
            }
            theDoc.Save(Server.MapPath(Path));




            byte[] theData = theDoc.GetData();
            Response.Clear();
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "inline; filename=MyPDF.PDF");
            Response.AddHeader("content-length", theData.Length.ToString());
            Response.BinaryWrite(theData);
            Response.End();

            return File(m, "application/pdf", "test.pdf");
            //theDoc.Clear();
        }

Все вместе, это схема того, что шаги:

flow

Как избавиться от промежуточного этапа просмотра PDF / html дважды перед его печатью?Например, положить html.actionLink (PDF) вместе с href Url.Action htmltoPDF2? Я не хочу печатать кнопку с содержимым страницы или полосой прокрутки.

НадеюсьУ меня нет большого опыта работы с подобными вещами, поэтому я не уверен, что Google, чтобы узнать, как собрать это в один шаг.Я унаследовал эту веб-страницу от кого-то, кого здесь больше нет.

...