PdfReader | Fast load and parse of Pdf format in C | Document Editor library
kandi X-RAY | PdfReader Summary
kandi X-RAY | PdfReader Summary
Fast load and parse of Pdf format in C#
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of PdfReader
PdfReader Key Features
PdfReader Examples and Code Snippets
Community Discussions
Trending Discussions on PdfReader
QUESTION
I am trying to add a Cover Page PDF file to another PDF file. I am using CopyPagesTo
method. CoverPageFilePath will go before any pages in the pdfDocumentFile
. I then need to rewrite that new file to the same location. When I run the code and open the new pdf file I get an error about it being damaged.
ANSWER
Answered 2022-Apr-04 at 15:02Whenever you have some other type, like a StreamWriter, or here a PdfWriter writing to a Stream, it may not write all the data to the Stream immediately.
Here you Close
the pdfDocument for all the data to be written to the MemoryStream.
ie this
QUESTION
GOAL
To open an existing PDF file with multiple pages and add background image to all pages. (Optionally the background image of the first page differs from the others)
In my current implementation (I use .NET 6 and PDFsharp btw.) I add the image to each page, which increases the size of the file dependent on the number of pages.
QUESTION
Is there a way in PDFsharp/MigraDoc to embed a background image only once into the document and then reference it for each page?
CODE
Both PDF document and the image come from a database as byte arrays.
...ANSWER
Answered 2022-Mar-11 at 16:27With PDFsharp and MigraDoc this optimization is done automatically if you use them as intended.
Load the image once with PDFsharp and add it to as many pages as you like, there will be only one copy of the image in the document.
QUESTION
I'm working on PDF related project and I want to create a PDF from the existing PDF.
all things are done but when I created a final PDF at that time this exception was thrown at the line of document.close();
at the method of savePDF
which describe below.
- Create new PDF from existing PDF adding
PdfImportedPage
.
here is my code
The app crashes only when we add a new page
...ANSWER
Answered 2022-Feb-17 at 13:46In createAndAddPage
you import the page into the wrong PdfWriter
:
QUESTION
I'm using iText 7.1.15 and SignDeferred to apply signatures to pdf documents. SignDeferred is required since the signature is created PKCS11 hardware token (usb key).
When i sign a "regular" pdf, e.g. created via word, i can apply multiple signatures and all signatures are shown as valid in the adobe acrobat reader.
If the pdf was created by combining multiple pdf documents with adobe DC, the first signature is valid but becomes invalid as soon as the seconds signature is applied.
Document in Adobe reader after the first signature is applied:
Document in Adobe reader after the second signature is applied:
The signatures of the same document are shown as valid in foxit reader.
I've found a similar issue on stackoverflow (multiple signatures invalidate first signature in iTextSharp pdf signing), but it was using iText 5 and i'm not sure it is the same problem.
Question: What can i do in order to keep both signatures valid in the Acrobat Reader?
Unsigned Pdf document on which the first signature becomes invalid: https://github.com/suntsu42/iTextDemoInvalidSecondSignature/blob/master/test.pdf
Twice signed document which is invalid: https://github.com/suntsu42/iTextDemoInvalidSecondSignature/blob/master/InvalidDocumentSignedTwice.pdf
Code used for signing
...ANSWER
Answered 2022-Jan-28 at 16:35As already mentioned in a comment, the example document "InvalidDocumentSignedTwice.pdf" has the signature not applied in an incremental update, so here it is obvious that former signatures will break. But this is not the issue of the OP's example project. Thus, the issue is processed with an eye on the actual outputs of the example project.
Analyzing the IssueWhen validating signed PDFs Adobe Acrobat executes two types of checks:
- It checks the signature itself and whether the revision of the PDF it covers is untouched.
- (If there are additions to the PDF after the revision covered by the signature:) It checks whether changes applied in incremental updates only consist of allowed changes.
The former check is pretty stable and standard but the second one is very whimsical and prone to incorrect negative validation results. Like in your case...
In case of your example document one can simply determine that the first check must positively validate the first signature: The file with only one (valid!) signature constitutes a byte-wise starting piece of the file with two signatures, so nothing can have been broken here.
Thus, the second type of check, the fickle type, must go wrong in the case at hand.
To find out what change one has to analyze the changes done during signing. A helpful fact is that doing the same using iText 5 does not produce the issue; thus, the change that triggered the check must be in what iText 7 does differently than iText 5 here. And the main difference in this context is that iText 7 has a more thorough tagging support than iText 5 and, therefore, also adds a reference to the new signature field to the document structure tree.
This by itself does not yet trigger the whimsical check, though, it only does so here because one outline element refers to the parent structure tree element of the change as its structure element (SE). Apparently Adobe Acrobat considers the change in the associated structure element as a change of the outline link and, therefore, as a (disallowed) change of the behavior of the document revision signed by the first signature.
So is this an iText error (adding entries to the structure tree) or an Adobe Acrobat error (complaining about the additions)? Well, in a tagged PDF (and your PDF has the corresponding Marked entry set to true) the content including annotations and form fields is expected to be tagged. Thus, addition of structure tree entries for the newly added signature field and its appearance not only should be allowed but actually recommended or even required! So this appears to be an error of Adobe Acrobat.
A Work-AroundKnowing that this appears to be an Adobe Acrobat bug is all well and good, but at the end of the day one might need a way now to sign such documents multiple times without current Adobe Acrobat calling that invalid.
It is possible to make iText believe there is no structure tree and no need to update a structure tree. This can be done by making the initialization of the document tag structure fail. For this we override the PdfDocument
method TryInitTagStructure
. As the iText PdfSigner
creates its document object internally, we do this in an override of the PdfSigner
method InitDocument
.
I.e. instead of PdfSigner
we use the class MySigner
defined like this:
QUESTION
I try to add a watermark using itext in pdf. it work without problem using this code :
...ANSWER
Answered 2022-Jan-27 at 15:23You use page.newContentStreamBefore()
to add a content stream for your water mark. Thus, when the page is drawn, the watermark is drawn first and the content thereafter over it. For usual text and sparse vector graphics that is good but for full area covering content the watermark may be totally hidden.
Try to use page.newContentStreamAfter()
instead. But beware, you may not want to bold the watermark text then anymore, probably even restrict to outline only, as the mark now covers content.
In a question update and a comment you asked how to
make the text transparent.
Transparency usually is achieved by selecting a matching extended graphics state, e.g.:
QUESTION
I have been trying to convert some PDFs into .txt, but most sample codes I found online have the same issue: They only convert one page at a time. I am kinda new to python, and I am not finding how to write a substitute for the .GetPage() method to convert the entire document at once. All help is welcomed.
...ANSWER
Answered 2022-Jan-14 at 22:44You could do this with a for
loop. Extract the text from the pages in the loop and append them to a list.
QUESTION
Ifound some example.
However, all of the examples use PdfReader
.
I want to use PDFWriter
.
Below is the code I wrote.
...ANSWER
Answered 2021-Dec-02 at 00:31You could do both:
QUESTION
I'm currently working on a simple proof of concept for a pdf-editor application. The example is supposed to be a simplified python script showcasing how we could use the pdfrw library to edit PDF files with forms in them.
So, here's the issue. I'm not interested in writing the edited PDF to a file. The idea is that file opening and closing is going to most likely be handled by external code and so I want all the edits in my files to be done in memory. I don't want to write the edited filestream to a local file.
Let me specify what I mean by this. I currently have a piece of code like this:
...ANSWER
Answered 2021-Nov-22 at 14:07To save your altered PDF to memory in an object that can be passed around (instead of writing to a file), simply create an empty instance of io.BytesIO
:
QUESTION
With libraries like iTextSharp or iText you can extract metadata from PDF documents via a PdfReader:
...ANSWER
Answered 2021-Nov-09 at 10:07With PDF4NET you can extract the XMP metadata without loading the entire document in memory:
QUESTION
I have a Blazor application in which I'm trying to download a PDF I have edited using ITextSharp. All resources I search tend to use the Response class which I don't have (I believe because I am using .NET 6). I found some solutions that that send the byte array to a javascript function but I'm having no such luck. I get the error
System.ArgumentNullException: 'Value cannot be null.' When I Envoke the JS function.
I've posted my code below. Though I'm not passing any null objects, I do see some potential errors in my memory stream and I'm not sure why (See Image). Any information on where I'm going wrong or any easy approach would be appreciated. Thanks.
...ANSWER
Answered 2021-Sep-13 at 20:36For anyone who needs it, I solved this issue by creating a controller.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install PdfReader
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page