Hello,
I'm not sure if this answer will reach you, because you're not
officially registered on the mailing-list (I had to approve your
question manually).
There are two answers to your question.
On 24/10/2012 17:25, pennettat wrote:
> Hi all,
>
> I am new to the iText community and am using the C# version of the library.
>
> I have an existing PDF which I have to add content on top of (lines, curves,
> text, etc). I have the new content given to me in a text file of Content
> Stream... an example is below of the Content Stream:
>
> ********START CONTENT STREAM*********
> q
> 1 0 0 1 29.046181172291313 823.6838365896981 cm
> 0.1678507992895204 0 0 -0.1678507992895204 0 0 cm
> 0 G
> 0 g
> 4.265151515151516 w
> 1 J
> 1 j
> 92 4437 m
> 97 4425 l
> 102 4411 l
> 2298 1700 l
> 2300 1701 l
> S
> 2351 1636 m
> 2357 1634 l
> 2362 1633 l
> 2369 1633 l
> 2378 1633 l
> 2387 1633 l
> 2396 1633 l
> 2405 1633 l
> 2414 1632 l
> 2422 1632 l
> S
> 2419 1630 m
> 2412 1643 l
> 2407 1658 l
> 2403 1677 l
> 2400 1696 l
> 2401 1717 l
> 2405 1737 l
> S
> Q
>
> ********END CONTENT STREAM***********
>
> Is there a way I can insert this to a new layer or directly to the PDF using
> a Stamper or Writer? The library has so many classes and functions to tinker
> with.
There is a way to insert this particular content stream to an existing PDF.
PdfReader reader = new PdfReader(original_file);
using (var ms = new MemoryStream()) {
using (PdfStamper stamper = new PdfStamper(reader, ms)) {
PdfContentByte canvas = stamper.GetOverContent(1);
canvas.SetLiteral(your_stream);
}
return ms.ToArray();
}
I think this will work (I can't guarantee it), because I don't see any
important changes of the Graphics State, I don't see any XObjects being
called, I don't see any references to fonts, etc...
The only question I have is: how on earth do you know that the lines
you're drawing will fit the page?
You're completely changing the coordinate system, for instance in this line:
0.1678507992895204 0 0 -0.1678507992895204 0 0 cm
You're scaling everything down and I think you're also flipping the
coordinate system upside-down.
I really don't understand why you would want to add PDF syntax to
existing content this way. Your PDF Fu must be very mighty if you want
this to work.
I apologize in advance if I'm wrong, but I fear that your PDF Fu is
inexistent. Why do I think so? Because you're saying "I have to add
content on top of (lines, curves, text, etc). I have the new content
given to me in a text file of Content Stream. "
Lines and curves OK as long as there's no external graphics state
object, but text? The fact that you include "text" in your description
of possible content, and the fact that you say that the content is give
in a text file of Content Stream doesn't make sense. Either you're lying
or you don't understand that what you say is impossible.
When you have PDF syntax for text, you have something like this:
BT
36 806 Td
/F1 12 Tf
(Hello World!)Tj
0 0 Td
ET
You're alleging that this is sufficient to add the words "Hello World"
at position 36, 806. This is a wrong assumption.
Which font do you want to use?
Your answer: I guess /F1
My question: what is /F1? Is it Helvetica, Courier,...?
Your answer: ???
Fact is that /F1 is a name that refers to a font dictionary that is
listed in the resources of the page or the XObject to which the content
stream belongs. If you only have the content stream in text format,
there is no way of knowing which font should be used.
If you add such a snippet to an existing PDF, you'll end up with a
corrupt PDF (regardless whether or not you're using iTextSharp or any
other tool).
So please rephrase your question. Explain why you would design an
application like this.
Or forget about the idea and don't tell anyone you ever had it.
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php