小编nam*_* vo的帖子

itextsharp 如何添加完整的换行符

我使用 itextsharp,我需要从页面的左到右(100% 宽度)绘制一个虚线换行符,但不知道如何。文档总是有左边距。请帮忙在此处输入图片说明

var pageSize = PageSize.A4;

        if (_pdfSettings.LetterPageSizeEnabled)
        {
            pageSize = PageSize.LETTER;
        }


        var doc = new Document(pageSize);
        PdfWriter.GetInstance(doc, stream);
        doc.Open();

        //fonts

        var titleFont = GetFont();
        titleFont.SetStyle(Font.BOLD);
        titleFont.Color = BaseColor.BLACK;
        titleFont.Size = 16;

        var largeFont = GetFont();
        largeFont.SetStyle(Font.BOLD);
        largeFont.Color = BaseColor.BLACK;
        largeFont.Size = 18;

        int ordCount = orders.Count;
        int ordNum = 0;

        foreach (var order in orders)
        {

            var addressTable = new PdfPTable(3);
            addressTable.WidthPercentage = 100f;
            addressTable.SetWidths(new[] { 25, 37, 37 });


            // sender address

            cell = new PdfPCell(); …
Run Code Online (Sandbox Code Playgroud)

c# itextsharp

5
推荐指数
1
解决办法
7643
查看次数

pdfptable中的ItextSharp水平对齐

我尝试使用ItextSharp在pdf表中对齐单元格内容。不知何故,它根本不起作用,始终在左侧对齐。

     var pageSize = PageSize.A4;

        if (_pdfSettings.LetterPageSizeEnabled)
        {
            pageSize = PageSize.LETTER;
        }


        var doc = new Document(pageSize);
        PdfWriter.GetInstance(doc, stream);
        doc.Open();

        //fonts     

        var normalFont = GetFont();

            normalFont.Color = BaseColor.BLACK;
            normalFont.Size = 14;

       //..titlefont, smallfont,largefont....

         var addressTable = new PdfPTable(1);
         addressTable.WidthPercentage = 100f;

         cell = new PdfPCell();

         cell.AddElement(new Paragraph("Ng??i G?i", titleFont));
         cell.AddElement(new Paragraph("TAKARA.VN", largeFont));

         cell.HorizontalAlignment = Element.ALIGN_RIGHT;

         addressTable.AddCell(cell);

         doc.Add(addressTable);
         doc.Add(new Paragraph("", normalFont));
Run Code Online (Sandbox Code Playgroud)

更新:我找到了答案

您在混淆文本模式和复合模式。

文字模式:

Phrase p = New Phrase("value");
PdfPCell cell = new PdfPCell(p);
cell.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(cell);
Run Code Online (Sandbox Code Playgroud)

复合模式:

PdfPCell cell …
Run Code Online (Sandbox Code Playgroud)

c# pdf itextsharp

5
推荐指数
1
解决办法
1万
查看次数

将长参数传递给asp.net webapi

我想将一个网站参数传递给webapi,但它无法正常工作.

Webapiconfig:

 config.Routes.MapHttpRoute(
           name: "DefaultApi",
           routeTemplate: "api/{controller}/{id}",
           defaults: new { id = RouteParameter.Optional }
       );
Run Code Online (Sandbox Code Playgroud)

Web api控制器:获取参数并返回其他网站的htmlsnapshot

    [HttpGet]
    [Route("api/snapshot/{param}")]
    public string GetSnapShot(string param)
    {

        string fragment = param;
        string content = "";

        if (fragment != null)
        {
            int firstSlash = fragment.IndexOf("/");
            if (firstSlash <= 2)
                fragment = fragment.Substring(firstSlash + 1, fragment.Length - firstSlash - 1);
            using (IWebDriver driver = new PhantomJSDriver())
            {
                string url = String.Format("http://domain.com/{0}", fragment);
                driver.Navigate().GoToUrl(url);

                content = driver.PageSource;
            }
        }
        return content;
    }
Run Code Online (Sandbox Code Playgroud)

如果我尝试api/snapshot/du-lieu - >打击控制器很好,但如果我传入更复杂的

api/snapshot …

c# asp.net-mvc

5
推荐指数
1
解决办法
1087
查看次数

phantomjsdriver如何添加用户代理?

我正在使用phantomjsdriver 1.8.1 for .net(C#) http://www.nuget.org/packages/phantomjs.exe/并想知道如何在加载Web内容之前添加用户代理firefox

c# selenium nuget nuget-package phantomjs

3
推荐指数
1
解决办法
5313
查看次数

实体框架核心:无法添加迁移:无参数构造函数

我的数据项目参考:(实体框架核心)

    <Project Sdk="Microsoft.NET.Sdk">    
      <PropertyGroup>
        <TargetFramework>netcoreapp1.1</TargetFramework>
      </PropertyGroup>    
      <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.1" />
        <ProjectReference Include="..\Butv.Core\Butv.Core.csproj" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.1" PrivateAssets="All" />      
        <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.0.0" />    
      </ItemGroup>
      <ItemGroup>
        <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />  
      </ItemGroup>
      <ItemGroup>
        <Folder Include="Migrations\" />
      </ItemGroup>
    </Project>
Run Code Online (Sandbox Code Playgroud)

数据库上下文:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
     public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }

     protected override void OnModelCreating(ModelBuilder modelBuilder)
     {  ....
     }
}
public class ApplicationUser : IdentityUser
{
}
Run Code Online (Sandbox Code Playgroud)

