title: PL/SQL Overwrite File with new Info without appending
body: <p>I'm building a PDF on my FTP Folder to send it via a Daemon, the file it's OK, but every time I put it there again this file is appended with information, PDF naturally only reads the LAST instruction, but in order to create a clean File I need to create each time a blank PDF.</p>
  
  <ol>
  <li>Create PDF</li>
  <li>Write info (UTL_FILE.PUT_LINE)</li>
  <li>Close File</li>
  </ol>
  
  <p>but if I need to create another file with same layer but new info, my process to create a file with some name and this find the old one and APPEND the information.</p>
  
  <p>I need to blank that file and put the new info, what should I do to avoid append that info?</p>
  
  <p>CODE: (it's the library of PL_FPDF modified to write files in a directory)</p>
  
  <pre><code>--some code!
  elsif (myDest = 'F') then
      -- DFVD -- Enviar a directorio
      -- Content Restriction
      v_len := 1;
  
      for i in pdfDoc.first..pdfDoc.last loop
          v_clob := to_clob(pdfDoc(i));
          if v_clob is not null then
              v_in := 1;
              v_out := 1;
              v_lang := 0;
              v_warning := 0;
              v_len := dbms_lob.getlength(v_clob);
  
              dbms_lob.convertToBlob(v_blob, v_clob, v_len, v_in, v_out, dbms_lob.default_csid, v_lang, v_warning);
  
  
              dbms_lob.append(v_doc, dbms_lob.substr(v_blob, v_len));   
          end if;
      end loop;
  
      l_blob_len := DBMS_LOB.getlength(v_doc);
      l_file := UTL_FILE.fopen('FTP_DIR',myName,'w', 32767);
  
      WHILE l_pos &lt; l_blob_len LOOP
          DBMS_LOB.read(v_doc, l_amount, l_pos, l_buffer);
          UTL_FILE.put_raw(l_file, l_buffer, TRUE);
          l_pos := l_pos + l_amount;
      END LOOP;
  
      UTL_FILE.fclose(l_file);
  else
  --some code!
  </code></pre>
  
  <p>THE INTERNAL CODE OF THE PDF LOOKS LIKE THIS:</p>
  
  <pre><code>%PDF-1.3
  3 0 obj
  &lt;&lt;/Type /Page
  /Parent 1 0 R
  /Resources 2 0 R
  /Contents 4 0 R&gt;&gt;
  endobj
  4 0 obj
  &lt;&lt;/Length 2401&gt;&gt;
  stream
  2 J
  0.56 w
  BT /F1 12.0 Tf ET
  BT /F2 20.0 Tf ET
  0.0 0.4 0.8 rg
  28.35 813.54 538.57 -28.34 re f 28.35 813.54 m 28.35 785.19 l S 28.35 813.54 m 566.92 813.54 l S 566.92 813.54 m 566.92 785.19 l S 28.35 785.19 m 566.92 785.19 l S q 1.0 1.0 1.0 rg BT 190.95 793.36 Td (Informe Liquidaciones) Tj ET Q
  BT /F2 9.0 Tf ET
  q 0.0 g BT 31.18 768.32 Td (Fecha: 17-02-2016) Tj ET Q
  28.35 728.50 m 28.35 700.15 l S 28.35 728.50 m 170.08 728.50 l S 28.35 700.15 m 170.08 700.15 l S q 0.0 g BT 115.74 711.62 Td (Devolucion:) Tj ET Q
  170.08 728.50 m 566.92 728.50 l S 566.92 728.50 m 566.92 700.15 l S 170.08 700.15 m 566.92 700.15 l S 
  28.35 697.31 m 28.35 668.97 l S 28.35 697.31 m 396.85 697.31 l S q 0.0 g BT 304.99 680.44 Td (Cantidad de Primas  ) Tj ET Q
  396.85 697.31 m 566.92 697.31 l S 566.92 697.31 m 566.92 668.97 l S q 0.0 g BT 399.68 680.44 Td (  Monto Recaudado) Tj ET Q
  28.35 668.97 m 28.35 640.62 l S q 0.0 g BT 31.18 652.09 Td (  Recaudado Tarjeta Ripley) Tj ET Q
  q 0.0 g BT 389.01 652.09 Td (  ) Tj ET Q
  566.92 668.97 m 566.92 640.62 l S q 0.0 g BT 399.68 652.09 Td (  ) Tj ET Q
  28.35 640.62 m 28.35 612.28 l S q 0.0 g BT 31.18 623.75 Td (  Recaudado OMP) Tj ET Q
  q 0.0 g BT 389.01 623.75 Td (  ) Tj ET Q
  566.92 640.62 m 566.92 612.28 l S q 0.0 g BT 399.68 623.75 Td (  ) Tj ET Q
  28.35 612.28 m 28.35 583.93 l S 28.35 583.93 m 396.85 583.93 l S q 0.0 g BT 31.18 595.40 Td (  Devoluciones no Pago Mes Anterior:) Tj ET Q
  566.92 612.28 m 566.92 583.93 l S 396.85 583.93 m 566.92 583.93 l S q 0.0 g BT 399.68 595.40 Td (  ) Tj ET Q
  28.35 578.26 m 28.35 549.91 l S 28.35 578.26 m 396.85 578.26 l S 28.35 549.91 m 396.85 549.91 l S q 0.0 g BT 313.50 561.39 Td (Total Recaudado:  ) Tj ET Q
  396.85 578.26 m 566.92 578.26 l S 566.92 578.26 m 566.92 549.91 l S 396.85 549.91 m 566.92 549.91 l S q 0.0 g BT 399.68 561.39 Td (  ) Tj ET Q
  BT /F1 8.0 Tf ET
  q 0.0 g BT 31.18 526.25 Td (Comentarios) Tj ET Q
  BT /F1 9.0 Tf ET
  28.35 521.57 m 28.35 408.18 l S 28.35 521.57 m 566.92 521.57 l S 566.92 521.57 m 566.92 408.18 l S 28.35 408.18 m 566.92 408.18 l S 
  BT /F2 9.0 Tf ET
  q 0.0 g BT 67.93 199.97 Td (_____________________) Tj ET Q
  q 0.0 g BT 252.18 199.97 Td (_____________________) Tj ET Q
  q 0.0 g BT 429.34 199.97 Td (_____________________) Tj ET Q
  q 0.0 g BT 86.46 185.80 Td (some guy) Tj ET Q
  q 0.0 g BT 260.96 185.80 Td (some guy) Tj ET Q
  q 0.0 g BT 447.62 185.80 Td (some guy) Tj ET Q
  
  endstream
  endobj
  1 0 obj
  &lt;&lt;/Type /Pages
  /Kids [3 0 R ]
  /Count 1
  /MediaBox [0 0 595.28 841.89]
  &gt;&gt;
  endobj
  5 0 obj
  &lt;&lt;/Type /Font
  /BaseFont /Helvetica
  /Subtype /Type1
  /Encoding /WinAnsiEncoding
  &gt;&gt;
  endobj
  6 0 obj
  &lt;&lt;/Type /Font
  /BaseFont /Helvetica-Bold
  /Subtype /Type1
  /Encoding /WinAnsiEncoding
  &gt;&gt;
  endobj
  2 0 obj
  &lt;&lt;
  /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
  /Font &lt;&lt;
  /F1 5 0 R
  /F2 6 0 R
  &gt;&gt;
  /XObject &lt;&lt;
  &gt;&gt;
  &gt;&gt;
  endobj
  7 0 obj
  &lt;&lt;
  /Producer (PL_FPDF 0.9.3 portage pour Laclasse.com par P.G. Levallois de la version 1.53 de PHP/FPDF d'Olivier Plathey.)
  /Title (Informe Liquidaciones a Companias)
  /Author ()
  /Creator ()
  /CreationDate (D:20160217160717)
  &gt;&gt;
  endobj
  8 0 obj
  &lt;&lt;
  /Type /Catalog
  /Pages 1 0 R
  /OpenAction [3 0 R /FitH null]
  /PageLayout /OneColumn
  &gt;&gt;
  endobj
  xref
  0 9
  0000000000 65535 f 
  0000002538 00000 n 
  0000002822 00000 n 
  0000000009 00000 n 
  0000000087 00000 n 
  0000002625 00000 n 
  0000002721 00000 n 
  0000002936 00000 n 
  0000003189 00000 n 
  trailer
  &lt;&lt;
  /Size 9
  /Root 8 0 R
  /Info 7 0 R
  &gt;&gt;
  startxref
  3292
  %%EOF
  %PDF-1.3
  3 0 obj
  &lt;&lt;/Type /Page
  /Parent 1 0 R
  /Resources 2 0 R
  /Contents 4 0 R&gt;&gt;
  endobj
  4 0 obj
  &lt;&lt;/Length 2401&gt;&gt;
  stream
  2 J
  0.56 w
  BT /F1 12.0 Tf ET
  BT /F2 20.0 Tf ET
  0.0 0.4 0.8 rg
  28.35 813.54 538.57 -28.34 re f 28.35 813.54 m 28.35 785.19 l S 28.35 813.54 m 566.92 813.54 l S 566.92 813.54 m 566.92 785.19 l S 28.35 785.19 m 566.92 785.19 l S q 1.0 1.0 1.0 rg BT 190.95 793.36 Td (Informe Liquidaciones) Tj ET Q
  BT /F2 9.0 Tf ET
  q 0.0 g BT 31.18 768.32 Td (Fecha: 17-02-2016) Tj ET Q
  28.35 728.50 m 28.35 700.15 l S 28.35 728.50 m 170.08 728.50 l S 28.35 700.15 m 170.08 700.15 l S q 0.0 g BT 115.74 711.62 Td (Devolucion:) Tj ET Q
  170.08 728.50 m 566.92 728.50 l S 566.92 728.50 m 566.92 700.15 l S 170.08 700.15 m 566.92 700.15 l S 
  28.35 697.31 m 28.35 668.97 l S 28.35 697.31 m 396.85 697.31 l S q 0.0 g BT 304.99 680.44 Td (Cantidad de Primas  ) Tj ET Q
  396.85 697.31 m 566.92 697.31 l S 566.92 697.31 m 566.92 668.97 l S q 0.0 g BT 399.68 680.44 Td (  Monto Recaudado) Tj ET Q
  28.35 668.97 m 28.35 640.62 l S q 0.0 g BT 31.18 652.09 Td (  Recaudado Tarjeta Ripley) Tj ET Q
  q 0.0 g BT 389.01 652.09 Td (  ) Tj ET Q
  566.92 668.97 m 566.92 640.62 l S q 0.0 g BT 399.68 652.09 Td (  ) Tj ET Q
  28.35 640.62 m 28.35 612.28 l S q 0.0 g BT 31.18 623.75 Td (  Recaudado OMP) Tj ET Q
  q 0.0 g BT 389.01 623.75 Td (  ) Tj ET Q
  566.92 640.62 m 566.92 612.28 l S q 0.0 g BT 399.68 623.75 Td (  ) Tj ET Q
  28.35 612.28 m 28.35 583.93 l S 28.35 583.93 m 396.85 583.93 l S q 0.0 g BT 31.18 595.40 Td (  Devoluciones no Pago Mes Anterior:) Tj ET Q
  566.92 612.28 m 566.92 583.93 l S 396.85 583.93 m 566.92 583.93 l S q 0.0 g BT 399.68 595.40 Td (  ) Tj ET Q
  28.35 578.26 m 28.35 549.91 l S 28.35 578.26 m 396.85 578.26 l S 28.35 549.91 m 396.85 549.91 l S q 0.0 g BT 313.50 561.39 Td (Total Recaudado:  ) Tj ET Q
  396.85 578.26 m 566.92 578.26 l S 566.92 578.26 m 566.92 549.91 l S 396.85 549.91 m 566.92 549.91 l S q 0.0 g BT 399.68 561.39 Td (  ) Tj ET Q
  BT /F1 8.0 Tf ET
  q 0.0 g BT 31.18 526.25 Td (Comentarios) Tj ET Q
  BT /F1 9.0 Tf ET
  28.35 521.57 m 28.35 408.18 l S 28.35 521.57 m 566.92 521.57 l S 566.92 521.57 m 566.92 408.18 l S 28.35 408.18 m 566.92 408.18 l S 
  BT /F2 9.0 Tf ET
  q 0.0 g BT 67.93 199.97 Td (_____________________) Tj ET Q
  q 0.0 g BT 252.18 199.97 Td (_____________________) Tj ET Q
  q 0.0 g BT 429.34 199.97 Td (_____________________) Tj ET Q
  q 0.0 g BT 86.46 185.80 Td (some guy) Tj ET Q
  q 0.0 g BT 260.96 185.80 Td (some guy) Tj ET Q
  q 0.0 g BT 447.62 185.80 Td (some guy) Tj ET Q
  
  endstream
  endobj
  1 0 obj
  &lt;&lt;/Type /Pages
  /Kids [3 0 R ]
  /Count 1
  /MediaBox [0 0 595.28 841.89]
  &gt;&gt;
  endobj
  5 0 obj
  &lt;&lt;/Type /Font
  /BaseFont /Helvetica
  /Subtype /Type1
  /Encoding /WinAnsiEncoding
  &gt;&gt;
  endobj
  6 0 obj
  &lt;&lt;/Type /Font
  /BaseFont /Helvetica-Bold
  /Subtype /Type1
  /Encoding /WinAnsiEncoding
  &gt;&gt;
  endobj
  2 0 obj
  &lt;&lt;
  /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
  /Font &lt;&lt;
  /F1 5 0 R
  /F2 6 0 R
  &gt;&gt;
  /XObject &lt;&lt;
  &gt;&gt;
  &gt;&gt;
  endobj
  7 0 obj
  &lt;&lt;
  /Producer (PL_FPDF 0.9.3 portage pour Laclasse.com par P.G. Levallois de la version 1.53 de PHP/FPDF d'Olivier Plathey.)
  /Title (Informe Liquidaciones a Companias)
  /Author ()
  /Creator ()
  /CreationDate (D:20160217160747)
  &gt;&gt;
  endobj
  8 0 obj
  &lt;&lt;
  /Type /Catalog
  /Pages 1 0 R
  /OpenAction [3 0 R /FitH null]
  /PageLayout /OneColumn
  &gt;&gt;
  endobj
  xref
  0 9
  0000000000 65535 f 
  0000006086 00000 n 
  0000006370 00000 n 
  0000003557 00000 n 
  0000003635 00000 n 
  0000006173 00000 n 
  0000006269 00000 n 
  0000006484 00000 n 
  0000006737 00000 n 
  trailer
  &lt;&lt;
  /Size 9
  /Root 8 0 R
  /Info 7 0 R
  &gt;&gt;
  startxref
  6840
  %%EOF
  %PDF-1.3
  3 0 obj
  &lt;&lt;/Type /Page
  /Parent 1 0 R
  /Resources 2 0 R
  /Contents 4 0 R&gt;&gt;
  endobj
  4 0 obj
  &lt;&lt;/Length 2401&gt;&gt;
  stream
  2 J
  0.56 w
  BT /F1 12.0 Tf ET
  BT /F2 20.0 Tf ET
  0.0 0.4 0.8 rg
  28.35 813.54 538.57 -28.34 re f 28.35 813.54 m 28.35 785.19 l S 28.35 813.54 m 566.92 813.54 l S 566.92 813.54 m 566.92 785.19 l S 28.35 785.19 m 566.92 785.19 l S q 1.0 1.0 1.0 rg BT 190.95 793.36 Td (Informe Liquidaciones) Tj ET Q
  BT /F2 9.0 Tf ET
  q 0.0 g BT 31.18 768.32 Td (Fecha: 17-02-2016) Tj ET Q
  28.35 728.50 m 28.35 700.15 l S 28.35 728.50 m 170.08 728.50 l S 28.35 700.15 m 170.08 700.15 l S q 0.0 g BT 115.74 711.62 Td (Devolucion:) Tj ET Q
  170.08 728.50 m 566.92 728.50 l S 566.92 728.50 m 566.92 700.15 l S 170.08 700.15 m 566.92 700.15 l S 
  28.35 697.31 m 28.35 668.97 l S 28.35 697.31 m 396.85 697.31 l S q 0.0 g BT 304.99 680.44 Td (Cantidad de Primas  ) Tj ET Q
  396.85 697.31 m 566.92 697.31 l S 566.92 697.31 m 566.92 668.97 l S q 0.0 g BT 399.68 680.44 Td (  Monto Recaudado) Tj ET Q
  28.35 668.97 m 28.35 640.62 l S q 0.0 g BT 31.18 652.09 Td (  Recaudado Tarjeta Ripley) Tj ET Q
  q 0.0 g BT 389.01 652.09 Td (  ) Tj ET Q
  566.92 668.97 m 566.92 640.62 l S q 0.0 g BT 399.68 652.09 Td (  ) Tj ET Q
  28.35 640.62 m 28.35 612.28 l S q 0.0 g BT 31.18 623.75 Td (  Recaudado OMP) Tj ET Q
  q 0.0 g BT 389.01 623.75 Td (  ) Tj ET Q
  566.92 640.62 m 566.92 612.28 l S q 0.0 g BT 399.68 623.75 Td (  ) Tj ET Q
  28.35 612.28 m 28.35 583.93 l S 28.35 583.93 m 396.85 583.93 l S q 0.0 g BT 31.18 595.40 Td (  Devoluciones no Pago Mes Anterior:) Tj ET Q
  566.92 612.28 m 566.92 583.93 l S 396.85 583.93 m 566.92 583.93 l S q 0.0 g BT 399.68 595.40 Td (  ) Tj ET Q
  28.35 578.26 m 28.35 549.91 l S 28.35 578.26 m 396.85 578.26 l S 28.35 549.91 m 396.85 549.91 l S q 0.0 g BT 313.50 561.39 Td (Total Recaudado:  ) Tj ET Q
  396.85 578.26 m 566.92 578.26 l S 566.92 578.26 m 566.92 549.91 l S 396.85 549.91 m 566.92 549.91 l S q 0.0 g BT 399.68 561.39 Td (  ) Tj ET Q
  BT /F1 8.0 Tf ET
  q 0.0 g BT 31.18 526.25 Td (Comentarios) Tj ET Q
  BT /F1 9.0 Tf ET
  28.35 521.57 m 28.35 408.18 l S 28.35 521.57 m 566.92 521.57 l S 566.92 521.57 m 566.92 408.18 l S 28.35 408.18 m 566.92 408.18 l S 
  BT /F2 9.0 Tf ET
  q 0.0 g BT 67.93 199.97 Td (_____________________) Tj ET Q
  q 0.0 g BT 252.18 199.97 Td (_____________________) Tj ET Q
  q 0.0 g BT 429.34 199.97 Td (_____________________) Tj ET Q
  q 0.0 g BT 86.46 185.80 Td (some guy) Tj ET Q
  q 0.0 g BT 260.96 185.80 Td (some guy) Tj ET Q
  q 0.0 g BT 447.62 185.80 Td (some guy) Tj ET Q
  
  endstream
  endobj
  1 0 obj
  &lt;&lt;/Type /Pages
  /Kids [3 0 R ]
  /Count 1
  /MediaBox [0 0 595.28 841.89]
  &gt;&gt;
  endobj
  5 0 obj
  &lt;&lt;/Type /Font
  /BaseFont /Helvetica
  /Subtype /Type1
  /Encoding /WinAnsiEncoding
  &gt;&gt;
  endobj
  6 0 obj
  &lt;&lt;/Type /Font
  /BaseFont /Helvetica-Bold
  /Subtype /Type1
  /Encoding /WinAnsiEncoding
  &gt;&gt;
  endobj
  2 0 obj
  &lt;&lt;
  /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
  /Font &lt;&lt;
  /F1 5 0 R
  /F2 6 0 R
  &gt;&gt;
  /XObject &lt;&lt;
  &gt;&gt;
  &gt;&gt;
  endobj
  7 0 obj
  &lt;&lt;
  /Producer (PL_FPDF 0.9.3 portage pour Laclasse.com par P.G. Levallois de la version 1.53 de PHP/FPDF d'Olivier Plathey.)
  /Title (Informe Liquidaciones a Companias)
  /Author ()
  /Creator ()
  /CreationDate (D:20160217160748)
  &gt;&gt;
  endobj
  8 0 obj
  &lt;&lt;
  /Type /Catalog
  /Pages 1 0 R
  /OpenAction [3 0 R /FitH null]
  /PageLayout /OneColumn
  &gt;&gt;
  endobj
  xref
  0 9
  0000000000 65535 f 
  0000009634 00000 n 
  0000009918 00000 n 
  0000007105 00000 n 
  0000007183 00000 n 
  0000009721 00000 n 
  0000009817 00000 n 
  0000010032 00000 n 
  0000010285 00000 n 
  trailer
  &lt;&lt;
  /Size 9
  /Root 8 0 R
  /Info 7 0 R
  &gt;&gt;
  startxref
  10388
  %%EOF
  </code></pre>
  
  <p>But the file is ok:</p>
  
  <p><a href="https://i.stack.imgur.com/cE3md.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cE3md.png" alt="enter image description here"></a></p>