是否可以仅使用免费软件将文档转换为 PDF 或在 C# 中编辑 PDF? [英] Is it at all possible to convert a document to PDF or edit a PDF in C# using only free software?

查看:72
本文介绍了是否可以仅使用免费软件将文档转换为 PDF 或在 C# 中编辑 PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个愚蠢的想法,即创建一个 .docx 或 .rtf 或 .pdf 格式的模板,然后替换该文档中的文本以生成报告.这似乎比使用付费报告软件更好.

嗯,我相信我现在已经尝试了几乎所有的东西,我很惊讶用 pdf 做任何事情是多么不可能.

尝试 1

HTML -> PDF

设计模板要困难得多.打印时看起来不一样.从来没有让它在命令行示例之外工作(不确定 iTextSharp-LGPL 甚至可以工作多好,或者它是否可以处理 base64 字符串,因为我不知道你还会如何告诉它有关图像的信息).无论如何,这样做会使模板设计变得太困难.

尝试 2

OpenXml -> PDF

我愚蠢地认为这是因为 Word 可以将 OpenXml 保存为 PDF.我错了.它无法另存为 PDF.

尝试 3

OpenOffice/LibreOffice (docX -> PDF)

它无法读取 OpenXml,这是一个问题,因为我将模板编辑为 OpenXml,然后将该结果保存(作为 .docx),但它无法读取该保存的文档.

尝试 4

我在这里做什么?购买软件以便我可以将文件保存为 PDF?这是唯一的选择吗?

解决方案

我有一个解决方案.我并不是说这是最好的解决方案.LibreOffice(如果您愿意,也可能是 OpenOffice)接受将进行切换的命令行参数.

soffice.exe --headless --convert-to pdf mockup.odt

*注意 - 这是在我将 libreoffice 添加到我的路径 (C:\Program Files\LibreOffice\program) 之后.知道为什么它被称为 soffice.exe 而不是 libreoffice.exe.

I had this stupid idea of creating a template as a .docx or .rtf or .pdf and then replacing the text in that document to generate reports. This seemed like a better way of doing it than using paid reporting software.

Well, I believe I've tried just about everything now and I'm amazed at how impossible it is to do anything with pdfs.

Try 1

HTML -> PDF

A lot harder to design the template. It doesn't look the same when you print it. Never got it working outside of a command line example (not sure how well, say, iTextSharp-LGPL would even work or if it could handle base64 strings as I'm not sure how else you are going to tell it about images). In any case, doing it this way makes it too hard to design the template.

Try 2

OpenXml -> PDF

I stupidly assumed that because Word could save as PDF that OpenXml could to. I was wrong. It cannot save as a PDF.

Try 3

OpenOffice/LibreOffice (docX -> PDF)

It can't read OpenXml which is a problem because I was editing the template as OpenXml and then saving that result (as a .docx) but it can't read that saved document.

Try 4

iTextSharp LGPL

This one just doesn't work, lol. And apparently even though when you google "convert rtf to pdf" the ONLY thing that comes up is iText and its derivatives it doesn't convert rtf documents to pdf documents. I verified this myself (it only saves the text not the formatting) and later found this post to convince me I wasn't doing something wrong.

Try 5

PDF -> PDF

Since converting ANYTHING to a PDF seems to be impossible maybe I can save the template as a PDF and just do a text replace on that. Nope, lol, that is apparently a very difficult thing to do.

Try 6

Pandoc (.odt/.docx -> pdf), (.rtf -> .pdf not supported)

pandoc mockup2.odt -s -o mockup2.pdf

link to the files in the picture. *note, it messes up in the same way if you try converting .odt/.docx to .tex.

What do I do here? Buy software so that I can save a file as PDF? Is that the only option?

解决方案

I have a solution. I'm not saying it's the best solution. LibreOffice (or possibly OpenOffice if you are so inclined) accepts command line arguments that will do the switch.

soffice.exe --headless --convert-to pdf mockup.odt

*note - this is after I added libreoffice to my path (C:\Program Files\LibreOffice\program). idk why it's called soffice.exe instead of libreoffice.exe.

这篇关于是否可以仅使用免费软件将文档转换为 PDF 或在 C# 中编辑 PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