How to get a pdf embedded fonts using PDFBOX0.8.0 - embedded-fonts

My code:
FileInputStream pdfFile = new FileInputStream("C:/work/pdf2tiff/test.PDF");
PDDocument pdDocument = PDDocument.load(pdfFile, true);
PDDocumentCatalog catalog = pdDocument.getDocumentCatalog();
List pages = catalog.getAllPages();
if (pages != null && pages.size() > 0) {
for (int i = 0; i < pages.size(); i++) {
PDPage page = (PDPage) pages.get(i);
Map fonts = page.getResources().getFonts();
System.out.println("fonts=" + fonts);
I got output:
fonts={F0=org.apache.pdfbox.pdmodel.font.PDType1Font#8aaed5,
F4=org.apache.pdfbox.pdmodel.font.PDType0Font#dc4414,
F2=org.apache.pdfbox.pdmodel.font.PDType0Font#f98ce0,
F6=org.apache.pdfbox.pdmodel.font.PDTrueTypeFont#18fcdce}
Why the fonts map's key is F0/F1/F2/F6? What these mean?
Should I iterate all pdf pages get all fonts?
Thanks for your answer.

It seems like the pdf you loaded has multiple fonts loaded. I couldn't figure out any way to retrieve fonts from a document (which I think should be available for us to retrieve since we load fonts to a particular document).
I'm guessing when you load a font into the document it uses "F0", "F1", etc as keys to map to PDFont type. When you print fonts object, it's printing the memory location of the object.
To get all the embedded fonts, you can create a new HashMap() object, then iterate over all the pages and add each font to your HashMap(). Then you can iterate over the keys, get the PDFont font object and, use font.getSubType() to get some sort of description of the font.
Hope this helps. Good luck!

Related

Unable to hide element category in a view in Revit file

I want to hide certain elements in the view.
I managed to hid (with view..HideCategoryTemporary) all the elements I wanted except the marked one in the picture attached.
3D_House_before_hide
Element snoop
This element is a building section of category OST_Viewers.
Manually hiding the element category via the view works, but fetching all OST_Viewers in the code and hiding them does not work.
The following code contain the building section elements in addition to the grids,
FilteredElementCollector viewers_sections = new FilteredElementCollector(doc, v_id).OfCategory(BuiltInCategory.OST_Viewers);
FilteredElementCollector grids = new FilteredElementCollector(doc, v_id).OfCategory(BuiltInCategory.OST_Grids);
FilteredElementCollector elements_to_be_hidden = new FilteredElementCollector(doc, v_id);
elements_to_be_hidden.UnionWith(viewers_sections).UnionWith(grids)
foreach (Element e in elements_to_be_hidden)
{
cur_view.HideCategoryTemporary(e.Category.Id);
}
I've checked that viewers_sections contains the mentioned building sections however it is not hidden from the view.
After hide
How do I hide these building sections?
Please use View#SetCategoryHidden instead to turn off the visibility of the category, the result of the View#HideCategoryTemporary will be reset after closing the file. Here is the working example:
var gridCate = this.Document.Settings.Categories.get_Item(BuiltInCategory.OST_Grids);
var sectionsCate = this.Document.Settings.Categories.get_Item(BuiltInCategory.OST_Sections);
using(var trans = new Transaction(this.Document))
{
trans.Start("Hide Grids & Secions");
this.ActiveView.SetCategoryHidden(gridCate.Id, true);
this.ActiveView.SetCategoryHidden(sectionsCate.Id, true);
trans.Commit();
}

apache odftoolkit portrait/landscape mode

I'm using library apache odftoolkit to generate report from Java code to *.odt file. Have code like this:
outputOdt = TextDocument.newTextDocument();
Paragraph p = outputOdt.addParagraph("some text");
p.appendTextContent("some text");
I'm adding paragraphs, tables, setting fonts, and it works fine.
But I need to set some pages in my document in Landscape mode but
don't know how to do this. I found API class PageLayoutProperties and method setPrintOrientation(), but don't know where to call it. Anybody know?
Found solution:
TextDocument outputOdt;
for( Iterator<StyleMasterPageElement> it = outputOdt.getOfficeMasterStyles().getMasterPages(); it.hasNext(); ) {
StyleMasterPageElement page = it.next();
String pageLayoutName = page.getStylePageLayoutNameAttribute();
OdfStylePageLayout pageLayoutStyle = page.getAutomaticStyles().getPageLayout( pageLayoutName );
PageLayoutProperties pageLayoutProps = PageLayoutProperties.getOrCreatePageLayoutProperties( pageLayoutStyle );
double tmp = pageLayoutProps.getPageWidth();
pageLayoutProps.setPageWidth( pageLayoutProps.getPageHeight());
pageLayoutProps.setPageHeight( tmp );
}
I came across this existing question and answer:
How can the Page Size, Page Orientation, and Page Margins of an ods Spreadsheet Be Set Using ODFDOM?
which is about doing the same thing for an ODS spreadsheet, which is essentially the same. Key is to set the page height and width as well as the print orientation in the PageLayoutProperties

JavaFX Pagination - Update the content of current page

In my JavaFX application I use Pagination to show some pictures. Reading the pictures takes much time so I fill an ObservableList<Image> with placeholder images, which should be replaced by the originals when they are loaded.
Everything works fine, but the only thing is that the current page doesn't get updated when the image is loaded. I have to change the CurrentPageIndex and change back. Than the right picture is displayed.
For loading the images I've created a Task, so that I'm able to use the Application during the process.
So my Question is, how is it possible to update the content of the current page?
The PageFactory looks like that:
ImageView imageView = new ImageView();
Image img = images.get(index);
imageView.setImage(img);
imageView.setFitWidth(240);
imageView.setStyle("-fx-background-color: white");
imageView.setPreserveRatio(true);
imageView.setSmooth(true);
imageView.setCache(true);
imageView.setEffect(createShadow(Color.BLACK, false));
VBox pageBox = new VBox();
pageBox.setAlignment(Pos.CENTER);
pageBox.getChildren().add(imageView);
return pageBox;
Here I replace the images (first 2 lines are methods of a framework):
for (int i = 0; i < pageCount; i++) {
PagePainter pp = parser.getPagePainter(i);
BufferedImage buffImg = pp.getImage(200);
fxImages.set(i, SwingFXUtils.toFXImage(buffImg, null));
}

Aspose.Words...calculating widt of text in pixels

I have an MVC3 C# .Net web app. I am using Aspose.Words to create an MS Word document. I have a requirement to not include tables in the document. However, on several lines of the document the alignment of the text is mis-aligned depending on the width of the text.
For example:
This looks good
Proposal Name: My Proposal Date:04/24/2012
This does not
Proposal Name: My Prop Date:04/24/2012
It should be
Proposal Name: My Prop Date:04/24/2012
Based on the width of the first bit of text, I need to calculate the width in pixels (I think) and insert a TAB if necessary.
Any ideas how to do this?
you can use Graphics.MeasureString function which gives you the width of your string in pixels based on your font. for more info go Here
Cheers,
Ehsan
The following code example returns the bounding rectangle of the current entity relative to the page top left corner.
Document doc = new Document(MyDir + "in.docx");
LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
var renderObject = layoutCollector.GetEntity(para);
layoutEnumerator.Current = renderObject;
RectangleF location = layoutEnumerator.Rectangle;
Console.WriteLine(location);
}
src: https://www.aspose.com/community/forums/thread/541215/replace-run-text-with-string-of-spaces-of-same-pixel-length.aspx

trying to extract formatted images from indesign into a separate folder

I'm looking for a way to extract images from an ID file in a 'formatted' / cropped form.
i.e: a. I have placed numerous, hi-res (tiff, psd) images into an InDesign CS5 file
b. The image boxes that they have been placed into, are smaller than the actual image (pretty intense cropping occurred) c. I am trying to collect these images in their new stage (cropped to the image box) and export them as jpg at 72dpi.
Are there any plug-ins out there that would automatically collect "formatted" images from ID for me? Or is there some other way?
If you're familiar with Indesign Scripting, this can very easily be done via a script. I use Javascript but this can be done with VBSript or AppleScript as well. Here is a basic example of a script that will open a document, and export a rectangle (your image box) as a JPG. Basically, you can just loop through the pictures in your document and export each one to a location/filename you choose (see the myFile variable below). There are several "jpegExportPreferences" you can pick from to determine how your output JPG will be (i.e. DPI).
test();
function test(){
var myDoc = app.open('c:/user/desktop/testDocument.indd');
var myGroups = myDoc.groups;
//for each group...
for (var i = 0;i < myGroups.length; i++){
// for each rectangle in the group...
for(var r = 0; r< myGroups[i].rectangles.length; r++){
var myRect = myGroups[i].rectangles[r];
app.jpegExportPreferences.exportResolution = 300;
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;
//give it a unique name
var myFile = new File('c:/users/desktop/newJPG' + myRect.id + '.jpg');
myRect.exportFile(ExportFormat.JPG, myFile);
}
}
}
For a list of the other optional JPG Export preferences, see this link:
http://indesignscriptingreference.com/cs2/javascript-cs2/jpegexportpreference.htm
Hope this helps!

Resources