[Solved] 1.1.4 Export to PDF with background images

Java, C++, C#, Delphi, ??? - Using the UNO bridges

[Solved] 1.1.4 Export to PDF with background images

Postby CraigW » Wed Jul 23, 2014 11:59 am

Hi, I have a problem that needs solving where we use OpenOffice 1.1.4 templated reports and programmatically export them to PDF. The team who create the templates have recently changed the header image and some images in a table to background images (before they were just inserted) since this change the current program is not creating the PDFs with the images. We can export from OpenOffice manually and the images are included. Can anyone help with a change I may need to make to get these background images included please?

The current code:
Code: Select all   Expand viewCollapse view
private void print(XInterface xComponent,
         PrintRequestDTO printReq, File sourceFile,
         Vector<String> pages) throws java.lang.Exception {

      String pageRange;
      
      // XXX create the PDF via OOo export facility
      com.sun.star.frame.XStorable pdfCreator = (com.sun.star.frame.XStorable) UnoRuntime
            .queryInterface(
                  com.sun.star.frame.XStorable.class,
                  xComponent);

      PropertyValue[] outputOpts = new PropertyValue[2];
      
      outputOpts[0] = new PropertyValue();
      outputOpts[0].Name = "CompressionMode";
      outputOpts[0].Value = "1"; // XXX Change this perhaps?

      outputOpts[1] = new PropertyValue();
      outputOpts[1].Name = "PageRange";

      if (printReq.getPageRange() == null) {

         pageRange = "1-";

      }
      else {

         if (printReq.getPageRange().length() > 0) {

            pageRange = printReq.getPageRange();

         }
         else {

            pageRange = "1-";

         }

      }

      log.debug("Print Instruction - page range = "
            + pageRange);

      PropertyValue[] filterOpts = new PropertyValue[3];

      filterOpts[0] = new PropertyValue();
      filterOpts[0].Name = "FilterName";
      filterOpts[0].Value = "writer_pdf_Export"; // MS Word 97

      filterOpts[1] = new PropertyValue();
      filterOpts[1].Name = "Overwrite";
      filterOpts[1].Value = new Boolean(true);

      filterOpts[2] = new PropertyValue();
      filterOpts[2].Name = "FilterData";
      filterOpts[2].Value = outputOpts;

      if (pages.size() == 0) { // ie no forced page breaks
         // set page range
         outputOpts[1].Value = pageRange;
         filterOpts[2] = new PropertyValue();
         filterOpts[2].Name = "FilterData";
         filterOpts[2].Value = outputOpts;

         File outputFile = new File(
               sourceFile.getParent(),
               printReq.getOutputFileName()
                     + ".pdf");
         
         StringBuffer sPDFUrl = new StringBuffer(
               "file:///");
         sPDFUrl.append(outputFile.getCanonicalPath()
               .replace('\\', '/'));

         log.debug("PDF file = " + sPDFUrl.toString());

         if (pdfCreator != null) {
            
            sleep();
            pdfCreator.storeToURL(sPDFUrl.toString(),
                  filterOpts);
            
         }
      }
      else if (pages.size() > 1) {
         throw new PrintDocumentException(
               "Only one forced split catered for currently");
      }
      else { // a forced split exists.
         log.debug("Page break found in "
               + (String) pages.firstElement());
         String[] newPageRanges = calculatePageRanges(
               (String) pages.firstElement(), pageRange);

         int rangeCount = newPageRanges.length;
         for (int i = 0; i < rangeCount; i++) {
            outputOpts[1].Value = newPageRanges[i];
            log.debug("page range = " + newPageRanges[i]);
            filterOpts[2] = new PropertyValue();
            filterOpts[2].Name = "FilterData";
            filterOpts[2].Value = outputOpts;
            String fileExtension = (i == 0 && rangeCount > 1) ? "__Summary.pdf"
                  : ".pdf";
            File outputFile = new File(
                  sourceFile.getParent(),
                  printReq.getOutputFileName()
                        + fileExtension);
            
            StringBuffer sPDFUrl = new StringBuffer(
                  "file:///");
            sPDFUrl.append(outputFile.getCanonicalPath()
                  .replace('\\', '/'));
            log.debug("PDF file = " + sPDFUrl.toString());

            if (pdfCreator != null) {
               log.debug("about to create the PDF file");
               sleep();
               pdfCreator.storeToURL(
                     sPDFUrl.toString(), filterOpts);
               log.debug("done");
            }
         }
      }      
   }

Thanks in advance
Last edited by CraigW on Thu Jul 24, 2014 5:20 pm, edited 1 time in total.
Open office 1.1.4 and 3.0
Windows 7
CraigW
 
Posts: 4
Joined: Wed Jul 23, 2014 11:50 am

Re: Open Office 1.1.4 Export to PDF with background images

Postby Villeroy » Wed Jul 23, 2014 1:09 pm

I would try to find out about any differences between the pictures that used to work and the new ones that don't and if the whole thing works again when you re-exchange the pictures with the old ones. Is there a difference in file format, scaling, resolution, are they embedded or linked?
As far as I can see, the Java code does nothing to the pictures.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28419
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Open Office 1.1.4 Export to PDF with background images

Postby CraigW » Wed Jul 23, 2014 1:16 pm

As far as I can see, the Java code does nothing to the pictures.

I agree with that it does nothing specific wi them.
are they embedded or linked?

Yes this is the problem thy were linked and now embedded and background images. This is the onlu difference and it seems the program does know how to handle the background images... and I don't know how to deal with the program to make it handle them!
Thanks.
Open office 1.1.4 and 3.0
Windows 7
CraigW
 
Posts: 4
Joined: Wed Jul 23, 2014 11:50 am

Re: Open Office 1.1.4 Export to PDF with background images

Postby RoryOF » Wed Jul 23, 2014 1:17 pm

The first thing to do is to verify that a sample file, using the correct template, can manually Export to PDF correctly.
Apache OpenOffice 4.1.7 on Xubuntu 18.04.4 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 31209
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Open Office 1.1.4 Export to PDF with background images

Postby CraigW » Wed Jul 23, 2014 1:26 pm

RoryOF wrote:The first thing to do is to verify that a sample file, using the correct template, can manually Export to PDF correctly.

Please see my original post, this has been done and is successful.
Thanks,
Open office 1.1.4 and 3.0
Windows 7
CraigW
 
Posts: 4
Joined: Wed Jul 23, 2014 11:50 am

Re: OpenOffice 1.1.4 Export to PDF with background images

Postby CraigW » Thu Jul 24, 2014 5:19 pm

Problem solved by setting the hidden property to true so the sxw is displayed whilst being worked on. Then when the file is exported the background images are included. I would prefer the file to remain hidden but at least it works now.
Open office 1.1.4 and 3.0
Windows 7
CraigW
 
Posts: 4
Joined: Wed Jul 23, 2014 11:50 am


Return to External Programs

Who is online

Users browsing this forum: No registered users and 1 guest