我使用 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) 我尝试使用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) 我想将一个网站参数传递给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 …
我正在使用phantomjsdriver 1.8.1 for .net(C#) http://www.nuget.org/packages/phantomjs.exe/并想知道如何在加载Web内容之前添加用户代理firefox
我的数据项目参考:(实体框架核心)
<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 …
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) 我是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).
使用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) 我将 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) c# ×7
asp.net ×3
asp.net-core ×2
asp.net-mvc ×2
itextsharp ×2
angularjs ×1
iis ×1
iis-7.5 ×1
memorycache ×1
nuget ×1
pdf ×1
phantomjs ×1
selenium ×1