如何将多个网页转换为一个pdf文档?(How do I convert several web pages into one pdf document?)
public FileResult Download() { var doc = new EO.Pdf.PdfDocument(); EO.Pdf.HtmlToPdf.ConvertUrl("http://www.google.com/", doc); var ms = new MemoryStream(); doc.Save(ms); ms.Position = 0; return new FileStreamResult(ms, "application/pdf") { FileDownloadName = "download.pdf" }; }
如果可能的话,请您展示如何扩展上面的代码,以便能够将多个网页转换成一个pdf文档?
棘手的部分是我们不知道用户可能尝试转换的页面。
因此,如上面的代码所示,对网页进行硬编码并没有帮助我们。
任何帮助是极大的赞赏。
//Create a new PdfDocument object var doc = new EO.Pdf.PdfDocument(); //Convert two ore more different pages into the same PdfDocument EO.Pdf.HtmlToPdf.ConvertUrl("c:\\1.html", doc); EO.Pdf.HtmlToPdf.ConvertUrl("c:\\2.html", doc);
最新代码:
public FileResult Download() { var doc = new EO.Pdf.PdfDocument(); foreach(var url in passedUrls) { EO.Pdf.HtmlToPdf.ConvertUrl(url, doc); doc.Save(ms); } ms.Position = 0; return new FileStreamResult(ms, "application/pdf") { FileDownloadName = "download.pdf" }; }
亚当的最新消息(谢谢先生)
public FileResult Download() { var documents = new List<EO.Pdf.PdfDocument>(); foreach(var url in passedUrls) { var doc = new EO.Pdf.PdfDocument(); EO.Pdf.HtmlToPdf.ConvertUrl(url, doc); documents.Add(doc); } EO.Pdf.PdfDocument mergedDocument = EO.Pdf.PdfDocument.Merge(documents.ToArray()); }
希望其他人发现这些代码很有用。
public FileResult Download() { var doc = new EO.Pdf.PdfDocument(); EO.Pdf.HtmlToPdf.ConvertUrl("http://www.google.com/", doc); var ms = new MemoryStream(); doc.Save(ms); ms.Position = 0; return new FileStreamResult(ms, "application/pdf") { FileDownloadName = "download.pdf" }; }
Can you please show if possible, how to extend the code above to be able to convert several web pages into one pdf document?
The tricky part is that we don't know what pages a user is likely to attempt to convert.
So, hardcoding the webpages as the code above shows isn't helping us.
Any help is greatly appreciated.
//Create a new PdfDocument object var doc = new EO.Pdf.PdfDocument(); //Convert two ore more different pages into the same PdfDocument EO.Pdf.HtmlToPdf.ConvertUrl("c:\\1.html", doc); EO.Pdf.HtmlToPdf.ConvertUrl("c:\\2.html", doc);
Latest code:
public FileResult Download() { var doc = new EO.Pdf.PdfDocument(); foreach(var url in passedUrls) { EO.Pdf.HtmlToPdf.ConvertUrl(url, doc); doc.Save(ms); } ms.Position = 0; return new FileStreamResult(ms, "application/pdf") { FileDownloadName = "download.pdf" }; }
Latest from Adam (thank you sir)
public FileResult Download() { var documents = new List<EO.Pdf.PdfDocument>(); foreach(var url in passedUrls) { var doc = new EO.Pdf.PdfDocument(); EO.Pdf.HtmlToPdf.ConvertUrl(url, doc); documents.Add(doc); } EO.Pdf.PdfDocument mergedDocument = EO.Pdf.PdfDocument.Merge(documents.ToArray()); }
Hopefully, others find these codes useful.
原文:
最满意答案
就像熊会吃你说的,似乎这两位编辑对选项卡的广泛程度有不同的看法。 默认情况下,一个制表符(
\t
)在emacs上是8个空格。 也许TextMate在您的配置中显示一个标签为4个空格?您可以在emacs中设置您的制表符宽度(在这种情况下为4个空格),方法是将以下内容添加到.emacs中:
(setq-default tab-width 4)
我对配置TextMate一无所知。
或者,您可以配置emacs使用空格而不是制表符来缩进:
(setq-default indent-tabs-mode nil)
同样,我不知道你是如何用TextMate做到的。
Like Bears will eat you said, it seems like the two editors have differing opinions on how wide a tab is. Be default a tab character (
\t
) is 8 spaces wide on emacs. Maybe TextMate shows a tab as 4 spaces in your configuration?You can set your tab-width in emacs (to 4 spaces in this case) by adding the following to your .emacs:
(setq-default tab-width 4)
I don't know anything about configuring TextMate.
Alternatively you can configure emacs to use spaces rather than tabs for indentation:
(setq-default indent-tabs-mode nil)
Again, I don't know how you do that with TextMate.
相关问答
更多-
在过去4个月里,邮件列表中有一个强烈的暗示或者直截了当的说法,几乎是肯定的,到2009年夏天至少会有一个测试版,但是我还没有能够挖掘它,所以我不确定。 说实话,我并不关心TextMate。 当然,我很乐意看到,因为新的东西总是很酷; 但在我看来,TextMate - 拆分窗格查看和更好的撤消支持中只有2个大功能缺失 - 我发现没有这些功能就可以生活。 TextMate 2可能会很棒,但是现在的TextMate是一个很好的编辑器,我不用担心TM2出来。 更新:公众阿尔法将于 2011年圣诞节到期 。 更新:现 ...
-
这很简单: Cx rt It's as simple as this: C-x r t
-
拉起椅子的儿子,让我讲这个。 在Xcode之前,有VIM和Emacs。 我知道这很难想象,但这是真的。 许多人习惯了VIM / Emacs,因此继续使用它。 Emacs是非常可定制的,并提供几乎可以想象的一切(包括内置收缩和河内的塔)。 您可以轻松地从Emacs调用编译器,并根据需要创建自己的扩展。 VIM具有令人难以置信的正则表达式引擎(Emacs也是如此),非常方便,因为(VI)几乎每个Unix操作系统都有,如果没有箭头键(是啊,真正的老学校) 人们使用键移动文件是非常好的,而不必使用鼠标。 Emacs ...
-
您必须创建一个Bundle Command和一个键盘快捷方式来执行此操作。 在TextMate中,转到Bundles - > Bundle Editor 在我们自己的Bundle中创建一个新命令。 称之为“在终端执行” 将“保存”设置为“无”,将“输入”设置为“选定文本”,将“或”设置为“线”。 将“输出设置为丢弃” 在“激活”中选择您自己的快捷方式。 我选择了Apple Shift U. 将下面的命令粘贴到“命令”框中(格式化导致我麻烦) 关闭Bundle Editor,然后选择Bundles - > B ...
-
更简单的答案: 安装MacRuby 转到TextMate-> Preferences-> Advanced-> Shell Variables,并添加一个名为TM_RUBY的变量设置为/usr/local/bin/macruby 。 或者,编辑PATH变量以包含/usr/local/bin/ ,并将TM_RUBY设置为macruby 。 如果你已经通过RVM安装了MacRuby,那么改为: 生成稳定的包装: rvm wrapper macruby-0.8 macruby #创建〜/ .rvm / bin / ...
-
TextMate在2006年试用时感觉“神奇”。它的Tab-Completion / Snippets系统,矩形选择/编辑,可扩展性,很好的SVN集成和整体风格使它比TextWrangler,DreamWeaver或我在时间。 我对此感到非常兴奋,并向我传播了它的力量。 我在完成了一个试用版的项目后才购买它。 那个时候对我来说每一分钱都是值得的。 不过,我花了大约一年的时间才达到高原。 我非常了解TextMate,但它开始感觉“有限”。 实际上,TextMate非常有影响力:现在许多IDE /编辑器都有许多 ...
-
我认为这些设置应该做到这一点: (defun my-html-mode-hook () (setq tab-width 4) (setq indent-tabs-mode t) (define-key html-mode-map (kbd "
") 'my-insert-tab) (define-key html-mode-map (kbd "C->") 'sgml-close-tag)) (defun my-insert-tab (&optional arg) (intera ... -
TextMate和Groovy(TextMate & Groovy)[2022-12-16]
要清楚,您应该单击TextMate>首选项>高级> Shell变量 然后添加一个名为'TM_GROOVY'的变量,其值为'/Applications/groovy-1.8.4/bin/groovy' 不知道为什么但是对于我的实例我实际上明确指定了'... / groovy'。 To be clear you should click on TextMate > Preferences > Advanced > Shell Variables Then add a Variable named 'TM_GRO ... -
如何从emacs启动vi或TextMate(配对)? (async-shell-command "vi") ;; From Emacs 23.2 (shell-command "vi &") ;; Before Emacs 23.2 要启动TextMate,你需要安装TextMate的命令行工具,然后从emacs中,它是(thx Chetan): (async-shell-command "mate") ;; From Emacs 23.2 (shell-command "mate &") ;; ...
-
就像熊会吃你说的,似乎这两位编辑对选项卡的广泛程度有不同的看法。 默认情况下,一个制表符( \t )在emacs上是8个空格。 也许TextMate在您的配置中显示一个标签为4个空格? 您可以在emacs中设置您的制表符宽度(在这种情况下为4个空格),方法是将以下内容添加到.emacs中: (setq-default tab-width 4) 我对配置TextMate一无所知。 或者,您可以配置emacs使用空格而不是制表符来缩进: (setq-default indent-tabs-mode nil) ...