Search code examples
c#pdfpdfclown

PDFClown cannot edit created PDF


I’m using PDF Clown (in C#) to generate a PDF file containing graphics (lines, polygons and circles) on separate layers. Now I run into a problem and I have searched the internet for days but cannot find the solution.

I have the following problem: How can I make sure that the PDF generated by PDFClown can be edited/modified using another application like for instance Blue Beam or Adobe Acrobat? At this moment the generated PDF looks ok but I’m unable to select and modify any of the graphics (lines, polygons etc.) on any layer.

Should I set something during creating layers or graphic objects?

A link to the generated file: https://drive.google.com/open?id=1om4UByGhfS1D9OOCYzhHrNjNQeNcJI-0

I would really appreciate your help! Following is piece of the code where a polyline is created.

var pdfFile = new File();

m_PdfDocument = pdfFile.Document;
m_PdfDocument.PageSize = PageFormat.GetSize(PageFormat.SizeEnum.A4);
m_PdfDocument.Version = Version.Get("1.6");


m_PdfPage = new Page(m_PdfDocument);
m_PdfDocument.Pages.Add(m_PdfPage);

var primitiveComposer = new PrimitiveComposer(m_PdfPage);

primitiveComposer.SetLineJoin(LineJoinEnum.Miter);
primitiveComposer.SetLineCap(LineCapEnum.Square);
primitiveComposer.SetLineWidth(2);

primitiveComposer.SetStrokeColor(DeviceRGBColor.Get(System.Drawing.Color.Black))
// Flip Y axis!
primitiveComposer.SetMatrix(1, 0, 0, -1, 0, m_PdfPage.Size.Height);

primitiveComposer.BeginLayer(layer);
primitiveComposer.DrawPolyline(line.ToArray());
primitiveComposer.Stroke();
primitiveComposer.End();

primitiveComposer.Flush();

pdfFile.Save(filename, SerializationModeEnum.Standard);

Edit2: New test file https://drive.google.com/open?id=1PHACkr2EcWrdIP5XocCnwDtakQ-P0hJY

Edit 18-01-2019 In Bluebeam Revu a polyline entry looks like this:

%PDF-1.5
%Çì¢
1 0 obj<</CreationDate(D:20190111132455+01'00')/ModDate(D:20190111132818+01'00')/Aut
hor(e.debont)/Creator(Bluebeam Revu x64)/Producer(Bluebeam PDF Library 18)>>
endobj
2 0 obj<</Type/Catalog/Pages 3 0 R/OCProperties 7 0 R>>
endobj
3 0 obj<</Type/Pages/Kids[4 0 R]/Count 1>>
endobj
4 0 obj<</Type/Pages/Kids[5 0 R]/Count 1/Parent 3 0 R>>
endobj
5 0 obj<</Type/Page/Parent 4 0 R/MediaBox[0 0 594.72 841.68]/Annots 19 0 R>>
endobj
6 0 obj<</Order[8 0 R]>>
endobj
7 0 obj<</OCGs[8 0 R]/D 6 0 R>>
endobj
8 0 obj<</Type/OCG/Name(Test)>>
endobj
19 0 obj[21 0 R]
endobj
21 0 obj<</Subj(Polylijn)/Type/Annot/P 5 0 R/F 4/C[1 0 0]/CreationDate
(D:20190111132642+01'00')/T(e.debont)/Subtype/PolyLine/AP<</N
22 0 R>>/IC[1 0 0]/M(D:20190111132642+01'00')/Vertices[225.8323 629.0071 
273.3759 657.8729 354.8793 583.5859]/Rect[220.3323 578.0859 360.3793 
663.3729]/NM(MQJCWGUIXHEAEWJU)/OC 8 0 R>>
endobj
22 0 obj<</Type/XObject/Subtype/Form/FormType 1/BBox[220.3323 578.0859 
360.3793 663.3729]/Resources<</ProcSet[/PDF]>>/Matrix[1 0 0 1 -220.3323 
-578.0859]/Length 84>>
stream
1 0 0 RG 1 0 0 rg 1 w 225.8323 629.0071 m 273.3759 657.8729 l 354.8793 
583.5859 l S 
endstream
endobj
xref
0 23
0000000000 65535 f 
0000000015 00000 n 
0000000183 00000 n 
0000000246 00000 n 
0000000296 00000 n 
0000000359 00000 n 
0000000443 00000 n 
0000000475 00000 n 
0000000514 00000 n 
0000000000 65535 f 
0000000000 65535 f 
0000000000 65535 f 
0000000000 65535 f 
0000000000 65535 f 
0000000000 65535 f 
0000000000 65535 f 
0000000000 65535 f 
0000000000 65535 f 
0000000000 65535 f 
0000000553 00000 n 
0000000000 65535 f 
0000000577 00000 n 
0000000900 00000 n 
trailer<</Size 23/Info 1 0 R/ID[<2753c66a6950982e644007ca4324fe83> 
<2753c66a6950982e644007ca4324fe83>]/Root 2 0 R>>
startxref
1175
%%EOF

PDFClown generates this (between stream and endstream there is binary data):

9 0 obj
<</Filter /FlateDecode /Length 60 >>
stream
Binary data
endstream
endobj
10 0 obj
<</Type /OCMD /P /AllOn /OCGs [8 0 R ] >>
endobj
11 0 obj
<</Type /XObject /Subtype /Form /BBox [0 0 594.71997 841.67999 ] /Resources 
<</Properties <</1 10 0 R >> >> /Filter /FlateDecode /Length 60 >>
stream
Binary data
endstream
endobj

How can I using PDFClown write the Bluebeam output? Or at least how do I prevent using /Filter /FlateDecode?


Solution

  • The example PDF contents posted indicate that the kind of line graphics your target PDF editing software can edit are not the paths in the page content but instead PolyLine annotations.

    You can create a simple PolyLine annotation with PDF Clown like this:

    org.pdfclown.files.File file = new org.pdfclown.files.File();
    Document document = file.Document;
    Page page = new Page(document);
    document.Pages.Add(page);
    
    new Polyline(page, page.Box, "Test-PolyLine")
    {
        Color = new DeviceRGBColor(1, 0, 0),
        Vertices = new List<PointF>() { new PointF(50, 50), new PointF(50, 250), new PointF(150, 150), new PointF(250, 250), new PointF(250, 50) }
    };
    
    file.Save("PolyLine-PdfClown.pdf", SerializationModeEnum.Standard);
    

    The result in Adobe Reader:

    screen shot