Good news, More tests showed that android.graphics.pdf.PdfRenderer did not draw the page background and if I remove all fill operations I get the desired result!. I'll now try to determine the size of the path being filled. Btw I keep getting a "BufferedOutputStream is closed" exception but the new file is being created.
PDDocument doc = null; try { try { int i = 0; doc = PDDocument.load(new File(filename)); for (PDPage page : doc.getPages()) { PDRectangle pageSize = page.getMediaBox(); PDFStreamParser parser = new PDFStreamParser(page); parser.parse(); List<Object> tokens = parser.getTokens(); List<Object> newTokens = new ArrayList<Object>(); for (Object token : tokens) { if (token instanceof Operator) { Operator op = (Operator)token; // remove fill operations if (op.getName().equals("f")) { // newTokens.remove( newTokens.size() -1 ); Log.i("pdfbox", op.getName()); continue; } } newTokens.add(token); } PDStream newContents = new PDStream(doc); OutputStream out = newContents.createOutputStream(COSName.FLATE_DECODE); ContentStreamWriter writer = new ContentStreamWriter(out); writer.writeTokens(newTokens); out.close(); page.setContents(newContents); } doc.save("/sdcard/VideoAssist/graphic/temp.pdf"); doc.close(); } catch (Exception e) { } On 23 Jun 2016 12:10 pm, "Robert Van Gemert" <rcvangem...@gmail.com> wrote: > Hi Tilman, > > I tried your idea but am having trouble getting the result I wanted. My > hope was to use a stock standard pdf rendering library (mupdf or > android.graphics.pdf.PdfRenderer ) to render to a bitmap and then use > opengl to do the blend. However mupdf renders a white background BEFORE > rendering the pdf commands. So I will try to modify mupdf. > > Thanks for your help, > Robert. > On 22 Jun 2016 4:25 pm, "Tilman Hausherr" <thaush...@t-online.de> wrote: > >> Am 22.06.2016 um 00:05 schrieb Robert Van Gemert: >> >>> Files exported from android google slides would work for me. >>> >>> https://www.dropbox.com/s/ncnjt8tlgzasb6f/slide_test.pdf?dl=0 >>> >> >> Strategy 1: >> use the command line utilities, run WriteDecodedDoc, then use an editor >> and overwrite this part with blanks: >> >> /Image3 >> Do >> >> >> The file is huge now, sadly. >> >> Strategy 2: >> >> In the source code download, in the examples, there's a program >> RemoveAllText.java. That one shows how to work with the content stream: >> >> for (Object token : tokens) >> { >> if( token instanceof Operator) >> { >> Operator op = (Operator)token; >> if( op.getName().equals( "TJ") || >> op.getName().equals( "Tj" )) >> { >> //remove the one argument to this operator >> newTokens.remove( newTokens.size() -1 ); >> continue; >> } >> } >> newTokens.add( token ); >> } >> >> Now you don't want to remove "TJ", you want to remove "Do". I just tested >> this, it works for your file. (But it might now work with files that have a >> different structure). >> >> Tilman >> >> >> >> >>> Thanks for your help. >>> >>> Robert >>> On 22 Jun 2016 2:32 am, "Tilman Hausherr" <thaush...@t-online.de> wrote: >>> >>> Am 21.06.2016 um 13:12 schrieb Robert Van Gemert: >>>> >>>> Hi, >>>>> >>>>> I wish to use pdf as a graphics overlay over video so I need to make >>>>> the >>>>> page background transparent or remove it. Can I use pdfbox to >>>>> preprocess a >>>>> pdf file? >>>>> My OS is Android. Initial tests show I cannot use pdfbox for rendering >>>>> but >>>>> preprocessing may work. >>>>> >>>>> Thanks, >>>>> >>>>> Robert >>>>> >>>>> >>>>> This is difficult to answer as there may be many methods to put a >>>> "background". There is no <BACKGROUND="image.jpg"/> command in PDF. Does >>>> your question apply to one specific PDF or to all possible PDFs in the >>>> world? If only one, please upload it somewhere. >>>> >>>> Tilman >>>> >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org >>>> For additional commands, e-mail: users-h...@pdfbox.apache.org >>>> >>>> >>>> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org >> For additional commands, e-mail: users-h...@pdfbox.apache.org >> >>