Quote:
I essentially need to either copy the 6 Vector icons which are located in OCG Layers to a new PDF, or delete all the Stroke/Vector Lines from the original file and save that.
Out of curiosity i had a look at your document.
What you're trying to achieve is probably doable, but it gets somewhat involved.
It helps, when you are able to look at your pdf in a text-editor.
For this i used mutool with the "clean" option (
https://mupdf.com/docs/manual-mutool-clean.html)
This helps identifying objects and seeing the overall document structure.
Having a clean pdf, we can look at the objects involved:
Page object:
Code:
9 0 obj
<<
/Contents 10 0 R <- Defines, what gets drawn onto the page
....
/Resources <<
/XObject <<
/Fm0 16 0 R <- Your icons are defined here, one XObject for each icon, note the Name (/Fm0 to /Fm5)
/Fm1 17 0 R
/Fm2 18 0 R
/Fm3 19 0 R
/Fm4 20 0 R
/Fm5 21 0 R
>>
.....
>>
/Type /Page
>>
endobj
The Page contents:
Code:
10 0 obj
<<
/Length 983
>>
stream <- Page-contents are a stream of drawing operators
....
q <- Save graphics state
0 0 0 RG <- Set stroke color
425 41 130 82 re <- Append rectangle to path
S <- Stroke path
Q <- Restore graphics state
....
q
1 0 0 1 354.23965 397.89322 cm <- Append transformation matrix
/C2_0 8 Tf <- Set drawing font (should not be necessary, but not sure)
/Fm0 Do <- Draw the icon (a named XObject, the name corresponds to an entry in the Resources/XObject dictionary above)
Q
I would try the following:
- open the document
- from the Catalog, delete the "OCProperties" to get rid of the layers (just to clean up, maybe you can keep it)
- create a PdfSharp.Pdf.Content.ContentReader for the page
- remove all operators not involved in drawing the icons, the goal is to end up with a content-stream like this:
Code:
q
1 0 0 1 354.23965 397.89322 cm
/C2_0 8 Tf <- maybe you can delete these as well
/Fm0 Do
Q
q
1 0 0 1 432.90109 397.89322 cm
/C2_0 8 Tf
/Fm1 Do
Q
....
- save the document
The steps may be incorrect and/or incomplete, but you should get the idea...
Quote:
Is there a way for me to Parse all Text Objects, find their Position and Value and then just use the XGraphics options in PDFSharp to just re-draw the text to a layer?
If the text is also wrapped in named XObjects, you can use the same method as described above.
But when the text is drawn directly onto the page, then it gets far more involved; you basically have to write your own pdf-rendering-engine, handling all kinds of font-stuff and drawing operators, just to get the positions right.
Thats outside my expertise, but i wish you best of luck !