每次我尝试命令

dotnet ef migrations添加Init --verbose

,我收到了错误.在将Data项目与主项目分开之前,它已经习惯了.

Microsoft.EntityFrameworkCore.Design.OperationException:在"ApplicationDbContext"上找不到无参数构造函数.将无参数构造添加到'ApplicationDbContext'或在与'ApplicationDbContext'相同的程序集中添加'IDbContextFactory'的实现.---> System.Mi ssingMethodException:没有为此对象定义无参数构造函数.在System.RuntimeTypeHandle.CreateInstance(RuntimeType类型,Boolean publicOn …

c# asp.net entity-framework

3
推荐指数
1
解决办法
5537
查看次数

如何在asp.net核心中迭代MemoryCache?

IMemoryCache中没有可用的方法允许迭代每个缓存的项目.我的项目很小,我不想使用像Redis这样的其他选项.

namepsace    Microsoft.Extensions.Caching.Memory{
        public static class CacheExtensions
    {
        public static object Get(this IMemoryCache cache, object key);
        public static TItem Get<TItem>(this IMemoryCache cache, object key);
        public static TItem GetOrCreate<TItem>(this IMemoryCache cache, object key, Func<ICacheEntry, TItem> factory);
        [AsyncStateMachine(typeof(CacheExtensions.<GetOrCreateAsync>d__9<>))]
        public static Task<TItem> GetOrCreateAsync<TItem>(this IMemoryCache cache, object key, Func<ICacheEntry, Task<TItem>> factory);
        public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value);
        public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value, DateTimeOffset absoluteExpiration);
        public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value, TimeSpan …
Run Code Online (Sandbox Code Playgroud)

c# memorycache asp.net-core

3
推荐指数
2
解决办法
6937
查看次数

ng-repeat with slick js carousel

我是angularjs的新手,我很难使用ng-repeat for js插件,比如https://github.com/vasyabigi/angular-slick和其他一些js模块(banner ...)

  <slick class="slider lazy">
   <div ng-repeat="slide in slides"><div class="image"><img data-lazy="http://vasyabigi.github.io/angular-slick/images/lazyfonz2.png"/></div></div>
</slick

     <slick class="slider lazy">
       <div><div class="image"><img data-lazy="..."/></div></div>
        <div><div class="image"><img data-lazy="..."/></div></div>...  >> without ng-repeat, it works
    </slick
Run Code Online (Sandbox Code Playgroud)

也许没有足够的时间等待所有图像在slickJs采取行动之前完成渲染.

该指令确实有$ timeout(https://github.com/vasyabigi/angular-slick/blob/master/dist/slick.js).

angularjs

2
推荐指数
1
解决办法
1万
查看次数

[A] System.Web.WebPages.Razor.Configuration.HostSection无法强制转换为[B] System.Web.WebPages.Razor.Configuration.HostSection

使用nuget将mvc框架更新到5.2.2.0后出现此错误

[A] System.Web.WebPages.Razor.Configuration.HostSection无法强制转换为[B] System.Web.WebPages.Razor.Configuration.HostSection.类型A源自'System.Web.WebPages.Razor,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35',位于'默认'位置'C:\ Windows\Microsoft.Net\assembly\GAC_MSIL\System .Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll".类型B源自'System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35',位于'默认'位置'C:\ Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\vs\36d3424f\d8d844c3\assembly\dl3\a0b68557\24516c31_ea0dd001\System.Web.WebPages.Razor.dll'.

在web.config上

<appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
  ...
  </appSettings>

    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
              <probing privatePath="Plugins/bin/" />
              <dependentAssembly>
                <assemblyIdentity name="FluentValidation" publicKeyToken="a82054b837897c66" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-3.4.0.0" newVersion="3.4.0.0" />
              </dependentAssembly>
              <dependentAssembly>
                <assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
              </dependentAssembly>
              <dependentAssembly>
                <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
              </dependentAssembly>
              <dependentAssembly>
                <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
              </dependentAssembly>
              <dependentAssembly> …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc

2
推荐指数
2
解决办法
6804
查看次数

如何使用 IIS 阻止机器人?

我将 web.config for asp.net core 配置成这样来阻止机器人 MJ12bot|spbot|YandexBot 我正在使用 IIS 7.5 并安装了 Url Rewrite Module 2.1。

  <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
     <aspNetCore processPath="dotnet" arguments=".\myproject.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">    
    </aspNetCore>
        <rewrite>
            <rules>
                <rule name="RequestBlockingRule1" patternSyntax="Wildcard" stopProcessing="true">
                    <match url="*" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{HTTP_USER_AGENT}" pattern="MJ12bot|spbot|YandexBot" />
                    </conditions>
                    <action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="You do not have permission to view this directory or page using the credentials that you supplied." />
                </rule>
            </rules>
        </rewrite>    
  </system.webServer> …
Run Code Online (Sandbox Code Playgroud)

asp.net iis iis-7.5 asp.net-core

2
推荐指数
1
解决办法
4311
查看次数