本地Mongodb安全(Local Mongodb security)
所以我是noSQL浪潮的新手,我最近一直在使用MEAN Stack。 我在运行其余网站的同一台服务器上运行MongoDB时,我只有一个关于安全性的问题。 每当我有一个mySQL或SQL Server数据库时,我总是被建议远程运行它,但是当它涉及到MEAN堆栈时,它都是本地的。 通常当我在网上看时,每个人都使用其余的代码运行他们的MongoDB,我只是想知道这是不是这样做了?
So I'm new to the noSQL wave of things and I've been working with the MEAN Stack recently. I just have a question about security when it comes to running MongoDB on the same server I'm running the rest of my website. Whenever I have a mySQL or SQL Server database, I was always advised to run it remotely but when it comes to the MEAN stack, it's all local. And usually when I look online, everyone has their MongoDB running with the rest of their code and I was just wondering if that's just how it's done?
原文:https://stackoverflow.com/questions/23858638
最满意答案
每当您使用iTextSharp编写需要创建新文档的内容时,它都不会写入现有文档。 在您的情况下,页面重新排序需要编写,因此您需要创建一个新文档,将页面重新排序然后重新排序。 (当然,您也可以在导入时重新排序它们。)
var inputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf"); var output = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Output.pdf"); //Bind a reader to our input file var reader = new PdfReader(inputFile); //Create our output file, nothing special here using (FileStream fs = new FileStream(output, FileMode.Create, FileAccess.Write, FileShare.None)) { using (Document doc = new Document(reader.GetPageSizeWithRotation(1))) { //Use a PdfCopy to duplicate each page using (PdfCopy copy = new PdfCopy(doc, fs)) { doc.Open(); copy.SetLinearPageMode(); for (int i = 1; i <= reader.NumberOfPages; i++) { copy.AddPage(copy.GetImportedPage(reader, i)); } //Reorder pages copy.ReorderPages(new int[] { 2, 1 }); doc.Close(); } } }
Whenever you use iTextSharp to write something you need to create a new document, it will never write to an existing document. In your case, page reordering would require writing so you need create a new document, bring over the pages and then reorder them. (Of course, you could also just reorder them upon import, too.)
var inputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf"); var output = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Output.pdf"); //Bind a reader to our input file var reader = new PdfReader(inputFile); //Create our output file, nothing special here using (FileStream fs = new FileStream(output, FileMode.Create, FileAccess.Write, FileShare.None)) { using (Document doc = new Document(reader.GetPageSizeWithRotation(1))) { //Use a PdfCopy to duplicate each page using (PdfCopy copy = new PdfCopy(doc, fs)) { doc.Open(); copy.SetLinearPageMode(); for (int i = 1; i <= reader.NumberOfPages; i++) { copy.AddPage(copy.GetImportedPage(reader, i)); } //Reorder pages copy.ReorderPages(new int[] { 2, 1 }); doc.Close(); } } }
相关问答
更多-
使用itextsharp为新的pdf文档添加新的页面和标签(adding new pages and labels to new pdf document using itextsharp)[2023-08-25]
你好,你可以简单地使用下面的代码添加新页面: - Document document = new Document(); document.Open(); document.NewPage(); 并添加标签请使用下面的代码: - static Font FontSubHeading = FontFactory.GetFont("gothic", 10, Font.NORMAL, new BaseColor(System.Drawing.ColorTranslator.FromHtml("#4040 ... -
您正在为每次传递创建一个新的PdfReader 。 这是非常低效的。 因为你从每个页面都有一个PdfImportedPage ,所有这些(可能是多余的) PdfReader实例都不会被PdfReader 。 建议: 两次通过。 首先建立一个文件和页面的列表。 其次依次对每个文件进行操作,因此您一次只能有一个“打开”的PdfReader 。 使用PdfCopy.freeReader()当你完成给定的读者。 这几乎肯定会改变你的页面添加顺序(也许是一件非常糟糕的事情)。 一次通过。 根据文件名缓存你的PdfRe ...
-
请转到官方文档 ,然后单击问答以转到最常见的问题。 选择入门类别。 您将看到的第一件事是最受欢迎的iText示例(为方便起见,我将其移植到C#): // step 1 Document document = new Document(); // step 2 FileStream fs = new FileStream("hello.pdf", FileMode.Create); PdfWriter.GetInstance(document, fs); // step 3 document.Open(); ...
-
扩展功能警告提示原始PDF已使用使用权限签名进行“读取器启用”签名,即告诉Adobe Reader在打开时激活某些附加功能,并且OP对其的操作已失效签名。 实际上,他经营使用 _pdfStamper = new PdfStamper(_pdfReader, _pdfOutputStream); 这会创建一个完全重新生成文档的PdfStamper 。 但是,要使签名无效,必须使用OP的固定代码中的附加模式(对于char pdfVersion = '\0', bool append = true ): _pd ...
-
该解决方案是Acrobat / Reader中的首选项。 转到编辑 - >首选项 - >常规选项卡 - > 取消选中“从URL创建链接” 。 最好的部分是,此设置将在打开不同文档时保持有效。 Chris Haas的积分。 The solution was a preference in Acrobat/Reader. Go to Edit -> Preferences -> General tab -> Uncheck "Create links from URLs". The best part is, ...
-
您的代码无法工作,因为您使用path创建PdfReader以及创建FileStream 。 您可能会收到错误,例如“文件正在使用中”或“文件无法访问”。 这在这里解释: StackOverflow: 如何在不创建新PDF的情况下更新PDF? 官方网站: 如何在不创建新PDF的情况下更新PDF? 您创建一个名为baos的MemoryStream() ,但您没有在任何地方使用该对象。 解决问题的一种方法是在第一次通过MemoryStream创建PDF时替换FileStream ,然后使用存储在该内存流中的字节来 ...
-
我几乎没有使用iText编程或使用c#的经验,所以我很乐意回答你的问题:) 首先,如果您想要做的只是标记一个页面,然后再次找到它,请不要使用 PDF中的辅助功能。 辅助功能对于辅助设备是有用的,滥用这些功能并不好。 特别是因为 - 如果我正确理解你想要做的事情 - 不需要这样做。 如果要标记页面,则应查找页面字典,例如: PdfReader reader = new iTextSharp.text.pdf.PdfReader(file_content); PdfDictionary pageDict = r ...
-
每当您使用iTextSharp编写需要创建新文档的内容时,它都不会写入现有文档。 在您的情况下,页面重新排序需要编写,因此您需要创建一个新文档,将页面重新排序然后重新排序。 (当然,您也可以在导入时重新排序它们。) var inputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf"); var output = Path.Combine(En ...
-
您需要从输入流中读取pdf。 PdfReader reader = new PdfReader(m); PdfImportedPage page = writer.GetImportedPage(reader, i); // size information //page.PageSize.Width //page.PageSize.Height You need to read the pdf from your input stream (m). PdfReader reader = new PdfR ...
-
您正在寻找启动操作 。 我是关于iText的书的作者,我通常不会谈论这个功能,因为它被认为是一个安全隐患(你在评论中指出:用户真的必须信任PDF)。 在iTextSharp中,您将创建一个这样的启动操作: Paragraph p = new Paragraph( new Chunk( "Click to open test.txt in Notepad.") .SetAction( new PdfAction( "c:/windows/no ...