Print Page | Close Window

DeleteOptionalContentGroup problem not save ?

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3515
Printed Date: 29 Apr 24 at 7:11AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: DeleteOptionalContentGroup problem not save ?
Posted By: mLipok
Subject: DeleteOptionalContentGroup problem not save ?
Date Posted: 16 Oct 17 at 7:32AM
I was using this snippet to add OptionalContentGroup:

Local $iOCG1 = $oQP.NewOptionalContentGroup("POUCZENIE")
Local $iCS_Id = $oQP.NewContentStream()
$oQP.SelectContentStream($iCS_Id)
$oQP.SaveState()

$oQP.SetTransparency(0) ; no transparency

Local $iIDFont = $oQP.AddTrueTypeFont('Arial {1250}', 0)
$oQP.SelectFont($iIDFont)
$oQP.SetBreakString(@CRLF)

$oQP.SetLineWidth(1)
$oQP.SetTextColor(1, 0, 0)
$oQP.SetLineColor(1, 0, 0)

$oQP.DrawLine( _
$aMaxBoundaries[$QPDF_CSVTEXTCOL_X4LD], _
$aMaxBoundaries[$QPDF_CSVTEXTCOL_Y4LD] + 10, _
$aMaxBoundaries[$QPDF_CSVTEXTCOL_X3RD], _
$aMaxBoundaries[$QPDF_CSVTEXTCOL_Y3RD] + 10 _
)

If Not @Compiled Then _ArrayDisplay($aMaxBoundaries, '$aMaxBoundaries')

Local $iIDFont = $oQP.AddTrueTypeFont('Arial {1250}', 0)
$oQP.SelectFont($iIDFont)
$oQP.SetBreakString(@CRLF)
$oQP.SetTextSize(8)
$oQP.SetTextAlign($__eQPDF_TEXTALIGN_Justified)

Local $iPouczenieWidth = $aMaxBoundaries[$QPDF_CSVTEXTCOL_X3RD] - $aMaxBoundaries[$QPDF_CSVTEXTCOL_X4LD]
Local $iLeft = $aMaxBoundaries[$QPDF_CSVTEXTCOL_X4LD]
Local $iTop = $aMaxBoundaries[$QPDF_CSVTEXTCOL_Y4LD] + 20

_QPDF_SetDefaultCoordinates($oQP)
$oQP.DrawWrappedText($iLeft, $iTop, $iPouczenieWidth, $sPouczenie_Text)

$oQP.SetContentStreamOptional($iOCG1)
$oQP.SetOptionalContentGroupVisible($iOCG1, 1)
$oQP.SetOptionalContentGroupPrintable($iOCG1, 1)
$oQP.LoadState()



My problem is that currently I can not delete this OCG
$oQP.SelectContentStream(1)
MsgBox(0, 'Save ?', $oQP.ContentStreamSafe())
MsgBox(0, 'Delete Result:', $oQP.DeleteOptionalContentGroup($oQP.GetOptionalContentGroupID(1)))

So First MsgBox is saying 0 and second MsgBox is saying 1

But when I use 
$oQP.SaveToFile($sPDF_FileFullPath & '__Deleted_Pouczenie.pdf')

I still have this OCG visible in this PDF file.

Do I'm doing something wrong ?



-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600



Replies:
Posted By: mLipok
Date Posted: 16 Oct 17 at 7:43AM
btw.
Foxit Quick PDF Library 14.11 Reference Guide.pdf

in description for .DeleteOptionalContentGroup

is not specyfing that return value are 0 or 1 but it is.

The return value is exactly like mentioned in Foxit Quick PDF Library 14 Developer Guide.pdf
If a function is not documented as having a return value then you can assume that a return value of one (1) indicates success. A returning value of zero (0) indicates failure. Other returned values indicate valid handle or ID and what this ID is for can be determined by the function name.

so the return Value for .DeleteOptionalContentGroup is showing properly 1 and 0 for example when I select non existen OCG.




-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: mLipok
Date Posted: 16 Oct 17 at 7:45AM
The other question is why 
$oQP.SelectContentStream(1)
MsgBox(0, 'Save ?', $oQP.ContentStreamSafe())

is saying 0

??


As I showed before I used QPDF to create this OCG



-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: mLipok
Date Posted: 16 Oct 17 at 8:06AM
Originally posted by mLipok mLipok wrote:

The other question is why 
$oQP.SelectContentStream(1)
MsgBox(0, 'Save ?', $oQP.ContentStreamSafe())

is saying 0

??


As I showed before I used QPDF to create this OCG


Now I figured it out.
$oQP.ContentStreamSafe() was saing 0 as I need also select Page
$oQP.SelectPage(2) MsgBox(0, 'Select Result', $oQP.SelectContentStream(1)) MsgBox(0, 'Save ?', $oQP.ContentStreamSafe())

