参考之前的帖子(PDF报告生成)
我决定使用类似于http://www.alistapart.com/articles/boom的解决方案
对于那些不想阅读任何参考文献的人 - 我正在创建一个报告并将其作为PDF格式化.我决定使用.NET进行HTML - > PDF路由.
所以,让我说我得到的HTML文件完全像我想要的那样.将所述页面转换为PDF的最佳方法是什么?本质上,我希望用户在HTML中看到"预览",然后能够将所述页面转换为PDF.我正在尝试的库是ABCPdf.
我的第一个想法是将页面保存到文件系统,并在页面本身的事件处理程序期间在转换例程中引用它的URL.这有它的问题,因为每次渲染时都要保存页面以准备打印它.实际上,它似乎是后退的.
我的下一个想法是使用页面的渲染方法将页面捕获为字节流并使用它(因为ABCPdf支持转换HTML流.)如果这是我的答案,我迷失了如何实际将它拉下来.有一个"打印"按钮,处理程序将Me.Render()转换为字节流并将其发送到转换例程?这甚至可能吗?
底线 - 一旦页面以精美的HTML呈现,您如何初始化该页面的PDF转换?欢迎使用变通方法和其他解决方案.
我希望我错过一些明显的东西,因为这必须是" 容易的部分 "
我正在使用abcPdf将HTML报告转换为pdf文件.pdf必须是单一的横向A4页面.
你知道是否有办法告诉abcPdf扩展HTML页面以适应pdf中的单个页面?我尝试使用Magnify()方法,它会缩放内容但仍将其分解为页面,即使它适合一页.我一直在摸不着头脑,我想知道是否有人这样做过.
这是我目前正在使用的代码:
public byte[] UrlToPdf(string url, PageOrientation po)
{
using (Doc theDoc = new Doc())
{
// When in landscape mode:
// We use two transforms to apply a generic 90 degree rotation around
// the center of the document and rotate the drawing rectangle by the same amount.
if (po == PageOrientation.Landscape)
{
// apply a rotation transform
double w = theDoc.MediaBox.Width;
double h = theDoc.MediaBox.Height;
double l = theDoc.MediaBox.Left;
double b = theDoc.MediaBox.Bottom;
theDoc.Transform.Rotate(90, l, …Run Code Online (Sandbox Code Playgroud) 我们有一个大型应用程序成功使用ABCPDF.NET与HTML样式文本.我们习惯于使用未安装在Windows中的字体添加文本,但存储在文件系统中其他位置的文件中 - 我们这样做,这样每个用户都可以上传自己的字体并将其与输出一起使用.我们使用AddFont调用将字体嵌入Doc中,然后使用AddText调用在HTML样式文本的标记中引用该字体.
我们开始考虑使用AddImageUrl/AddImageHTML来获得更多HTML功能.因此,字体是一个棘手的问题.似乎MSHTML和Gecko引擎只能看到与Windows相同的字体列表.
我试过这段代码来看看@ font-face是否适用于Gecko:
Sub Main
dim pdf as new Doc
with pdf.HtmlOptions
.Engine = EngineType.Gecko
.FontEmbed = true
.FontSubstitute = false
.FontProtection = false
end with
pdf.AddImageUrl("http://www.w3.org/2010/09/web-on-tv/slides/1009-tv-web-chaals/demos/webfonts.htm")
pdf.Save("c:\temp\a.pdf")
End Sub
Run Code Online (Sandbox Code Playgroud)
但事实并非如此.还有什么我可以做的吗?
这是ABCpdf.NET 8.1.0.7.升级到9或更高版本的8会有帮助吗?
如何使用ABCPdf.NET工具从PDF文件中提取内容文本?
我尝试了GetText方法,但没有提取内容:
var doc = new Doc();
var url = @".../FileName.pdf";
doc.Read(url);
string xmlContents = doc.GetText("Text");
Response.Write(xmlContents);
doc.Clear();
doc.Dispose();
Run Code Online (Sandbox Code Playgroud)
我的pdf有近1000个单词,但GetText只返回4-5个单词.我意识到它只返回第一页的文本.
所以问题应该是"如何从pdf文件的所有页面中提取文本?" - (更改标题以使其更清晰).
谢谢,
我正在创建一个 pdf 文件,我想将其链接到与 pdf 相同的目录中的其他文件。
IE。
MyFolder
|
|-main.pdf
|-myotherpdf.pdf
|-myotherotherpdf.pdf
Run Code Online (Sandbox Code Playgroud)
我希望 main.pdf 具有链接,使 pdf 上的默认程序打开其他 pdf。
当我在服务器上生成这些文件,然后将它们下载到客户端时,我无法使用绝对链接,因为这些文件不会存在于客户端电脑上。
首先,pdf 文件实际上支持这样的相对文件链接吗?我还没有发现太多说明它们可以这样做。
另外,为了生成我的 pdf,我使用 abcpdf 并提供 html 以将其转换为 pdf。
为了尝试在 html 中生成正确的正确网址,我尝试了以下操作
<a href='test.pdf'>test pdf link to local file</a>
<a href='#test.pdf'>test pdf link to local file</a>
<a href='/test.pdf'>test pdf link to local file</a>
<a href='file:///test.pdf'>test pdf link to local file</a>
<a href='file://test.pdf'>test pdf link to local file</a>
Run Code Online (Sandbox Code Playgroud)
他们中的大多数人要么直接向我指示生成 pdf 文档的点(临时文件路径),要么链接悬停在 acrobat 中显示“file:///test.pdf”,但单击它会弹出一个警告对话框,要求允许/deny,点击允许后,它会在 Firefox 中打开,网址为“file:///test.pdf”,但不会解析任何内容。
关于如何实现此功能或者这种链接是否可以在 pdf 中实现的任何想法?
我正在使用ABCpdf工具,我试图将1TB的PDF文件(因此效率问题)分成单页PDF文件.
我尝试过以下方法:
Doc theSrc = new Doc();
theSrc.Read("C://development//pdfSplitter//Bxdfbc91ca-fc05-4315-8c40-798a77431ee0xP.pdf");
for (int i = 1; i <= theSrc.PageCount; i++)
{
Doc singlePagePdf = new Doc();
singlePagePdf.Rect.String = singlePagePdf.MediaBox.String = theSrc.MediaBox.String;
singlePagePdf.AddPage();
singlePagePdf.AddImageDoc(theSrc, i, null);
singlePagePdf.FrameRect();
singlePagePdf.Save("C://development//pdfSplitter//singlePDF//singlePage"+i+".pdf");
singlePagePdf.Clear();
}
theSrc.Clear();
Run Code Online (Sandbox Code Playgroud)
这一个非常快,但它不保留旋转的页面,他们需要.我试图手动旋转它们,但这很快就变得有点混乱,并且它们没有像原始文档中那样精确地出现.
我也尝试过:
Doc theSrc = new Doc();
theSrc.Read("C://development//pdfSplitter//Bxdfbc91ca-fc05-4315-8c40-798a77431ee0xP.pdf");
for (int i = 1; i <= theSrc.PageCount; i++)
{
Doc singlePagePdf = new Doc();
singlePagePdf.Append(theSrc);
singlePagePdf.RemapPages(i.ToString());
singlePagePdf.Save("C://development//pdfSplitter//singlePDF//singlePage"+i+".pdf");
singlePagePdf.Clear();
}
theSrc.Clear();
Run Code Online (Sandbox Code Playgroud)
这个比第一个慢大约6倍(在大型文档上)但它保持旋转页面的格式,这很重要.这个问题是我必须附加整个文档并再次删除所有不需要的页面.这对文件中的所有页面都是非常低效的.
有人可以帮我解决这个问题吗?
我正在使用abcpdf,我很好奇我们是否可以递归调用AddImageUrl()函数来汇编编译多个url的pdf文档?
就像是:
int pageCount = 0;
int theId = theDoc.AddImageUrl("http://stackoverflow.com/search?q=abcpdf+footer+page+x+out+of+", true, 0, true);
//assemble document
while (theDoc.Chainable(theId))
{
theDoc.Page = theDoc.AddPage();
theId = theDoc.AddImageToChain(theId);
}
pageCount = theDoc.PageCount;
Console.WriteLine("1 document page count:" + pageCount);
//Flatten document
for (int i = 1; i <= pageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
//now try again
theId = theDoc.AddImageUrl("http://stackoverflow.com/questions/1980890/pdf-report-generation", true, 0, true);
//assemble document
while (theDoc.Chainable(theId))
{
theDoc.Page = theDoc.AddPage();
theId = theDoc.AddImageToChain(theId);
}
Console.WriteLine("2 document page count:" + theDoc.PageCount);
//Flatten document …Run Code Online (Sandbox Code Playgroud) 我正在使用ABCPDF库的AddImageUrl函数,并使页面呈现为PDF格式.但是我遇到的问题是链接(标签)没有在PDF链接中呈现,而是作为没有链接功能的普通文本.我检查了HTML页面以确保页面上存在链接.
我正在尝试更新我(以前工作)的pdf创建Web应用程序以使用ABCpdf.NET和ABCpdf.NET Gecko Runtime nuget包.
我已经安装了两个软件包(都是版本8.1.1.6)但是当我运行我的应用程序时,我得到以下WebSupergoo.ABCpdf8.Internal.PDFException:
无法添加HTML:Gecko引擎遇到了无法恢复的错误.可能的原因:XULRunner文件夹已损坏或来自另一版本的ABCpdf.
在安装了ABCpdf.NET Gecko Runtime软件包之后,我得到了一个对话框,告诉我需要手动将XULRunner文件夹复制到我的输出目录中.为了实现这一点,我在我的应用程序.csproj文件中添加了以下内容:
<Target Name="AfterBuild">
<CallTarget Targets="CopyAbcpdfToDeployFolder" />
</Target>
<Target Name="CopyAbcpdfToDeployFolder">
<ItemGroup>
<SourceDir Include="$(ProjectDir)XULRunner\**\*.*" />
</ItemGroup>
<Copy SourceFiles="@(SourceDir)" DestinationFolder="$(WebProjectOutputDir)\$(OutputPath)%(SourceDir.RecursiveDir)\XULRunner" />
</Target>
Run Code Online (Sandbox Code Playgroud)
(这似乎工作正常 - 构建后,XULRunner文件夹及其内容存在于我的bin文件夹中)
失败的代码行如下:
theDoc.AddImageUrl(url);
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我搞定这个吗?
问题:
我正在传递HTML并通过ABC pdf创建pdf.
但是CSS没有应用于内容,并且创建的pdf不是预期的.
这是我的代码可以请你建议问题是什么或我们如何应用CSS ...
public static String CreateHtmlFile(String strHtmlCode)
{
String Modifiedhtml = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd""><html class="" _Telerik_IE9"" xmlns=""http://www.w3.org/1999/xhtml"">" + strHtmlCode;
Modifiedhtml = Modifiedhtml.Remove(Modifiedhtml.IndexOf(@"//<![CDATA["), (Modifiedhtml.IndexOf("//]]>") - Modifiedhtml.IndexOf(@"//<![CDATA[")));
string[] stringSeparators = new string[] { "PdfCreator" };
var baseUrl = HttpContext.Current.Request.Url.AbsoluteUri.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries).First();
Modifiedhtml = Modifiedhtml.Replace(@"href=""../", (@"href=""" + baseUrl));
Modifiedhtml = Modifiedhtml.Replace(@"href=""/", (@"href=""" + baseUrl));
Doc theDoc = new Doc();
theDoc.HtmlOptions.UseScript = false;
//theDoc.Width = 1125;
String s = string.Empty;
//s = File.ReadAllText(@"D:\test.html");
theDoc.Page = theDoc.AddPage(); …Run Code Online (Sandbox Code Playgroud)