I figured it out when I was trying to use:
$oQP.SetOptionalContentGroupVisible($iGroupID, 0)
$oQP.SetOptionalContentGroupPrintable($iGroupID, 0) 

Which was not working until I use $oQP.SelectPage(2)

But .DeleteOptionalContentGroup is still not working even if I select proper page.



-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: mLipok
Date Posted: 16 Oct 17 at 8:28AM
QUESTION:
Do you know any way to find on which page is located specyfic OCG ?



-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: ukobsa
Date Posted: 16 Oct 17 at 3:59PM
Hi,

just tested it with this code (14.11): and here the second PDF do no longer have the OCG layer (just the layer; content is still visible)


  lPDF  := TDebenuPDFLibrary.Create;
  try
    lPDF.SetOrigin(1);
    lPDF.AddStandardFont(1);
    lPDF.DrawText(100, 50, 'Regulärer Text');

    lPDF.NewContentStream;
    lPDF.DrawText(100, 100, '1. Layer DUMMY added');

    nOC := lPDF.NewOptionalContentGroup('DUMMY');
    lPDF.SetContentStreamOptional(nOC);
    lPDF.SetOptionalContentGroupVisible(nOC, 0);

    lPDF.SaveToFile('.\test_oc_dummy.pdf');

    nRes := lPDF.DeleteOptionalContentGroup(nOC);
    // nRes is set to 1 when executing

    lPDF.SaveToFile('.\test_oc_dummy_del.pdf');
  finally
    lPDF.Free;
  end;


Does this help?


Posted By: mLipok
Date Posted: 16 Oct 17 at 7:16PM
Thanks. I will give it a try. And back with results.

-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: mLipok
Date Posted: 16 Oct 17 at 7:36PM
Your example is like this:

    ......
    lPDF.NewContentStream;
    lPDF.DrawText(100, 100, '1. Layer DUMMY added');

    nOC := lPDF.NewOptionalContentGroup('DUMMY');
    lPDF.SetContentStreamOptional(nOC);
    lPDF.SetOptionalContentGroupVisible(nOC, 0)
    .......

My is like this:

    ......
    nOC := lPDF.NewOptionalContentGroup('DUMMY');
    lPDF.NewContentStream;
    lPDF.DrawText(100, 100, '1. Layer DUMMY added');

    lPDF.SetContentStreamOptional(nOC);
    lPDF.SetOptionalContentGroupVisible(nOC, 0)
    .......

I'm wondering if I doing this wrong ?



-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: mLipok
Date Posted: 16 Oct 17 at 9:51PM
@ukobsa
I have used your example in AutoIt and I have such example:

Func _Example2()
Local $oQP
If _QPDF_CreateObjectAndUnlock($oQP) = $QPDF_RET_VALID_COMMERCIAL Then
$oQP.SetOrigin(1) ;
$oQP.AddStandardFont(1) ;
$oQP.DrawText(100, 50, 'Regulärer Text') ;

$oQP.NewContentStream ;
$oQP.DrawText(100, 100, '1. Layer DUMMY added') ;

Local $iOC = $oQP.NewOptionalContentGroup('DUMMY') ;
$oQP.SetContentStreamOptional($iOC) ;
$oQP.SetOptionalContentGroupVisible($iOC, 0) ;

$oQP.SaveToFile(@ScriptDir & '\test_oc_dummy.pdf') ;

Local $iRes = $oQP.DeleteOptionalContentGroup($iOC) ;
MsgBox(0, '$iRes', $iRes)
;~     // $iRes is set to 1 when executing

$oQP.SaveToFile(@ScriptDir & '\test_oc_dummy_del.pdf') ;
EndIf
EndFunc   ;==>_Example2

The results are here:
http://lipok.pl/Debenu/test_oc_dummy.pdf
http://lipok.pl/Debenu/test_oc_dummy_del.pdf

REMARK: 
Downlad this two files, and open in AcrobatReader not in GoogleChrome or in any other WebBrowser.


You should notice that:
test_oc_dummy_del.pdf

still contains "1. Layer DUMMY added" text .


I expected that deleting OCG would also remove all content inside this OCG.

But that did not happen.
Question is :  Why that did not happen ?



-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: Ingo
Date Posted: 16 Oct 17 at 10:31PM
Hi :)

here are two links with similar problems.
The second one was the interesting one for you.
Rowan is telling there something about the meaning of these OptionalContentGroups and why the content is still there obviously you've deleted the OCG ;-)
http://www.quickpdf.org/forum/delete-optionalcontentgroup_topic3253.html
http://www.quickpdf.org/forum/help-with-detecting-visible-ocgs-and-removing-ocgs_topic3153.html



-------------
Cheers,
Ingo




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk